-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
According to doc it is allowed to use values of string type as option.id: https://docs.svar.dev/svelte/core/combo/api/props/options/#usage
But in case there are options with id like "0", "00", "0E1" they can't be selected by mouse.
<script>
import { Combo, Willow } from "@svar-ui/svelte-core";
const ids = ['', '0', '000', '0E1'];
const options = ids.map(id => ({id, label: `"${id}" option`}));
let value = $state(ids.at(-1));
</script>
<Willow>
<Combo {options} bind:value={value} />
<p>Selected option: {JSON.stringify(value)}</p>
</Willow>Playground: https://svelte.dev/playground/ef444580799640838ccc1954887b102d?version=5.44.0
Selection by keyboard works except for option with "" (empty string) id.
As it seems the issue is related to internal usage of data-id attribute.
| data-id={data.id} |
core/svelte/src/components/helpers/listnav.js
Lines 43 to 46 in e2f0f07
| const id = locateID(ev); | |
| // if we have id:"1", the locateID will return 1 as number | |
| // so using non-strict comparison | |
| const index = options.findIndex(a => a.id == id); |
if (typeof value === "string") {
const t = (value as undefined as number) * 1;
if (!isNaN(t)) return t;
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels