Skip to content

[combobox] Add createItems collection API - #5326

Merged
atomiks merged 50 commits into
mui:masterfrom
atomiks:claude/ecstatic-ardinghelli-bfa7ae
Aug 11, 2026
Merged

atomiks merged 50 commits into
mui:masterfrom
atomiks:claude/ecstatic-ardinghelli-bfa7ae

Conversation

@atomiks

@atomiks atomiks commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Closes #5228.
Closes #4735.
Closes #3865.

Problem

Combobox treats each item as both the source data rendered by collection callbacks and the public value used by value, selection events, equality, and form submission. This works when applications want the selected record, but it is awkward when they render rich objects while storing primitive IDs. Deriving the ID on <Combobox.Item> is too late because the root needs values and labels before items mount, including for the initial input value, <Combobox.Value>, closed-trigger typeahead, autofill, and virtualization.

Solution

API designed by @jjenzz.

Adds the pure Combobox.createItems() factory, which produces an opaque collection for the root's items prop.

const users: User[] = [
  { id: 1, name: 'Alice' },
  { id: 2, name: 'Bob' },
];

const items = Combobox.createItems(users, {
  getValue: (user) => user.id,
  getLabel: (user) => user.name,
});

export function Example() {
  return (
    <Combobox.Root items={items} defaultValue={1}>
      <Combobox.List>
        {(user) => (
          <Combobox.Item key={user.id} value={user.id}>
            {user.name}
          </Combobox.Item>
        )}
      </Combobox.List>
    </Combobox.Root>
  );
}

Every API sits on one side of the source item / derived value split:

Receives the source item Receives the derived value
<List> and <Collection> function children value, defaultValue, and onValueChange
useFilteredItems(), filteredItems, and the root filter The <Combobox.Item value> prop
The getValue and getLabel accessors isItemEqualToValue, itemToStringValue, and itemToStringLabel
onItemHighlighted and <Combobox.Value> children
  • The collection lazily indexes its data, so labels resolve while the list is closed or virtualized without running accessors during collection creation.
  • getLabel labels values the collection can resolve. The root's itemToStringLabel is the fallback for values it cannot resolve.
  • Data may be flat or grouped, and accessors always receive leaf items. Filtering stays in the source item domain, while selection, equality, serialization, typeahead, and autofill use derived values.
  • filteredItems remains in the source item domain. Its current window can resolve labels, but no previous window is retained.
  • Derived values must be stable, unique, non-null primitives. null and undefined remain reserved for no selection.

Why the collection is opaque

The collection intentionally has no public lookup API. Resolving a derived value consistently can depend on the root's current filteredItems and isItemEqualToValue, so a collection-level get could disagree with the root or encourage treating the collection as a cache. Applications still own the source data and can maintain their own lookup when needed. The opaque type also allows a public lookup API to be added compatibly later if a concrete use case emerges.

An end-to-end test covers the #5228 use case.

TypeScript compatibility

This PR narrows filteredItems and filter from any to the source item type. Existing code that passes object items while using primitive selection values may now produce TypeScript errors.

That combination was not consistently supported at runtime. Selection, label resolution, filtering, and equality could operate on different shapes. For example, the original #4735 pattern displayed the primitive value "1" instead of the item label "Apple" after selection.

Migrate these cases to createItems() with getValue and getLabel. Code whose items and selection values already use the same type is unaffected.

Note

This is a type-level breaking change. Existing plain-array runtime behavior is unchanged, but code that relied on mismatched item and selection-value types may now fail to compile. That configuration was already inconsistently supported at runtime and should migrate to createItems().

When to keep object values

Use createItems when application state should store a primitive ID and looking up the corresponding record when needed is acceptable. Rendering and filtering still receive source objects, while selection callbacks, equality, and form submission use the derived primitive.

Keep object values when the selected value itself must carry metadata, for example, callbacks outside Combobox.Root, rich chips, or selected-value content requiring more than a label. With object values, itemToStringLabel resolves the label directly from the value, and isItemEqualToValue can match refreshed instances by ID.

Async loading alone does not decide which model to use. With createItems, getLabel can resolve an ID while its source item is present in the collection data or current filteredItems. For paginated search, keep the selected record alongside the current results, or provide an itemToStringLabel fallback backed by application data.

A possible follow-up API improvement would be passing the resolved label as a second argument to <Combobox.Value> children:

<Combobox.Value>
  {(value, label) => /* custom rendering */}
</Combobox.Value>

This would make primitive values more convenient for custom rendering inside Combobox.Root. Because <Combobox.Value> consumes root context, it would not expose the label or source record to onValueChange or application code outside the root. Those consumers would still need an application-owned lookup or object values. This API is not part of this PR.

Select

Select already accepts value-to-label metadata through its items prop and has no source item render/filter split, so this PR does not add Select.createItems.

Bundle impact

The standalone factory tree-shakes when unused. The Combobox integration cost is tracked by the bundle-size CI check.

@atomiks atomiks added component: combobox Changes related to the combobox component. type: new feature Expand the scope of the product to solve a new problem. labels Jul 23, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@5326
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@5326
    

commit: c81f993

@code-infra-dashboard

code-infra-dashboard Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+1.29KB(+0.29%) 🔺+592B(+0.40%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@atomiks
atomiks force-pushed the claude/ecstatic-ardinghelli-bfa7ae branch 2 times, most recently from 0b1d7ad to 987f2c6 Compare July 23, 2026 23:46
@netlify

netlify Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit c81f993
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a7ad3d04385cb0008082ebb
😎 Deploy Preview https://deploy-preview-5326--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@atomiks
atomiks force-pushed the claude/ecstatic-ardinghelli-bfa7ae branch 2 times, most recently from e5dd55e to 065536c Compare July 24, 2026 12:56
@atomiks atomiks added component: autocomplete Changes related to the autocomplete component. and removed component: autocomplete Changes related to the autocomplete component. labels Jul 27, 2026
@atomiks
atomiks force-pushed the claude/ecstatic-ardinghelli-bfa7ae branch 2 times, most recently from a2b68e6 to 3e96a0a Compare July 28, 2026 04:56
@atomiks atomiks changed the title [combobox] Add useItems collection API [combobox] Add createItems collection API Jul 28, 2026
@atomiks
atomiks marked this pull request as ready for review July 28, 2026 06:41
@atomiks
atomiks force-pushed the claude/ecstatic-ardinghelli-bfa7ae branch from ae33f2e to 1425ec5 Compare July 28, 2026 21:56
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 28, 2026
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 31, 2026
@atomiks
atomiks force-pushed the claude/ecstatic-ardinghelli-bfa7ae branch from 407eac3 to 6b8bc73 Compare August 3, 2026 23:36
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Aug 3, 2026
@atomiks
atomiks force-pushed the claude/ecstatic-ardinghelli-bfa7ae branch from e550195 to 39d3c7c Compare August 5, 2026 06:24
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Aug 5, 2026
@atomiks
atomiks force-pushed the claude/ecstatic-ardinghelli-bfa7ae branch from 86b9034 to ffc589f Compare August 7, 2026 04:38
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Aug 7, 2026
@atomiks
atomiks force-pushed the claude/ecstatic-ardinghelli-bfa7ae branch 4 times, most recently from e8995f3 to 936fb36 Compare August 11, 2026 03:41
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Aug 11, 2026
@atomiks
atomiks force-pushed the claude/ecstatic-ardinghelli-bfa7ae branch from 936fb36 to d8777a7 Compare August 11, 2026 04:03
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Aug 11, 2026
…-5326-final

# Conflicts:
#	packages/react/src/combobox/root/AriaCombobox.tsx
@atomiks
atomiks force-pushed the claude/ecstatic-ardinghelli-bfa7ae branch from d8777a7 to 544bcac Compare August 11, 2026 04:21
@atomiks

atomiks commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@claude review low

@github-actions

github-actions Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

PR review

Nothing here is merge-blocking. The createItems() collection is cleanly isolated — the source-item/derived-value split is threaded consistently through flatFilteredValues, valuesRef, labelsRef, and the store, and the plain-array path is unchanged in every branch I traced. The AutocompleteRoot filter refactor is behaviour-equivalent to the code it replaces for all four mode values, with the inline-completion query now carried by the new internal filterQuery prop instead of a wrapper closure. Two smaller items below. This ran at low effort, so tests, simplifications, and docs were out of scope — see the closing note for one docs artifact I noticed in passing but did not investigate.

Bugs (2)

1. 🟡 useFilter() cannot label a collection's derived value, so external filtering loses the selection bypass

Location: packages/react/src/combobox/root/utils/index.ts:53

const selectedValueToString = itemToStringLabel?.selected ?? itemToStringLabel;
const selectedString =
  selectedValue != null ? stringifyAsLabel(selectedValue, selectedValueToString) : '';

The .selected escape hatch is only ever attached by AriaCombobox's internal filterItemToString (AriaCombobox.tsx:235). That covers the case where a consumer passes filter={comboboxFilter.contains} to the root, because the root then supplies the augmented itemToString. It does not cover the case where a consumer calls filter.contains(item, query) themselves to compute filteredItems — which is the shape the new async-window docs section pushes people toward (docs/.../combobox/page.mdx, "Displaying a window of async results").

In that path selectedValue is a derived primitive while itemToString is a source-item accessor, so the two domains are mismatched and selectedString collapses to '' (or to the stringified ID when no itemToString is passed). The "keep every item visible while the query still matches the selection" behaviour that UseComboboxFilterOptions.value documents then silently never fires, while the equivalent internal path (shouldBypassFiltering, AriaCombobox.tsx:341) still does.

Failure scenario: Combobox.createItems(users, { getValue: u => u.id, getLabel: u => u.name }), single select, value={selectedUserId} (say 3, "Alice"). The consumer filters externally with const filter = Combobox.useFilter({ value: selectedUserId }) and filter.contains(user, query, u => u.name). Reopening the popup with the input showing "Alice" narrows the list to items matching "Alice" instead of showing the full list, unlike the same combobox using internal filtering.

Fix: give useComboboxFilter a way to label the selected value in the value domain — e.g. a second itemToStringLabel/valueToString option on UseComboboxFilterOptions that createSingleSelectionCollatorFilter prefers — or document that value should be omitted when filtering a createItems() collection externally.

2. ℹ️ isGroupedItems now does a full O(n) consistency scan in dev on an unmemoized label path

Location: packages/react/src/internals/resolveValueLabel.tsx:30

if (process.env.NODE_ENV !== 'production' && items?.some((item) => isGroup(item) !== grouped)) {

The check itself is a good guard, but it runs on every isGroupedItems() call, and flattenLeafItems → isGroupedItems sits on resolveSelectedLabel, which ComboboxValue/SelectValue call directly in the render body (once per selected value via resolveMultipleLabels). For the flat-array case this turns what was an O(1) check into an O(n) scan on a hot dev path shared with Select, which this PR does not otherwise touch.

Failure scenario: a multi-select Select or Combobox with ~5k items and ~50 chips does ~250k extra isGroup calls per render in development; production is unaffected, but typing feels sluggish in dev only. Hoisting the check behind a WeakSet of already-validated arrays (or running it once per items identity in AriaCombobox rather than inside the shared helper) keeps the diagnostic without the per-call cost.

Fix: memoize the consistency check per items reference instead of re-running it on every isGroupedItems() call.

Verdict

Approve after nits — no correctness regression found in the collection plumbing or the AutocompleteRoot filter refactor; the useFilter() gap is a narrow new-API limitation worth closing or documenting.

One thing spotted but not reviewed at this effort level: the generated docs/.../combobox/types.md:1057 renders the internal RejectGroupShapedItems error string as the type of createItems' data parameter, and docs/.../autocomplete/types.md:28 now carries a createItems() sentence for a component that does not accept collections. Both look like pnpm docs:api artifacts rather than intentional prose.


🤖 Review generated with Claude Code · Opus 5 (High) · low review depth · 44 turns · 9m38s · $3.07 · run

@atomiks
atomiks merged commit 0893836 into mui:master Aug 11, 2026
6 checks passed
@atomiks
atomiks deleted the claude/ecstatic-ardinghelli-bfa7ae branch August 11, 2026 07:56
arturbien added a commit to whopio/frosted-ui that referenced this pull request Sep 8, 2026
## Summary

Upgrades `@base-ui/react` from `^1.7.0` → `^1.8.0` (latest, published
Sep 4, 2026).

No Frosted UI source changes were required. Validated locally:
- `tsc` (CJS + ESM) ✅
- `eslint` + `stylelint` ✅
- `vitest` — 312/312 tests passing ✅

Sources: [Base UI v1.8.0 release
notes](https://base-ui.com/react/overview/releases/v1-8-0), [GitHub
CHANGELOG](https://github.com/mui/base-ui/blob/master/CHANGELOG.md).

---

## Breaking changes

**Official changelog marks no breaking changes in v1.8.0.**

A few behavioral / API additions consumers (and Frosted UI wrappers)
should be aware of:

| Area | Change |
|---|---|
| Avatar | New `keepMounted` prop on `<Avatar.Image>`
([#5536](mui/base-ui#5536)) — Frosted already
forwards image props, so this is available automatically |
| Combobox | New `createItems` collection API
([#5326](mui/base-ui#5326)) |
| Toast | `update()` can take a function derived from the current toast
([#5464](mui/base-ui#5464),
[#5611](mui/base-ui#5611),
[#5629](mui/base-ui#5629)) |
| Autocomplete / Combobox / Select | Popup can open and be browsed while
`readOnly` ([#5541](mui/base-ui#5541),
[#5531](mui/base-ui#5531)) |
| Navigation Menu | Focus stays on the trigger when opening
([#5479](mui/base-ui#5479)) |
| Field | Neutral validity is published while async validation is in
flight ([#5600](mui/base-ui#5600)) |
| Dialog / Alert Dialog / Popover | Outside clicks from presses that
began before open are ignored
([#5378](mui/base-ui#5378)) |
| Scroll Area | Scrollbars no longer steal focus
([#5430](mui/base-ui#5430)) |

### Frosted UI impact assessment

| Concern | Status |
|---|---|
| Compile / typecheck against 1.8.0 | Passes with no source edits |
| Existing `DialogRootActions` / `AlertDialogRootActions` imports |
Still exported |
| `useRender` / `mergeProps` | Unchanged public surface |
| Toast manager `update()` | Still compatible; functional updates are
additive |
| Combobox `useFilter` re-export | Still present |

---

## Full v1.8.0 changelog (from
[upstream](https://base-ui.com/react/overview/releases/v1-8-0))

_Sep 4, 2026_

### General changes

- Fix label association when a control unregisters (#5456)
- Reduce animation completion work (#5535)
- Fix prop and ref merging for lazy render elements (#5562)
- Fix roving focus when items are added or removed (#5447)
- Fix hover and focus interaction issues (#5037)
- Improve trigger mount performance (#5426)
- Fix disabled anchor tracking on scroll (#5478)
- Fix transform origin for start/end alignment (#5015)
- Remove duplicate options key from arrow middleware (#5606)
- Register passive touch listeners (#5572)

### Alert Dialog

- Ignore outside clicks from presses that began before open (#5378)

### Autocomplete

- Render groups with the rowgroup role in grid mode (#5564)
- Allow opening and browsing the popup while `readOnly` (#5541)
- Move `aria-orientation` to the role owners (#5551)
- Hide group labels and scrollbars from the accessibility tree (#5598)

### Avatar

- Add `keepMounted` prop to `<Avatar.Image>` (#5536)

### Checkbox

- Fix stale and duplicated control IDs (#5457)
- Fix controlled blur validation and stale filled state (#5563)

### Checkbox Group

- Fix stale and duplicated control IDs (#5457)

### Combobox

- Fix applying `data-readonly` to `<Combobox.Trigger>` (#5418)
- Add `createItems` collection API (#5326)
- Fix cancellation when preserving the filter after selection (#5362)
- Render groups with the rowgroup role in grid mode (#5564)
- Allow opening and browsing the popup while `readOnly` (#5541)
- Move `aria-orientation` to the role owners (#5551)
- Fix record item label lookup reading from `Object.prototype` (#5518)
- Anchor multiple selection to the first selected item with a linear
lookup (#5573, #5613)
- Hide group labels and scrollbars from the accessibility tree (#5598)

### Dialog

- Ignore outside clicks from presses that began before open (#5378)

### Drawer

- Ignore swipes without an attributed direction when using snap points
(#5477)
- Respect canceled snap point dismissal (#5571)
- Ignore the page scroller when starting a swipe (#5567)

### Field

- Fix custom validity ownership and validation lifecycle (#5449)
- Sync controlled value changes with field state (#5460)
- Fix stale and duplicated control IDs (#5457)
- Validate once on Enter inside a Form (#5459)
- Publish neutral validity while async validation is in flight (#5600)
- Fix controlled blur validation and stale filled state (#5563)

### Form

- Fix `clearErrors` dropping updates when multiple fields change at once
(#5446)

### Menu

- Play the enter transition for an initially open submenu (#4383)
- Move `aria-orientation` to the role owners (#5551)
- Hide group labels and scrollbars from the accessibility tree (#5598)

### Menubar

- Fix menubar accessibility tree to satisfy `aria-required-children`
(#5058)

### Navigation Menu

- Fix pointer-events lock when sweeping quickly across a trigger (#5454)
- Keep focus on trigger when opening (#5479)
- Add disabled data attribute to `<NavigationMenu.Trigger>` (#5521)

### Number Field

- Stop incrementing when disabled during press-and-hold (#5435)
- Prevent scrubbing on horizontal wheel events (#5463)
- Preserve native and consumer-controlled selection when focusing the
input (#5578, #5619)

### Popover

- Ignore outside clicks from presses that began before open (#5378)
- Fix detached trigger store migration (#5442)

### Scroll Area

- Hide group labels and scrollbars from the accessibility tree (#5598)
- Prevent scrollbars from stealing focus (#5430)

### Select

- Move `aria-orientation` to the role owners (#5551)
- Anchor multiple selection to the first selected item with a linear
lookup (#5573, #5613)
- Hide group labels and scrollbars from the accessibility tree (#5598)
- Fix the root ID being ignored inside a Field (#5461)
- Remove redundant size check in `<Select.Positioner>` (#5469)
- Allow opening and browsing the popup while `readOnly` (#5531)
- Fix record item label lookup reading from `Object.prototype` (#5518)

### Slider

- Prevent update loops from unstable refs (#5441)

### Switch

- Fix controlled blur validation and stale filled state (#5563)

### Tabs

- Prevent update loops from unstable refs (#5441)
- Consider 3D transforms when positioning the indicator (#4852)

### Toast

- Allow functional toast updates derived from the current toast (#5464,
#5611, #5629)

### Tooltip

- Respect trigger delay with zero provider delay (#5444)

---

## Test plan

- [x] Bump `@base-ui/react` to `^1.8.0` and refresh lockfile
- [x] `pnpm --filter=frosted-ui exec tsc --project tsconfig-esm.json
--noEmit`
- [x] `pnpm --filter=frosted-ui build:js` (CJS + ESM)
- [x] `pnpm --filter=frosted-ui lint`
- [x] `pnpm --filter=frosted-ui test` (312 tests)
- [x] CI green on this PR
- [ ] Spot-check Storybook surfaces that wrap Base UI heavily (Combobox,
Select, Dialog, Menu, Toast, Field) if desired before merge


Made with [Cursor](https://cursor.com)

Co-authored-by: Cursor <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: combobox Changes related to the combobox component. type: new feature Expand the scope of the product to solve a new problem.

Projects

None yet

2 participants