You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 8a3bd22
Browse filesBrowse the repository at this point in the historyBrowse files
* feat(Listbox): opt-in `filter` on ListboxRoot (#2824 item 7)
`filter(text, search, value)` on `ListboxRoot` / `useListboxRoot` filters
the items by the `ListboxFilter` value. Filtered-out items stay mounted
but render nothing, so navigation, typeahead, select-all and range
selection only see matches; a group with no match is hidden. In a
`ListboxVirtualizer` the filter runs over `options` (via `textContent`),
so filtered-out options take no virtual index or `aria-setsize` slot.
Omitted or `null`, nothing is filtered (v2 behaviour). Combobox and
Autocomplete keep their own engine until their PR.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* docs(Listbox): regenerate API meta for `filter`
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* fix(Combobox): keep the inner Listbox `filter` off in Combobox and Autocomplete
Both roots forward `$attrs` to their inner `ListboxRoot`, so a `filter`
attribute turned the Listbox filter on through `ComboboxInput` on top of
their own filtering. Bind `:filter="null"` until the Combobox PR moves
them onto it.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* fix(ColorSwatchPicker): omit the inherited Listbox `filter` prop
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* fix(Listbox): filter review follow-ups
- re-measure a reused item whose value changed while filtered out
- clear a virtualized highlight whose option no longer matches
- dev warning for object options filtered without `textContent`
- a group with no registered items stays visible (SSR)
- docs: recommend ListboxVirtualizer for large filtered lists
- tests: typeahead, select-all and Shift ranges over filtered items
(plain and virtualized), `filtered.count`, Combobox/Autocomplete stay inert
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/content/docs/components/listbox.md
+70-2Lines changed: 70 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -89,7 +89,7 @@ Contains all the parts of a listbox. An `input` will also render when used withi
89
89
90
90
### Filter
91
91
92
-
Input element to perform filtering.
92
+
Input element to perform filtering. Its value is the search term the root's `filter` runs against; without a `filter` on the root it only moves the highlight, and you filter the items yourself (see [Filtering](#filtering)).
Pass a `filter` function to `ListboxRoot` to filter the items by the `ListboxFilter` value. It is called as `filter(text, search, value)` with the item's `textValue` (or its text content) and returns whether the item matches. `useFilter` provides locale-aware `contains`, `startsWith` and `endsWith` matchers that fit this signature.
227
+
228
+
Items that do not match are not rendered, so keyboard navigation, typeahead and select-all skip them, and a `ListboxGroup` whose items all fail to match is hidden. Filtering is opt-in: without `filter` (or with `null`) the listbox renders every item.
229
+
230
+
```vue line=5,10
231
+
<script setup lang="ts">
232
+
import { ListboxContent, ListboxFilter, ListboxItem, ListboxRoot, useFilter } from 'reka-ui'
Set `textValue` on an item whose content is not plain text, so the filter matches the text you want. The root exposes the result as `filtered` (`{ search, active, count }`, read it through a template ref), which you can use to render an empty state.
257
+
258
+
Each item stays a mounted component while it is filtered out, and clearing or widening the search renders every item that matches again. For a large list (thousands of items) use a `ListboxVirtualizer`, which only renders the visible window of the matching options.
259
+
260
+
With a `ListboxVirtualizer`, the filter runs over its `options` before they are virtualized: it matches `textContent(option)` (or the option's string form, so pass `textContent` for object options), and a filtered-out option takes no virtual index and does not count in `aria-setsize`.
Copy file name to clipboardExpand all lines: docs/content/docs/guides/migration-v3.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -244,3 +244,7 @@ Two additions come with it:
244
244
- `textValue` on `ListboxItem` sets the text the root's label registry records for the item, and defaults to the item's text content. Set it when the visible content is not plain text (an icon, a component that updates on its own).
245
245
246
246
The `update:modelValue` and `beforeUpdate:modelValue` events of `ListboxRoot` are now typed as `T|T[] |undefined`: an array with `multiple`, and `undefined` when a single selection is cleared. A handler typed for a single `T` may need widening; the runtime payload is unchanged.
247
+
248
+
## Listbox filtering
249
+
250
+
`ListboxRoot` has a new, opt-in `filter` prop. Nothing changes until you pass one: without it (or with `null`) the listbox filters nothing, and a list you already filter by hand from the `ListboxFilter` value keeps working as in v2. With a filter function, for example `contains` from `useFilter({ sensitivity:'base' })`, items whose text does not match the `ListboxFilter` value are not rendered, a group whose items all fail to match is hidden, and keyboard navigation, typeahead and select-all only see the matching items. In a `ListboxVirtualizer`, the filter runs over `options` (matching `textContent(option)`), so a filtered-out option takes no virtual index. See [Filtering](../components/listbox#filtering). `ComboboxRoot` and `AutocompleteRoot` keep their own filtering and `ignoreFilter` for now.
Copy file name to clipboardExpand all lines: docs/content/meta/ComboboxVirtualizer.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@
22
22
},
23
23
{
24
24
'name': 'textContent',
25
-
'description': '<p>Text content for each item to achieve type-ahead feature</p>\n',
25
+
'description': '<p>Text content for each item, used by typeahead and by a <code>ListboxRoot</code> <code>filter</code> (which otherwise matches the option\'s string form)</p>\n',
26
26
'type': '((option: T) => string)',
27
27
'required': false
28
28
}
@@ -56,7 +56,7 @@
56
56
|`estimateSize`| Estimated size (in px) of each item |`number \| ((index: number) => number)`| No | - |
57
57
|`options`| List of items |`T`| Yes | - |
58
58
|`overscan`| Number of items rendered outside the visible area |`number`| No | - |
59
-
|`textContent`| Text content for each item to achieve type-ahead feature|`((option: T) => string)`| No | - |
59
+
|`textContent`| Text content for each item, used by typeahead and by a ListboxRoot filter (which otherwise matches the option's string form)|`((option: T) => string)`| No | - |
Copy file name to clipboardExpand all lines: docs/content/meta/ListboxRoot.md
+7Lines changed: 7 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,6 +39,12 @@
39
39
'type': 'boolean',
40
40
'required': false
41
41
},
42
+
{
43
+
'name': 'filter',
44
+
'description': '<p>Filters the items by the <code>ListboxFilter</code> search term: called as <code>filter(text, search, value)</code> with the item\'s\n<code>textValue</code> (or text content; in a <code>ListboxVirtualizer</code>, <code>textContent(option)</code>), it returns whether the item\nmatches. Items that do not match are not rendered, so keyboard navigation, typeahead and select-all skip them.\nOmitted or <code>null</code>, the listbox does not filter (filter the items yourself, or on a server).</p>\n',
'description': '<p>Resolves what a keydown means for keyboard navigation. Return <code>undefined</code> to fall back to the default mapping\n(arrows, Home, End, PageUp, PageDown — orientation and reading-direction aware), <code>null</code> to opt the key out (for\nEnter this also skips the selection), or <code>\'select\'</code> to select the highlighted item as Enter does. <code>ListboxFilter</code>\nnever passes unmodified printable keys (they stay text input), and Space on a focused item already selects it, so a\n<code>\'select\'</code> intent for Space does not select it twice.</p>\n',
@@ -146,6 +152,7 @@
146
152
|`defaultValue`| The value of the listbox when initially rendered. Use when you do not need to control the state of the Listbox |`AcceptableValue \| AcceptableValue[]`| No | - |
147
153
|`dir`| The reading direction of the listbox when applicable. <br> If omitted, inherits globally from ConfigProvider or assumes LTR (left-to-right) reading mode. |`"ltr" \| "rtl"`| No | - |
148
154
|`disabled`| When true, prevents the user from interacting with listbox |`boolean`| No | - |
155
+
|`filter`| Filters the items by the ListboxFilter search term: called as filter(text, search, value) with the item's textValue (or text content; in a ListboxVirtualizer, textContent(option)), it returns whether the item matches. Items that do not match are not rendered, so keyboard navigation, typeahead and select-all skip them. Omitted or null, the listbox does not filter (filter the items yourself, or on a server). |`ListboxFilterFunction<AcceptableValue> \| null`| No | - |
149
156
|`getNavigationIntent`| Resolves what a keydown means for keyboard navigation. Return undefined to fall back to the default mapping (arrows, Home, End, PageUp, PageDown — orientation and reading-direction aware), null to opt the key out (for Enter this also skips the selection), or 'select' to select the highlighted item as Enter does. ListboxFilter never passes unmodified printable keys (they stay text input), and Space on a focused item already selects it, so a 'select' intent for Space does not select it twice. |`((event: KeyboardEvent) => ListboxNavigationIntent \| null)`| No | - |
150
157
|`highlightOnHover`| When true, hover over item will trigger highlight |`boolean`| No | - |
151
158
|`loop`| When true, keyboard navigation will loop from last item to first, and vice versa. |`boolean`| No | - |
Copy file name to clipboardExpand all lines: docs/content/meta/ListboxVirtualizer.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@
22
22
},
23
23
{
24
24
'name': 'textContent',
25
-
'description': '<p>Text content for each item to achieve type-ahead feature</p>\n',
25
+
'description': '<p>Text content for each item, used by typeahead and by a <code>ListboxRoot</code> <code>filter</code> (which otherwise matches the option\'s string form)</p>\n',
26
26
'type': '((option: T) => string)',
27
27
'required': false
28
28
}
@@ -56,7 +56,7 @@
56
56
|`estimateSize`| Estimated size (in px) of each item |`number \| ((index: number) => number)`| No | - |
57
57
|`options`| List of items |`T`| Yes | - |
58
58
|`overscan`| Number of items rendered outside the visible area |`number`| No | - |
59
-
|`textContent`| Text content for each item to achieve type-ahead feature|`((option: T) => string)`| No | - |
59
+
|`textContent`| Text content for each item, used by typeahead and by a ListboxRoot filter (which otherwise matches the option's string form)|`((option: T) => string)`| No | - |
0 commit comments