Skip to content

Commit 27c2386

Browse files
committed
fix: code-rabbit feedbacks
1 parent 083d63a commit 27c2386

File tree

3 files changed

+50
-9
lines changed

3 files changed

+50
-9
lines changed

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

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ test('should have no a11y violations', async () => {
5757
expect(results).toHaveNoViolations();
5858
});
5959

60-
test('should select radio on click', async () => {
60+
test('should select radio on button click', async () => {
6161
const user = setupUser();
6262
const mockedSubmit = vi.fn();
6363

@@ -91,6 +91,43 @@ test('should select radio on click', async () => {
9191
expect(mockedSubmit).toHaveBeenCalledWith({ bear: 'pawdrin' });
9292
});
9393

94+
test('should select radio on label click', async () => {
95+
const user = setupUser();
96+
const mockedSubmit = vi.fn();
97+
98+
render(
99+
<FormMocked
100+
schema={z.object({ bear: z.string() })}
101+
useFormOptions={{ defaultValues: { bear: '' } }}
102+
onSubmit={mockedSubmit}
103+
>
104+
{({ form }) => (
105+
<FormField>
106+
<FormFieldLabel>Bearstronaut</FormFieldLabel>
107+
<FormFieldController
108+
type="radio-group"
109+
control={form.control}
110+
name="bear"
111+
options={options}
112+
/>
113+
</FormField>
114+
)}
115+
</FormMocked>
116+
);
117+
118+
const radio = screen.getByRole('radio', { name: 'Buzz Pawdrin' });
119+
const label = screen.getByText('Buzz Pawdrin');
120+
121+
expect(radio).not.toBeChecked();
122+
123+
// Test clicking the label specifically
124+
await user.click(label);
125+
expect(radio).toBeChecked();
126+
127+
await user.click(screen.getByRole('button', { name: 'Submit' }));
128+
expect(mockedSubmit).toHaveBeenCalledWith({ bear: 'pawdrin' });
129+
});
130+
94131
test('should handle keyboard navigation', async () => {
95132
const user = setupUser();
96133
const mockedSubmit = vi.fn();

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,15 @@ export const FieldRadioGroup = <
7777
>
7878
{options.map(({ label, ...option }) => {
7979
if (renderOption) {
80-
return renderOption({
81-
key: `${ctx.id}-${option.value}`,
82-
label,
83-
...option,
84-
});
80+
return (
81+
<React.Fragment key={`${ctx.id}-${option.value}`}>
82+
{renderOption({
83+
label,
84+
onBlur,
85+
...option,
86+
})}
87+
</React.Fragment>
88+
);
8589
}
8690

8791
return (

app/components/ui/radio-group.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ export function Radio({ children, className, noLabel, ...rest }: RadioProps) {
2727
const compProps = noLabel
2828
? {}
2929
: {
30-
className: 'flex items-center gap-2',
30+
className: 'flex items-center gap-2 text-sm',
3131
};
3232
return (
3333
<Comp {...compProps}>
3434
<RadioPrimitive.Root
3535
className={cn(
36-
'peer size-5 cursor-pointer rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50',
36+
'peer size-4 cursor-pointer rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50',
3737
className
3838
)}
3939
{...rest}
4040
>
4141
<RadioPrimitive.Indicator className="flex items-center justify-center">
42-
<Circle className="size-3 fill-current text-current" />
42+
<Circle className="size-2.5 fill-current text-current" />
4343
</RadioPrimitive.Indicator>
4444
</RadioPrimitive.Root>
4545
{children}

0 commit comments

Comments
 (0)