base-ui icon indicating copy to clipboard operation
base-ui copied to clipboard

[combobox] Combobox.Root typing/docs reject autoHighlight="always" although runtime supports it

Open winzamark123 opened this issue 9 months ago • 11 comments

Bug report

Current behavior

Combobox.Root runtime behavior supports autoHighlight="always" (works correctly for async search lists), but TypeScript and docs currently reject/omit it.

  • In internal combobox engine (AriaCombobox) found here , autoHighlight is typed as boolean | 'input-change' | 'always' and runtime logic handles "always".
  • In public Combobox.Root props, autoHighlight is typed as boolean only.
  • The docs API reference for Combobox Root also shows boolean only. This causes valid runtime usage to fail type-checking.

Expected behavior

Combobox.Root public type and docs should allow autoHighlight="always" (matching runtime/internal behavior), so async search use cases can use it without local type workarounds.

Reproducible example

Minimal repro:

import { Combobox } from "@base-ui/react/combobox";
<Combobox.Root
  items={[{ id: "1", label: "One" }]}
  itemToStringLabel={(item) => item.label}
  autoHighlight="always"
/>;

TypeScript error today: Type '"always"' is not assignable to type 'boolean | undefined'.

Base UI version

@base-ui/[email protected] but also latest and in docs

Which browser are you using?

Chrome

Which OS are you using?

Mac OS

Which assistive tech are you using (if applicable)?

N/A

Additional context

Related history:

  • Feature issue: #2922
  • Merged implementation PR: #2976 (autoHighlight: "always" support)

winzamark123 avatar Feb 25 '26 00:02 winzamark123

BAS-426

linear[bot] avatar Feb 25 '26 00:02 linear[bot]

Opened a fix in #4189 that updates Combobox.Root typing/docs for autoHighlight="always" and adds a regression test. Let me know if this works!

winzamark123 avatar Feb 25 '26 00:02 winzamark123

The type here is intentional, despite the runtime (didn't bother adding a guard for it). Is there a reason you want this for combobox?

atomiks avatar Feb 25 '26 00:02 atomiks

The type here is intentional, despite the runtime (didn't bother adding a guard for it). Is there a reason you want this for combobox?

the autohighlight feature doesnt work for async search with autoHighlight = true. For results that are loaded/refreshed async (in my case via a debounce) the new items wont get highlighted.

example with autohighlight = {true} https://github.com/user-attachments/assets/1010dcd3-6ee3-48d8-b7fa-e3c6bc304350

example with autohighlight = "always" https://github.com/user-attachments/assets/c70c19d8-0feb-497e-9139-142429692077

the autohighlight = "always" allows the first item to be preselected (shown as a gray bg in the video) which also allows key event of "enter" to select the first item. Hopes this gives more context! Let me know if it doesn't or if my implementation of combobox might be incorrect in this regard.

winzamark123 avatar Feb 25 '26 02:02 winzamark123

@winzamark123 I think you're looking for the Autocomplete component, check the async example for your use case.

Autocomplete accepts the autoHighlight="always" prop.

 <Autocomplete.Root autoHighlight="always" />

check this demo: https://stackblitz.com/edit/tftek4k4?file=src%2FApp.tsx

CiscoFran10 avatar Feb 25 '26 04:02 CiscoFran10

For results that are loaded/refreshed async (in my case via a debounce) the new items wont get highlighted.

Arguably this is a bug because autoHighlight: true is "highlights while filtering", but it's not handling async items despite the input having filter text

atomiks avatar Feb 25 '26 12:02 atomiks

@winzamark123 I think you're looking for the Autocomplete component, check the async example for your use case.

Autocomplete accepts the autoHighlight="always" prop.

<Autocomplete.Root autoHighlight="always" /> check this demo: https://stackblitz.com/edit/tftek4k4?file=src%2FApp.tsx

this worked out great for me, thank you @CiscoFran10 !

Regarding the bug, this PR #4189 just widens the type, which worked in my case as well but i'm not sure if this is a deeper bug for async items. @atomiks if bandwidth is the issue, you could point to the part of the code that needs investigating, I'll be happy to help!

winzamark123 avatar Feb 25 '26 21:02 winzamark123

Just came across this issue as well. Is there a plan to merge #4189 ? I have to force autoHighlight={'always' as unknown as boolean}

green-mint avatar Mar 22 '26 07:03 green-mint

I'm also facing this issue. I can't use Autocomplete, and I'm basing my implementation on Combobox, as having pills is a strong requirement.

dimitrisnl avatar Jul 30 '26 08:07 dimitrisnl

Having this issue as well. Is there a plan to merge https://github.com/mui/base-ui/pull/4189 ? I have to force autoHighlight={'always' as unknown as boolean}

dwickander-emc avatar Sep 03 '26 15:09 dwickander-emc

To answer "is there a reason you want this for combobox?": we have a picker with a preview pane next to the list, and the preview shows the highlighted item. It needs a selected value (single and multiple), so Autocomplete doesn't fit. The preview should never be empty, so an item has to be highlighted as soon as the popup opens and stay highlighted when the pointer leaves the list: autoHighlight="always" plus keepHighlight. Both already work on Combobox.Root at runtime in 1.9.0; only the types block them (keepHighlight is omitted too):

<Combobox.Root
  items={items}
  {...({ autoHighlight: 'always', keepHighlight: true } as object)}
>

The same picker also sets the highlight from the parent, for example to reopen on the item previewed last. The highlightItem action covered that until #5910 reverted it, and #4745 asks for the same. A controlled highlighted value would cover both.

ItaiYosephi avatar Nov 18 '26 09:11 ItaiYosephi