diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-05-24 17:54:23 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-05-24 17:54:23 +0200 |
| commit | 691646c97b09f9150ac823670d6c661358c81c1c (patch) | |
| tree | cc2115a23d9dae87b7cdfab9223f1366aa629c69 /src/components/organisms/forms | |
| parent | 041fb0974f624368a45316c296c2a3e3c229dae2 (diff) | |
chore: give autofocus to the toolbar search form
Diffstat (limited to 'src/components/organisms/forms')
| -rw-r--r-- | src/components/organisms/forms/search-form.tsx | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/components/organisms/forms/search-form.tsx b/src/components/organisms/forms/search-form.tsx index 56d3895..1b5f662 100644 --- a/src/components/organisms/forms/search-form.tsx +++ b/src/components/organisms/forms/search-form.tsx @@ -5,7 +5,7 @@ import LabelledField, { type LabelledFieldProps, } from '@components/molecules/forms/labelled-field'; import { useRouter } from 'next/router'; -import { FC, useState } from 'react'; +import { forwardRef, ForwardRefRenderFunction, useId, useState } from 'react'; import { useIntl } from 'react-intl'; import styles from './search-form.module.scss'; @@ -21,7 +21,10 @@ export type SearchFormProps = Pick<LabelledFieldProps, 'hideLabel'> & { * * Render a search form. */ -const SearchForm: FC<SearchFormProps> = ({ hideLabel, searchPage }) => { +const SearchForm: ForwardRefRenderFunction< + HTMLInputElement, + SearchFormProps +> = ({ hideLabel, searchPage }, ref) => { const intl = useIntl(); const fieldLabel = intl.formatMessage({ defaultMessage: 'Search for:', @@ -42,17 +45,20 @@ const SearchForm: FC<SearchFormProps> = ({ hideLabel, searchPage }) => { setValue(''); }; + const id = useId(); + return ( <Form grouped={false} onSubmit={submitHandler} className={styles.wrapper}> <LabelledField - type="search" - id="search-form" - name="search-form" + className={styles.field} + hideLabel={hideLabel} + id={`search-form-${id}`} label={fieldLabel} - value={value} + name="search-form" + ref={ref} setValue={setValue} - hideLabel={hideLabel} - className={styles.field} + type="search" + value={value} /> <Button type="submit" @@ -67,4 +73,4 @@ const SearchForm: FC<SearchFormProps> = ({ hideLabel, searchPage }) => { ); }; -export default SearchForm; +export default forwardRef(SearchForm); |
