Filter bar
A row of filters above a table or a chart: a search field, a chip for each filter that opens a small panel of options or a range, and saved views. It holds plain data, so the parent filters its own rows. For one choice between a few views, a segmented control is enough.
Install
npx shadcn@latest add @thrum-pro/filter-barThis is a Pro component. The command works once your project has a licence key: set up Pro or see pricing.
Automatically installs icons plus and x from the icon set.
Data shape
type FilterValue = readonly string[] | readonly [number, number];
type Filters = Readonly<Record<string, FilterValue>>;const filters: Filters = {
status: ["active", "trial"],
seats: [20, 100],
};Props
| Prop | Type | Default | Description |
|---|---|---|---|
fields | readonly FilterField[] | Required | The filters, in order. An options field has key, label and options; a range field has key, label, min, max, and an optional step and format. |
filters | Filters | – | The set filters, when the parent holds them. Use it with onFiltersChange. |
defaultFilters | Filters | Default {} | The filters at first, when the bar holds them itself. |
onFiltersChange | (filters: Filters) => void | – | Called with every set filter when one changes. Unset fields are left out, and options keep the fields' order. |
search | string | – | The search text, when the parent holds it. Use it with onSearchChange. |
defaultSearch | string | Default "" | The search text at first, when the bar holds it itself. |
onSearchChange | (search: string) => void | – | Called with the text on every change, including when it is cleared. |
searchLabel | string | Default "Search" | The search field's name for screen readers. An empty string draws no search field. |
searchPlaceholder | string | Default "Search" | Shown in the empty search field. |
views | readonly SavedView[] | – | Saved views: value, label, filters and an optional search. Picking one sets them. The view that matches the current state shows as selected; none does after a change by hand. |
onViewChange | (value: string) => void | – | Called with the value of a picked view. |
locale | string | Default "en-US" | The locale that prints range values. |
sound | boolean | Default true | Play a rising click when an option is ticked and a falling one when a filter is removed, if the visitor has sound on. |
className | string | – | Extra classes for the root, merged last. |
isActive(), cleanFilters() | functions | – | More exports: whether a field's value filters anything, and the set filters in a fixed order, for comparing two states. |
Motion and sound
Motion
- A filter's panel fades and grows from 96% over 150 ms, from the chip it belongs to.
- Chips, ticks and the saved-view thumb change over 150 ms.
- Reduced motion: everything changes at once.
Sound
- A rising click when an option is ticked, a falling one when it is cleared, when a chip is removed, and on Clear all.
- A soft tone when a filter's panel opens and closes; a tick as a range thumb crosses a step; a click when a saved view is picked.
Sound is off until the visitor turns it on. Pass sound={false} to keep this component silent. How sound works
Accessibility
- Each chip is a button named by its field and its values, such as Status, Active, Trial, and it says that it opens a dialog. Its remove button is named Remove Status filter.
- When a chip is removed the focus stays on the chip, which is now empty; Clear all moves it to the first chip.
- A polite line, read by screen readers only, repeats the filters after every change.
- Options are checkboxes named by their visible text. A range is two slider thumbs named Lowest and Highest with the field's name.
- A set filter is a solid chip with its values written out; an unset one is dashed with a plus, so the state does not rest on colour.
- The panels are floating surfaces. Under a glass material their tint keeps text at 4.5 to 1, and every control sits 8 pixels inside the edge.
| Keys | Action |
|---|---|
| Tab | Move through the saved views, the search field, the chips with their remove buttons, and Clear all. |
| Enter / Space | On a chip: open its panel. The focus moves into it. |
| Space | In a panel: tick or clear the focused option. |
| ← / → / Home / End | On a range thumb: move it one step, or to an end. On the saved views: pick the next or previous view. |
| Esc | Close the panel. The focus returns to its chip. In the search field, Escape clears the text. |
Source
The source comes with Pro
TypeScript source · Copy-paste ready · MIT-compatible for client projects · Includes all dependencies
Files and dependencies
- Adds
components/ui/filter-bar.tsx- Packages
- None
- Brings along
- ButtonCheckboxPopoverSearch fieldSegmented controlSliderSound engine
- Icons
plusx
Changelog
- 1.0.0 · 2026-12-03First release.