diff options
| author | Armand Philippot <git@armandphilippot.com> | 2021-12-20 19:06:49 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2021-12-20 19:06:49 +0100 |
| commit | 43cdb7607d9423109758334155acfe844eab6ea5 (patch) | |
| tree | 0798fbb6f00bfbdbc3bd64759ffdb305dee43f0c /src/components/SearchForm/SearchForm.tsx | |
| parent | f9df5cbce7db38ce83cc8b40346c9cabde5debc4 (diff) | |
chore: define search form visibility
Diffstat (limited to 'src/components/SearchForm/SearchForm.tsx')
| -rw-r--r-- | src/components/SearchForm/SearchForm.tsx | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/components/SearchForm/SearchForm.tsx b/src/components/SearchForm/SearchForm.tsx new file mode 100644 index 0000000..c02c224 --- /dev/null +++ b/src/components/SearchForm/SearchForm.tsx @@ -0,0 +1,37 @@ +import { ButtonSubmit } from '@components/Buttons'; +import { Form, Input } from '@components/Form'; +import { t } from '@lingui/macro'; +import { FormEvent, useEffect, useRef, useState } from 'react'; + +const SearchForm = ({ isOpened }: { isOpened: boolean }) => { + const [query, setQuery] = useState(''); + const inputRef = useRef<HTMLInputElement>(null); + + useEffect(() => { + setTimeout(() => { + if (inputRef.current) { + inputRef.current.focus(); + } + }, 800); + }, [isOpened]); + + const launchSearch = (e: FormEvent) => { + e.preventDefault(); + }; + + return ( + <Form submitHandler={launchSearch} modifier="search"> + <Input + ref={inputRef} + id="search-query" + name="search-query" + type="search" + value={query} + setValue={setQuery} + /> + <ButtonSubmit>{t`Search`}</ButtonSubmit> + </Form> + ); +}; + +export default SearchForm; |
