digdir / designsystemet

Designsystemet
https://designsystemet.no
MIT License
68 stars 34 forks source link

in ComboboxOption if value is a string of a number it gets converted to number #2081

Closed PieNappl3 closed 3 weeks ago

PieNappl3 commented 1 month ago

Description of the bug

when adding a map of comboboxoptions and the value parameter is set to something like '3000' the string is converted to number and the page crashes when writing anything in the search box

Steps To Reproduce

create combobox with at least 2 options where values are numbers, does not happen if the number is something like '0001' but does happen if it is something like '1000'

<ComboboxOption
  id={'3000'}
  key={'3000'}
  value={'3000'}>
  some value
</ComboboxOption>
<ComboboxOption
  id={'2000'}
  key={'2000'}
  value={'2000'}>
  some other value
</ComboboxOption>

this does not seem to be an issue on the key param then when writing 'some o' and one of the options are supposed to be removed it will instead throw an error unhandled runtime error typeError: instance.parentNode is null

Additional Information

No response

Barsnes commented 1 month ago

Hi, thanks for the bug report!

This is most likely due to us using the value as a key in an object - and should not be a problem to make sure we use the key as a string. I believe an object always tries to use the key as a number if it can.

PieNappl3 commented 1 month ago

forgot to add that this was not an issue in version 0.56.2, just in case that is helpful :)

Barsnes commented 1 month ago

forgot to add that this was not an issue in version 0.56.2, just in case that is helpful :)

No worries, this should still be an issue today, since we are not making sure the keys are strings

Barsnes commented 1 month ago

I created a codesandbox that replicates this issue: https://codesandbox.io/p/sandbox/combobox-number-option-xh49zp