From 691646c97b09f9150ac823670d6c661358c81c1c Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Tue, 24 May 2022 17:54:23 +0200 Subject: chore: give autofocus to the toolbar search form --- src/components/organisms/forms/search-form.tsx | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src/components/organisms/forms') 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 & { * * Render a search form. */ -const SearchForm: FC = ({ 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 = ({ hideLabel, searchPage }) => { setValue(''); }; + const id = useId(); + return (