feat: add autoFocus

This commit is contained in:
JimmFly
2022-12-14 16:15:21 +08:00
parent fc8deafde6
commit 9ff3f0800f
4 changed files with 51 additions and 54 deletions
@@ -1,4 +1,4 @@
import React, { Dispatch, SetStateAction } from 'react';
import React, { Dispatch, SetStateAction, useEffect, useRef } from 'react';
import { SearchIcon } from '@blocksuite/icons';
import { StyledInputContent, StyledLabel } from './style';
import { Command } from 'cmdk';
@@ -6,12 +6,17 @@ export const Input = (props: {
query: string;
setQuery: Dispatch<SetStateAction<string>>;
}) => {
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
return inputRef.current?.focus();
}, [inputRef]);
return (
<StyledInputContent>
<StyledLabel htmlFor=":r5:">
<SearchIcon />
</StyledLabel>
<Command.Input
ref={inputRef}
value={props.query}
onValueChange={props.setQuery}
placeholder="Quick Search..."