nulogy / design-system

Nulogy Design System
http://nulogy.design
MIT License
64 stars 13 forks source link

RadioGroup event does not contain the original value of its child Radio input #1284

Closed haideralsh closed 6 months ago

haideralsh commented 8 months ago

Describe the bug

When using the RadioGroup component, the value returned from the onChange event does not always have the type of the value that was passed in to the Radio.

Steps to reproduce

Notice how in the onChange event handler we have to parseInt, since the value returned is a string, whereas the value of any of the Radio inputs inside the group is a number.

<RadioGroup
    checkedValue={value}
    labelText="My radio buttons"
    onChange={(event) => { setValue(parseInt(event.target.value)) }}
>
    <Radio value={2} labelText="2 digits" />
    <Radio value={4} labelText="4 digits" />
    <Radio value={6} labelText="6 digits" />
</RadioGroup>

Expected behaviour

RadioGroup should return the same value and type of the value passed to the Radio input

<RadioGroup
    checkedValue={value}
    labelText="My radio buttons"
    onChange={(event) => { setValue(parseInt(event.target.value)) }}
>
    <Radio value={2} labelText="2 digits" />
    <Radio value={4} labelText="4 digits" />
    <Radio value={6} labelText="6 digits" />
</RadioGroup>

Is your team blocked from moving forward by the bug?

No we're not blocked.

Who would you like to fix the bug?

Screenshots

No response

Additional context

No response

haideralsh commented 6 months ago

Closing this issue as this is the expected behaviour for this component. In HTML, passing a number value to an input and calling onChange on that input with typeof input.target.value will always print string. I think we should keep the HTML standard.