feat(ui): make inputselect also handle value+label options

This commit is contained in:
2026-05-04 14:11:52 +02:00
parent 59a1e63396
commit 3ee074b11c
7 changed files with 174 additions and 31 deletions
+11 -3
View File
@@ -1,16 +1,24 @@
<script lang="ts">
type SelectOption = string | { value: number; label: string };
interface Props {
options?: string[];
options?: SelectOption[];
value?: number;
id?: string;
}
let { options = [], value = $bindable(0), id = '' }: Props = $props();
const normalized = $derived(
options.map((opt, i) =>
typeof opt === 'string' ? { value: i, label: opt } : opt
)
);
</script>
<select {id} bind:value class="bg-layer-2 text-text">
{#each options as label, i (label)}
<option value={i}>{label}</option>
{#each normalized as opt (opt.value)}
<option value={opt.value}>{opt.label}</option>
{/each}
</select>