Select: closed trigger keeps the first label it learned; a changed item label never shows

Open
#508 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
react, typescript
Domain
frontend

Research direction

Start in foundation/lists/listbox-value.js, where selection.learn runs only on the first call and listbox.remember caches the label. Reproduce with the Select example in the issue, where the trigger keeps showing Unknown · 0 after the item label changes. Done means the closed SelectValue shows the selected item's current label, and a test covers a label that changes while the list is closed. Choosing when to re-learn is a design decision, so confirm the approach with maintainers first.

Written by the indexing model from the issue text.

Description

@ui-sdk/core 0.1.0-beta.2, Select: while the list is closed, the trigger keeps the label it first learned for the selected value. When that item's label changes later (a count in it, a name that depends on another field), SelectValue still shows the old text until the list is opened.

Cause: selection.learn (foundation/lists/listbox-value.js) runs once ("Only the first call looks") and listbox.remember caches the label; the items are not mounted while closed, so nothing updates it.

Repro

function Demo() {
  const [n, setN] = useState(0)
  return (
    <>
      <Select defaultValue="a">
        <SelectTrigger><SelectValue /></SelectTrigger>
        <SelectContent><SelectItem value="a">Unknown · {n}</SelectItem></SelectContent>
      </Select>
      <button onClick={() => setN(n + 1)}>+1</button>
    </>
  )
}

Press +1: the trigger still says Unknown · 0. A native <select> shows Unknown · 1.

Expected: the closed trigger shows the selected item's current label, as a native select does.

Workaround we use: itemToLabel from the current children, and a SelectValue render function returning that label.

Dominant language
TypeScript
Stars
4.4k
Forks
122
Avg merge
3h 12m
Merged PRs (30d)
437

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vercel-labs/ui

All issues in vercel-labs/ui

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.