Skip to Content
NarakUI

Filter Builder

Build one filter condition from a field, operator, and typed value in a joined control.

Interactive example

Pick a field, choose an operator, and enter a typed value in a single joined control. Pass showFieldSearch to filter long field lists from the keyboard.

{"fieldId":"answer-engine","operatorId":"is","value":"chatgpt"}

Value types

Each field defines the input shown in the value segment:

  • select — Opens a selection menu of options, with optional search via searchable.
  • number — Renders an inline number input that commits on blur or Enter, and validates min, max, and step (with step alignment starting at min when provided, or 0 otherwise).
  • text — Renders an inline text input. Empty strings clear the value to null unless allowEmpty is enabled.
  • multi — Stores a string[] and displays each value as a removable pill. Pass options for a checkable list (with optional searchable and onSearchChange for server-side filtering), or enable allowCustom without options to add values on Enter or comma.
Select
Number
Text
Multi (options)
Multi (custom)
narakcode.devui.narakcode.dev

Compatible field changes

Switching fields keeps the current operator when the new field supports the same operator ID; otherwise it falls back to the new field's defaultOperatorId, or null if none is defined.

The value resets to null by default so incompatible data does not carry over. Set the same compatibilityKey on value configs that share a domain — such as Assignee and Reviewer — to keep the current value whenever it remains valid for the new field.

Switch between Assignee and Reviewer to keep the selected person. Switch to Region to keep the operator and clear the value.

{"fieldId":"assignee","operatorId":"is","value":"alex"}

Controlled state

FilterBuilder is fully controlled through condition and onConditionChange. Start from an empty condition (fieldId: null, operatorId: null, value: null) to let the user build a rule from scratch, or update it programmatically from presets and reset actions.

const [condition, setCondition] = useState<FilterCondition>({
  fieldId: null,
  operatorId: null,
  value: null,
});

<FilterBuilder
  fields={fields}
  condition={condition}
  onConditionChange={setCondition}
/>
{"fieldId":null,"operatorId":null,"value":null}

Installation

pnpm dlx shadcn@latest add @narakui/filter-builder

Add "@narakui": "https://ui.narakcode.dev/r/{name}.json" to components.json, or install directly from https://ui.narakcode.dev/r/filter-builder.json.

Properties

PropTypeDefaultDescription
fields (Required)readonly FilterBuilderField[]—Field definitions with their operators, default operator, and typed value configuration
condition (Required)FilterCondition—Controlled condition object (fieldId, operatorId, value)
onConditionChange (Required)(condition: FilterCondition) => void—Called whenever the selected field, operator, or value changes
fieldPlaceholderstring'Select field'Placeholder shown in the field segment before a field is chosen
operatorPlaceholderstring'Select operator'Placeholder shown in the operator segment before an operator is chosen
valuePlaceholderstring'Select value'Default placeholder for the value segment when the field config does not provide one
showFieldSearchbooleanfalseShows a search input inside the field selection popover
fieldSearchPlaceholderstring'Search fields'Placeholder text for the field search input
size'micro' | 'small' | 'regular' | 'large''regular'Size scale shared across all three segments
disabledbooleanfalseDisables all segments of the control
withRadixPortalbooleantrueRenders segment popovers inside a portal. Set to false to render them inline
align'start' | 'center' | 'end''start'Alignment of segment popovers relative to their triggers
ariaLabelstring'Filter condition'Accessible label applied to the joined group container
classNamestring—Additional classes for the outer container
segmentClassNames{ field?: string; operator?: string; value?: string }—Class overrides for individual field, operator, and value segments