From 691646c97b09f9150ac823670d6c661358c81c1c Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Tue, 24 May 2022 17:54:23 +0200
Subject: chore: give autofocus to the toolbar search form

---
 src/components/molecules/forms/labelled-field.tsx | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

(limited to 'src/components/molecules/forms/labelled-field.tsx')

diff --git a/src/components/molecules/forms/labelled-field.tsx b/src/components/molecules/forms/labelled-field.tsx
index ecc9255..6a00a3e 100644
--- a/src/components/molecules/forms/labelled-field.tsx
+++ b/src/components/molecules/forms/labelled-field.tsx
@@ -1,6 +1,6 @@
 import Field, { type FieldProps } from '@components/atoms/forms/field';
 import Label from '@components/atoms/forms/label';
-import { FC } from 'react';
+import { forwardRef, ForwardRefRenderFunction } from 'react';
 import styles from './labelled-field.module.scss';
 
 export type LabelledFieldProps = FieldProps & {
@@ -23,14 +23,13 @@ export type LabelledFieldProps = FieldProps & {
  *
  * Render a field tied to a label.
  */
-const LabelledField: FC<LabelledFieldProps> = ({
-  hideLabel = false,
-  id,
-  label,
-  labelPosition = 'top',
-  required,
-  ...props
-}) => {
+const LabelledField: ForwardRefRenderFunction<
+  HTMLInputElement,
+  LabelledFieldProps
+> = (
+  { hideLabel = false, id, label, labelPosition = 'top', required, ...props },
+  ref
+) => {
   const positionModifier = `label--${labelPosition}`;
   const visibilityClass = hideLabel ? 'screen-reader-text' : '';
 
@@ -43,9 +42,9 @@ const LabelledField: FC<LabelledFieldProps> = ({
       >
         {label}
       </Label>
-      <Field id={id} required={required} {...props} />
+      <Field id={id} ref={ref} required={required} {...props} />
     </>
   );
 };
 
-export default LabelledField;
+export default forwardRef(LabelledField);
-- 
cgit v1.2.3

