digdir / designsystemet

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

Combobox: Searching with numbers in multiple mode auto-selects options #2128

Closed mimarz closed 2 weeks ago

mimarz commented 2 weeks ago

Found when testing for bug #2124.

Whenever i type only numbers, it automatically selects options.

Changing the value to be prefixed with something number seems to solve the issue. Maybe we missed something with #2095 where we applied this logic internally.

Forked sandbox with updated next version which was published today: https://codesandbox.io/p/sandbox/broken-night-forked-nrh89r?file=%2Fsrc%2FApp.tsx%3A40%2C25

Barsnes commented 2 weeks ago

This is expected to happen, since we are checking if the input matches a value:

// ComboboxInput.tsx:72

// check if input value is the same as a label, if so, select it
    const option = options[prefix(value.toLowerCase())];
    if (!option) return;
    if (selectedOptions[prefix(option.value)]) return;

This is wrong, and I will fix this - it should check on the display value instead