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-bar

Usage

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 FilterBarSelect apply as soon as the value changes. Keep up to three frequently used filters visible this way.
  • FilterPanel holds every other criterion. Its fields edit a draft that re-seeds from applied each 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 canClear is 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

PropTypeDefaultDescription
childrenReact.ReactNode-Search, visible filters, and the FilterPanel, in order.
chipsFilterChip[][]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.
canClearbooleanfalseShows the toolbar's Clear all action.
actionsReact.ReactNode-Controls unrelated to filtering, such as export or column settings, at the far end.
classNamestring-Classes for the outer wrapper.

FilterChip is { key: string; label: string; value: string }.

FilterBarSearch

PropTypeDefaultDescription
valuestring-The current query.
onValueChange(value: string) => void-Called on every keystroke and on Clear search.
labelstring-Accessible name naming what is searched.
placeholderstringlabelPlaceholder text.
classNamestring-Classes for the input group.

FilterBarSelect

PropTypeDefaultDescription
labelstring-Accessible name, e.g. “Status”.
valuestring-The selected option value.
onValueChange(value: string) => void-Called as soon as an option is picked.
optionsFilterBarOption[]-{ value, label } pairs.
allValuestring"all"The value that means “no filter”.
allLabelstring-Label for allValue, e.g. “All statuses”.
idstring-Lets a visible label point at the trigger.
classNamestring-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.

PropTypeDefaultDescription
labelstring-Accessible name, e.g. “Department”.
valuestring-The selected option value.
onValueChange(value: string) => void-Called as soon as an option is picked.
optionsFilterBarOption[]-{ value, label } pairs.
allValuestring"all"The value that means “no filter”.
allLabelstring-Label for allValue, e.g. “All departments”.
idstring-Lets a visible label point at the input.
classNamestring-Classes for the input group.

FilterPanel

PropTypeDefaultDescription
appliedT-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.
countnumber-Number of applied criteria, shown on the trigger.
titlestring"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.
classNamestring-Classes for the popover content.