diff --git a/.changeset/eight-flowers-heal.md b/.changeset/eight-flowers-heal.md new file mode 100644 index 0000000000..3d513d836f --- /dev/null +++ b/.changeset/eight-flowers-heal.md @@ -0,0 +1,5 @@ +--- +'@graphcommerce/ecommerce-ui': patch +--- + +CheckboxElement, MultiSelectElement, NumberFieldElement, SelectElement, SliderElement and TextFieldElement have their inputRef passed, allowing focus to be set by the form. diff --git a/packages/ecommerce-ui/components/FormComponents/CheckboxElement.tsx b/packages/ecommerce-ui/components/FormComponents/CheckboxElement.tsx index b2188951ac..913cb6a85b 100644 --- a/packages/ecommerce-ui/components/FormComponents/CheckboxElement.tsx +++ b/packages/ecommerce-ui/components/FormComponents/CheckboxElement.tsx @@ -47,7 +47,8 @@ export function CheckboxElement({ name={name} rules={rules} control={control} - render={({ field: { value, onChange }, fieldState: { invalid, error } }) => { + render={({ field: { value, onChange, ref, ...field }, fieldState: { invalid, error } }) => { + // eslint-disable-next-line no-nested-ternary const parsedHelperText = error ? typeof parseError === 'function' ? parseError(error) @@ -61,6 +62,8 @@ export function CheckboxElement({ control={ ({ }} value={value} checked={!!value} - onChange={() => { - onChange(!value) - }} + onChange={() => onChange(!value)} /> } /> diff --git a/packages/ecommerce-ui/components/FormComponents/MultiSelectElement.tsx b/packages/ecommerce-ui/components/FormComponents/MultiSelectElement.tsx index 11998bdd59..4a325b5576 100644 --- a/packages/ecommerce-ui/components/FormComponents/MultiSelectElement.tsx +++ b/packages/ecommerce-ui/components/FormComponents/MultiSelectElement.tsx @@ -72,7 +72,7 @@ export function MultiSelectElement( name={name} rules={rules} control={control} - render={({ field: { value, onChange, onBlur }, fieldState: { invalid, error } }) => { + render={({ field: { value, onChange, ...field }, fieldState: { invalid, error } }) => { helperText = error ? typeof parseError === 'function' ? parseError(error) @@ -102,6 +102,7 @@ export function MultiSelectElement( )}