Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit30179ae

Browse files
authored
fix: apply autofocus to workspace button search (#16905)
Fixes:#14816
1 parent4994ba1 commit30179ae

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

‎site/src/components/SearchField/SearchField.stories.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ type Story = StoryObj<typeof SearchField>;
2020

2121
exportconstEmpty:Story={};
2222

23+
exportconstFocused:Story={
24+
args:{
25+
autoFocus:true,
26+
},
27+
};
28+
2329
exportconstDefaultValue:Story={
2430
args:{
2531
value:"owner:me",

‎site/src/components/SearchField/SearchField.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,28 @@ import InputAdornment from "@mui/material/InputAdornment";
66
importTextField,{typeTextFieldProps}from"@mui/material/TextField";
77
importTooltipfrom"@mui/material/Tooltip";
88
importvisuallyHiddenfrom"@mui/utils/visuallyHidden";
9-
importtype{FC}from"react";
9+
import{typeFC,useEffect,useRef}from"react";
1010

1111
exporttypeSearchFieldProps=Omit<TextFieldProps,"onChange">&{
1212
onChange:(query:string)=>void;
13+
autoFocus?:boolean;
1314
};
1415

1516
exportconstSearchField:FC<SearchFieldProps>=({
1617
value="",
1718
onChange,
19+
autoFocus=false,
1820
InputProps,
1921
...textFieldProps
2022
})=>{
2123
consttheme=useTheme();
24+
constinputRef=useRef<HTMLInputElement>(null);
25+
26+
if(autoFocus){
27+
useEffect(()=>{
28+
inputRef.current?.focus();
29+
});
30+
}
2231
return(
2332
<TextField
2433
// Specifying `minWidth` so that the text box can't shrink so much
@@ -27,6 +36,7 @@ export const SearchField: FC<SearchFieldProps> = ({
2736
size="small"
2837
value={value}
2938
onChange={(e)=>onChange(e.target.value)}
39+
inputRef={inputRef}
3040
InputProps={{
3141
startAdornment:(
3242
<InputAdornmentposition="start">

‎site/src/pages/WorkspacesPage/WorkspacesButton.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export const WorkspacesButton: FC<WorkspacesButtonProps> = ({
6969
>
7070
<MenuSearch
7171
value={searchTerm}
72+
autoFocus={true}
7273
onChange={setSearchTerm}
7374
placeholder="Type/select a workspace template"
7475
aria-label="Template select for workspace"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp