Skip to content

Commit 7700b59

Browse files
committed
fix: spread ref for proper focus on error
1 parent df09620 commit 7700b59

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

app/components/form/field-radio-group/docs.stories.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,9 @@ export const WithCustomRadio = () => {
233233
type="radio-group"
234234
name="bear"
235235
options={options}
236-
renderOption={({ value, label, id, key }) => {
236+
renderOption={({ label, ...props }) => {
237237
// We can then customize the render of our field's radios
238-
return (
239-
<CardRadio value={value} id={id} key={key}>
240-
{label}
241-
</CardRadio>
242-
);
238+
return <CardRadio {...props}>{label}</CardRadio>;
243239
}}
244240
/>
245241
</FormField>

app/components/form/field-radio-group/index.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ export const FieldRadioGroup = <
5454
disabled={disabled}
5555
defaultValue={defaultValue}
5656
shouldUnregister={shouldUnregister}
57-
render={({ field: { onBlur, onChange, ...field }, fieldState }) => {
57+
render={({
58+
field: { onBlur, onChange, value, ...field },
59+
fieldState,
60+
}) => {
5861
return (
5962
<div
6063
{...containerProps}
@@ -75,9 +78,9 @@ export const FieldRadioGroup = <
7578
? `${ctx.descriptionId}`
7679
: `${ctx.descriptionId} ${ctx.errorId}`
7780
}
78-
{...rest}
81+
value={value}
7982
onValueChange={onChange}
80-
{...field}
83+
{...rest}
8184
>
8285
{options.map(({ label, ...option }) => {
8386
const radioId = `${ctx.id}-${option.value}`;
@@ -88,14 +91,15 @@ export const FieldRadioGroup = <
8891
{renderOption({
8992
label,
9093
onBlur,
94+
...field,
9195
...option,
9296
})}
9397
</React.Fragment>
9498
);
9599
}
96100

97101
return (
98-
<Radio key={radioId} onBlur={onBlur} {...option}>
102+
<Radio key={radioId} onBlur={onBlur} {...field} {...option}>
99103
{label}
100104
</Radio>
101105
);

0 commit comments

Comments
 (0)