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/atoms | |
| parent | 041fb0974f624368a45316c296c2a3e3c229dae2 (diff) | |
chore: give autofocus to the toolbar search form
Diffstat (limited to 'src/components/atoms')
| -rw-r--r-- | src/components/atoms/forms/field.tsx | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/components/atoms/forms/field.tsx b/src/components/atoms/forms/field.tsx index e45a8a7..377e1b0 100644 --- a/src/components/atoms/forms/field.tsx +++ b/src/components/atoms/forms/field.tsx @@ -1,4 +1,9 @@ -import { ChangeEvent, FC, SetStateAction } from 'react'; +import { + ChangeEvent, + forwardRef, + ForwardRefRenderFunction, + SetStateAction, +} from 'react'; import styles from './forms.module.scss'; export type FieldType = @@ -72,12 +77,10 @@ export type FieldProps = { * * Render either an input or a textarea. */ -const Field: FC<FieldProps> = ({ - className = '', - setValue, - type, - ...props -}) => { +const Field: ForwardRefRenderFunction<HTMLInputElement, FieldProps> = ( + { className = '', setValue, type, ...props }, + ref +) => { /** * Update select value when an option is selected. * @param e - The option change event. @@ -96,12 +99,13 @@ const Field: FC<FieldProps> = ({ /> ) : ( <input - type={type} - onChange={updateValue} className={`${styles.field} ${className}`} + onChange={updateValue} + ref={ref} + type={type} {...props} /> ); }; -export default Field; +export default forwardRef(Field); |
