-
Notifications
You must be signed in to change notification settings - Fork 34
Description
Describe the bug
I ran into a couple issues writing a component based on Combobox with trying to provide an initial value.
I'm using a $bindable() value for setting the initial value and observing changes. Starting with a simple setup like this, when the value was populated by the caller the initial value was not displayed in the Combobox. I needed to open and select a value:
let { value = $bindable(), labelFunc } = $props();
const combobox = new Combobox<T>({
value: () => value,
onValueChange: (v: T) => {
value = v;
},
});
Adding combobox.select(value); also did not update the value. Looking in the source, I realized part of the issue was that the Combobox did not have a cached value for the label since the UI had not rendered yet at that time.
Adding combobox.getOption(value, label(value)); before select() ensured that the label was cached and it displayed the selected value.
Is there another pattern I should be following here for pre-selecting a value? Or maybe the Combobox needs some additional reactivity to update its internal state and display the label once the selected option is rendered?
Reproduction
Logs
System Info
System:
OS: macOS 26.0.1
CPU: (8) arm64 Apple M1
Memory: 162.59 MB / 16.00 GB
Shell: 4.0.8 - /opt/homebrew/bin/fish
Binaries:
Node: 22.20.0 - ~/.volta/tools/image/node/22.20.0/bin/node
npm: 10.9.3 - ~/.volta/tools/image/node/22.20.0/bin/npm
pnpm: 7.13.2 - ~/.volta/bin/pnpm
Browsers:
Safari: 26.0.1Severity
annoyance