Skip to content

Commit acae8f2

Browse files
committed
feat: Focus automatically the search input
1 parent 5742877 commit acae8f2

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

app/components/select-tree.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,9 @@ function SelectTree({
338338
return res;
339339
}, [options]);
340340

341-
const handleOpen = useEventCallback((ev: React.MouseEvent<HTMLElement>) => {
341+
const handleOpen = useEventCallback(() => {
342342
setOpenState(true);
343-
setMinMenuWidth(ev.currentTarget.clientWidth);
343+
setMinMenuWidth(inputRef.current?.clientLeft);
344344
onOpen?.();
345345
});
346346

@@ -463,7 +463,8 @@ function SelectTree({
463463
const handleKeyDown: React.HTMLAttributes<HTMLInputElement>["onKeyDown"] =
464464
useEvent((ev) => {
465465
if (ev.key === "Enter" || ev.key == " ") {
466-
handleOpen(ev);
466+
handleOpen();
467+
ev.preventDefault();
467468
}
468469
});
469470

@@ -510,6 +511,7 @@ function SelectTree({
510511
value={inputValue}
511512
sx={{ p: 1, width: "100%" }}
512513
InputProps={{
514+
autoFocus: true,
513515
startAdornment: <Icon name="search" size={16} color="#555" />,
514516
endAdornment: (
515517
<IconButton size="small" onClick={handleClickResetInput}>

0 commit comments

Comments
 (0)