Filter Bar
A table toolbar with live search, a few always-visible filters, a “+ Filter” popover that applies on “Apply filters”, and the active filters as removable chips with Clear all.
- Ana ReyesFinance · Full-time
- Ben CruzHR · Full-time
- Cara LimHR · Contract
- Dan SantosFinance · Contract
Installation
pnpm dlx shadcn@latest add @syncblocks/filter-barUsage
import {
FilterBar,
FilterBarSearch,
FilterBarSelect,
FilterPanel,
} from "@/components/ui/filter-bar"<FilterBar
chips={chips}
onRemoveChip={removeChip}
canClear={isFiltered}
onClearAll={clearAll}
>
<FilterBarSearch
label="Search employee name"
value={search}
onValueChange={setSearch}
/>
<FilterBarSelect
label="Status"
value={status}
onValueChange={setStatus}
allLabel="All statuses"
options={STATUS_OPTIONS}
/>
<FilterPanel
title="Filter employees"
applied={applied}
empty={noFilters}
count={chips.length}
onApply={setApplied}
>
{(draft, setDraft) => (
<DepartmentField
value={draft.department}
onChange={(department) => setDraft({ ...draft, department })}
/>
)}
</FilterPanel>
</FilterBar>How filters apply
- Search and
FilterBarSelectapply as soon as the value changes. Keep up to three frequently used filters visible this way. FilterPanelholds every other criterion. Its fields edit a draft that re-seeds fromappliedeach time the panel opens; nothing reaches the table until Apply filters. Cancel, Escape, or clicking away keeps the applied criteria. The panel's Clear all only resets the draft.- Chips show the applied panel criteria outside the popover, so a user can see and remove them without reopening it. Filters already visible in the toolbar don't need a chip.
- The toolbar's Clear all appears while
canClearis true and should remove every applied filter and the search.
The component owns no filtering logic: keep search, visible filters, and applied panel criteria in your own state, derive the chips from them, and filter your rows however your data requires. When the result is empty, show an empty state with a way to clear the filters.
API Reference
FilterBar
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNode | - | Search, visible filters, and the FilterPanel, in order. |
chips | FilterChip[] | [] | Applied criteria shown as removable chips. |
onRemoveChip | (key: string) => void | - | Removes one applied criterion. Chips have no remove button without it. |
onClearAll | () => void | - | Removes every applied filter and the search. |
canClear | boolean | false | Shows the toolbar's Clear all action. |
actions | React.ReactNode | - | Controls unrelated to filtering, such as export or column settings, at the far end. |
className | string | - | Classes for the outer wrapper. |
FilterChip is { key: string; label: string; value: string }.
FilterBarSearch
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | - | The current query. |
onValueChange | (value: string) => void | - | Called on every keystroke and on Clear search. |
label | string | - | Accessible name naming what is searched. |
placeholder | string | label | Placeholder text. |
className | string | - | Classes for the input group. |
FilterBarSelect
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | - | Accessible name, e.g. “Status”. |
value | string | - | The selected option value. |
onValueChange | (value: string) => void | - | Called as soon as an option is picked. |
options | FilterBarOption[] | - | { value, label } pairs. |
allValue | string | "all" | The value that means “no filter”. |
allLabel | string | - | Label for allValue, e.g. “All statuses”. |
id | string | - | Lets a visible label point at the trigger. |
className | string | - | Classes for the trigger. |
FilterBarCombobox
A searchable version of FilterBarSelect for long entity lists such as
departments, positions, or ranks. It takes the same props and also applies as
soon as an option is picked. The field itself is the search box: type to narrow
the list, or open it whole from the chevron. Leaving the field without picking
restores the selected label, and emptying it does not clear the filter.
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | - | Accessible name, e.g. “Department”. |
value | string | - | The selected option value. |
onValueChange | (value: string) => void | - | Called as soon as an option is picked. |
options | FilterBarOption[] | - | { value, label } pairs. |
allValue | string | "all" | The value that means “no filter”. |
allLabel | string | - | Label for allValue, e.g. “All departments”. |
id | string | - | Lets a visible label point at the input. |
className | string | - | Classes for the input group. |
FilterPanel
| Prop | Type | Default | Description |
|---|---|---|---|
applied | T | - | The criteria affecting the table; the draft re-seeds from it. |
onApply | (next: T) => void | - | Called with the draft on Apply filters. |
empty | () => T | - | The criteria with nothing selected; used by the panel's Clear all. |
count | number | - | Number of applied criteria, shown on the trigger. |
title | string | "Filter" | Names the panel, e.g. “Filter employees”. |
canApply | (draft: T) => boolean | - | Disables Apply filters while it returns false. |
children | (draft: T, setDraft: (next: T) => void) => ReactNode | - | The panel's fields, bound to the draft. |
className | string | - | Classes for the popover content. |