diff --git a/site/src/components/SearchField/SearchField.stories.tsx b/site/src/components/SearchField/SearchField.stories.tsx index aa7ad9ba739f1..79e76d4d6ad82 100644 --- a/site/src/components/SearchField/SearchField.stories.tsx +++ b/site/src/components/SearchField/SearchField.stories.tsx @@ -20,6 +20,12 @@ type Story = StoryObj; export const Empty: Story = {}; +export const Focused: Story = { + args: { + autoFocus: true, + }, +}; + export const DefaultValue: Story = { args: { value: "owner:me", diff --git a/site/src/components/SearchField/SearchField.tsx b/site/src/components/SearchField/SearchField.tsx index cfe5d0637b37e..2ce66d9b3ca78 100644 --- a/site/src/components/SearchField/SearchField.tsx +++ b/site/src/components/SearchField/SearchField.tsx @@ -6,19 +6,28 @@ import InputAdornment from "@mui/material/InputAdornment"; import TextField, { type TextFieldProps } from "@mui/material/TextField"; import Tooltip from "@mui/material/Tooltip"; import visuallyHidden from "@mui/utils/visuallyHidden"; -import type { FC } from "react"; +import { type FC, useEffect, useRef } from "react"; export type SearchFieldProps = Omit & { onChange: (query: string) => void; + autoFocus?: boolean; }; export const SearchField: FC = ({ value = "", onChange, + autoFocus = false, InputProps, ...textFieldProps }) => { const theme = useTheme(); + const inputRef = useRef(null); + + if (autoFocus) { + useEffect(() => { + inputRef.current?.focus(); + }); + } return ( = ({ size="small" value={value} onChange={(e) => onChange(e.target.value)} + inputRef={inputRef} InputProps={{ startAdornment: ( diff --git a/site/src/pages/WorkspacesPage/WorkspacesButton.tsx b/site/src/pages/WorkspacesPage/WorkspacesButton.tsx index 973c4d9b13e05..c5a2527d7a75d 100644 --- a/site/src/pages/WorkspacesPage/WorkspacesButton.tsx +++ b/site/src/pages/WorkspacesPage/WorkspacesButton.tsx @@ -69,6 +69,7 @@ export const WorkspacesButton: FC = ({ >