Skip to content

[combobox] value gets cleared if shape of value differs from items #3865

@freshgiammi

Description

@freshgiammi

Bug report

Current behavior

Currently, there seems to be an issue where the Combobox's value get cleared everytime the user performs a selection if the shape of items does not match the one of value.

A problematic usage looks like this:

type User = { id: string; name: string; email: string }

const users: User[] = [
  { id: "u1", name: "Alice Johnson", email: "alice.johnson@example.com" },
  { id: "u2", name: "Bob Smith", email: "bob.smith@example.com" },
  { id: "u3", name: "Charlie Lee", email: "charlie.lee@example.com" }
]

return (
  <Combobox.Root items={users}>
    {/* when rendering items: */}
    {(item: User) => <Combobox.Item value={item.id}>{item.name}</Combobox.Item>}
  </Combobox.Root>
)


Selecting items that set the value as something different that the full item cause the value to be updated, but removed immediately after - the origin of this issues seems to be this effect.

Additionally, the effect invokes isItemEqualToValue with a possibly invalid first argument (at least, considering this shape) since Value might be different to the items value provided to Combobox.Root.

#3824 fixes this by removing the effect, but I'm opening an issue anyway since this appears to be a different issue to the two that the PR fixes.

Expected behavior

The Combobox shouldn't clear valid values only because the items and value objects differ (or if it should, the signature for isItemEqualToValue should be less restricted)

Reproducible example

https://stackblitz.com/edit/yichkwiw?file=src%2FApp.tsx

Base UI version

v1.1.0

Which browser are you using?

Chrome

Which OS are you using?

MacOS

Which assistive tech are you using (if applicable)?

Voiceover/JAWS etc.

Additional context

Provide any additional context that might help us identify the problem and find a solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: comboboxChanges related to the combobox component.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions