Filter Builder
NewBuild conditions like Status is Active AND Revenue > 1000, with nested groups and operators per field type.
Status is Active AND Revenue > 1000
2 of 6 companies match
- Northwind
- Umbrella
Installation
$ pnpm dlx shadcn@latest add @synccn/filter-builderFirst time in this project? Connect synccn with one command.
Usage
import { FilterBuilder, matchesFilter, filterToString } from "@/components/ui/filter-builder";<FilterBuilder fields={fields} value={filter} onValueChange={setFilter} />rows.filter((r) => matchesFilter(r, filter, fields))API reference
Generated from the component's TypeScript types, so it always matches the code.
FilterBuilder
Visual query builder: conditions joined by AND or OR, nested groups, operators that fit each field type. Pair `matchesFilter` with the value to filter rows, and `filterToString` to show or log it.
- fieldsrequired
FilterField[]Fields people can filter on.
- value
FilterGroupControlled filter.
- defaultValue
FilterGroupInitial filter when uncontrolled.
- onValueChange
(value: FilterGroup) => voidCalled with the new filter on every change.
- maxDepth
numberDefault
2How deep groups can nest. 1 means no nested groups.
- className
stringExtra classes for the root element.
matchesFilter
True when `row` passes `group`. Empty groups match everything.
Takes no props.
filterToString
Readable form, e.g. `Status is Active AND (Revenue > 1000 OR Plan is Pro)`.
- idrequired
string—
- combinatorrequired
"and" | "or"—
- rulesrequired
(FilterRule | FilterGroup)[]—
Dependencies
Read from the component's imports when the site builds. The CLI installs all of these for you.
npm packages
- clsx for cn()
- tailwind-merge for cn()
- lucide-react for FolderPlus, Plus, Trash2
Used by
Keyboard
- TabMove between field, operator and value controls
- EnterorSpaceAdd, remove or switch AND/OR
Accessibility
- Each rule and group is a labelled group, so screen readers announce where you are.
- The AND/OR toggle names what it will switch to.
From the source
Read from this component's code when the site builds, so it can't drift.
- ARIA roles: group
- ARIA attributes: aria-label
- Shows a visible focus ring for keyboard users