Skip to content

Commit

Permalink
consolidate radiogroup id
Browse files Browse the repository at this point in the history
  • Loading branch information
ccatherinetan committed Dec 23, 2024
1 parent ff5465c commit 546451e
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions components/RadioGroup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,30 @@ export default function RadioGroup<T>({

return (
<ComponentContainer>
{options.map(option => (
<RadioButton
key={String(option.value)}
$isSelected={selectedValue === option.value}
onClick={() => handleChange(option.value)}
>
<RadioLabel
{options.map(option => {
const id = option.label + '-radio';
return (
<RadioButton
key={String(option.value)}
$isSelected={selectedValue === option.value}
htmlFor={option.label + '-radio'}
onClick={() => handleChange(option.value)}
>
{option.label}
</RadioLabel>
<RadioInput
name={name}
value={String(option.value)}
checked={selectedValue === option.value}
onChange={() => handleChange(option.value)}
id={option.label + '-radio'}
/>
</RadioButton>
))}
<RadioLabel
$isSelected={selectedValue === option.value}
htmlFor={id}
>
{option.label}
</RadioLabel>
<RadioInput
name={name}
value={String(option.value)}
checked={selectedValue === option.value}
onChange={() => handleChange(option.value)}
id={id}
/>
</RadioButton>
);
})}
</ComponentContainer>
);
}
Expand Down

0 comments on commit 546451e

Please sign in to comment.