Skip to content

fix(select): keep bind:value and onChange$ in step with the user's pick - #1241

Merged
maiieul merged 1 commit into
qwikifiers:mainfrom
maiieul:fix/select-value-sync
Nov 20, 2026
Merged

maiieul merged 1 commit into
qwikifiers:mainfrom
maiieul:fix/select-value-sync

Conversation

@maiieul

@maiieul maiieul commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

What is it?

  • Bug

Description

Closes #1234, closes #1235, closes #1236, closes #1237, closes #1238.

The Select matched bind:value as a substring, dropped empty option values, never wrote a pick back to a bind:value that started empty, and ran onChange$ for values the parent set (and twice per pick). It also waited for onChange$ before it showed the pick. It now matches values exactly, keeps '', writes back every pick, runs onChange$ once per pick only, and no longer awaits it.

bind:value is now updated before onChange$ runs, as a native <select> updates its value before change.

const relation = useSignal('SISTER');

<Select.Root bind:value={relation} onChange$={(value) => console.log(value)}>
  <Select.Trigger>
    <Select.DisplayValue placeholder="Select an option" />
  </Select.Trigger>
  <Select.Popover>
    <Select.Item value=""><Select.ItemLabel>Anyone</Select.ItemLabel></Select.Item>
    <Select.Item value="BROTHER"><Select.ItemLabel>Brother</Select.ItemLabel></Select.Item>
    <Select.Item value="OTHER"><Select.ItemLabel>Other</Select.ItemLabel></Select.Item>
    <Select.Item value="SISTER"><Select.ItemLabel>Sister</Select.ItemLabel></Select.Item>
  </Select.Popover>
</Select.Root>
Before After
bind:value starts as BROTHER shows "Other" shows "Brother"
Pick "Brother" ends on "Other", onChange$ gets SISTER, OTHER, OTHER "Brother", onChange$ gets BROTHER
Pick "Anyone" bind:value is Anyone bind:value is ''
bind:value starts as '', no "Anyone" option, pick "Sister" bind:value stays '' bind:value is SISTER
Parent sets bind:value to SISTER onChange$ runs onChange$ doesn't run
onChange$ takes 3 s the pick shows after over 3 s the pick shows at once
select.test.ts
└─ Props
   ✓ GIVEN a select with an onChange$ prop WHEN the select value changes THEN the placeholder should be presented instead of a selected value
   ├─ controlled
   │  ✓ GIVEN a controlled select with a bind:value prop on the root component WHEN the signal data matches the second option THEN …
   │  ✓ GIVEN a controlled closed select with a bind:open prop on the root component WHEN the bind:open signal changes to true THEN …
   ├─ option value
   │  ✓ GIVEN a select with distinct display and option values WHEN the 2nd option is selected THEN …
   │  ✓ GIVEN a select with distinct display and option values WHEN a controlled value is set to the 5th option THEN …
   │  ✓ GIVEN a select with distinct display and option values WHEN the 5th option is selected AND it clicks another option …
   │  + a bind:value chooses the option with that exact value, not one it contains
   │  + picking an option whose value contains another one sets bind:value to it
   │  + picking an option with an empty value sets bind:value to an empty string
   │  + an empty bind:value chooses the option with an empty value
   │  + a pick updates a bind:value that starts empty
   └─ onChange$
      + runs once for a pick
      + does not run when the parent sets bind:value
      + a pick shows while a slow onChange$ still runs

@pkg-pr-new

pkg-pr-new Bot commented Nov 20, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/qwik-ui@1241
npm i https://pkg.pr.new/@qwik-ui/headless@1241
npm i https://pkg.pr.new/@qwik-ui/styled@1241
npm i https://pkg.pr.new/@qwik-ui/utils@1241

commit: 6665c2b

@maiieul
maiieul merged commit 50576c2 into qwikifiers:main Nov 20, 2026
6 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant