diff --git a/.changeset/calm-sheep-relate.md b/.changeset/calm-sheep-relate.md new file mode 100644 index 0000000000..33970b7071 --- /dev/null +++ b/.changeset/calm-sheep-relate.md @@ -0,0 +1,5 @@ +--- +'@graphcommerce/ecommerce-ui': patch +--- + +Added ref forwarding for the inputRef diff --git a/packages/ecommerce-ui/components/FormComponents/CheckboxElement.tsx b/packages/ecommerce-ui/components/FormComponents/CheckboxElement.tsx index 65b8722e6d..4e467deab1 100644 --- a/packages/ecommerce-ui/components/FormComponents/CheckboxElement.tsx +++ b/packages/ecommerce-ui/components/FormComponents/CheckboxElement.tsx @@ -8,7 +8,14 @@ import type { SxProps, Theme, } from '@mui/material' -import { Checkbox, FormControl, FormControlLabel, FormGroup, FormHelperText } from '@mui/material' +import { + Checkbox, + FormControl, + FormControlLabel, + FormGroup, + FormHelperText, + useForkRef, +} from '@mui/material' export type CheckboxElementProps = Omit & { label?: FormControlLabelProps['label'] @@ -62,7 +69,7 @@ export function CheckboxElement( = Omit< TextFieldProps, @@ -44,7 +44,7 @@ export function NumberFieldElement(props: NumberFieldElem variant = 'outlined', disabled, shouldUnregister, - ...textFieldProps + ...rest } = props const classes = withState({ size }) @@ -69,22 +69,22 @@ export function NumberFieldElement(props: NumberFieldElem return ( { const newValue = (ev.target as HTMLInputElement).valueAsNumber onChange(Number.isNaN(newValue) ? '' : newValue) - textFieldProps.onChange?.(ev) + rest.onChange?.(ev) }} variant={variant} required={required} error={invalid} - helperText={error ? error.message : textFieldProps.helperText} + helperText={error ? error.message : rest.helperText} size={size} type='number' - className={`${textFieldProps.className ?? ''} ${classes.quantity}`} + className={`${rest.className ?? ''} ${classes.quantity}`} sx={[ { width: responsiveVal(90, 120), diff --git a/packages/ecommerce-ui/components/FormComponents/SelectElement.tsx b/packages/ecommerce-ui/components/FormComponents/SelectElement.tsx index 63290b6fb1..2810a7f2e6 100644 --- a/packages/ecommerce-ui/components/FormComponents/SelectElement.tsx +++ b/packages/ecommerce-ui/components/FormComponents/SelectElement.tsx @@ -3,7 +3,7 @@ import type { ControllerProps, FieldValues } from '@graphcommerce/react-hook-for import { useController } from '@graphcommerce/react-hook-form' import { i18n } from '@lingui/core' import type { TextFieldProps } from '@mui/material' -import { MenuItem, TextField } from '@mui/material' +import { MenuItem, TextField, useForkRef } from '@mui/material' type OptionBase = { id: string | number; label: string | number } @@ -63,7 +63,7 @@ export function SelectElement { let item: number | string | O | undefined = event.target.value if (type === 'number') item = Number(item) diff --git a/packages/ecommerce-ui/components/FormComponents/TextFieldElement.tsx b/packages/ecommerce-ui/components/FormComponents/TextFieldElement.tsx index 5aad4d5e31..ad679fdc4a 100644 --- a/packages/ecommerce-ui/components/FormComponents/TextFieldElement.tsx +++ b/packages/ecommerce-ui/components/FormComponents/TextFieldElement.tsx @@ -4,7 +4,7 @@ import type { FieldValues, UseControllerProps } from '@graphcommerce/react-hook- import { emailPattern, useController } from '@graphcommerce/react-hook-form' import { i18n } from '@lingui/core' import type { TextFieldProps } from '@mui/material' -import { TextField } from '@mui/material' +import { TextField, useForkRef } from '@mui/material' import React, { useState } from 'react' export type TextFieldElementProps = Omit< @@ -68,7 +68,7 @@ export function TextFieldElement({ onChange(type === 'number' && ev.target.value ? Number(ev.target.value) : ev.target.value) rest.onChange?.(ev) }} - inputRef={ref} + inputRef={useForkRef(ref, rest.inputRef)} required={required} type={type} error={Boolean(error) || rest.error}