Editable filter rules that wrap to fit narrow cards, side panels, and mobile screens.
FilterBuilder combines field, operator, and value controls with add and remove actions. Keep the rules in state and pass onChange so every control updates the current filters.
Change a value, add another rule, or remove a filter. The controls wrap to fit their container.
"use client";
import { FilterBuilder, type FilterRule } from "@froggdesign/enter-ui-react";
import { useState } from "react";
export function FilterBuilderExample() {
const [rules, setRules] = useState<FilterRule[]>([
{ id: "status", field: "status", operator: "is", value: "active" },
]);
return (
<FilterBuilder
fields={[
{
id: "status",
label: "Status",
operators: ["is", "is not"],
options: [
{ label: "Active", value: "active" },
{ label: "Archived", value: "archived" },
],
},
{ id: "owner", label: "Owner", operators: ["is", "is not"] },
]}
rules={rules}
onChange={setRules}
/>
);
}import { FilterBuilder, type FilterRule } from "@froggdesign/enter-ui-react";A rule stays on one row when enough space is available. Field, operator, value, and remove controls wrap in their reading order when the container becomes narrow. This works inside a desktop side panel as well as on a phone, without a consumer media query or styling override. Controls can shrink within their available width; value fields keep the remaining row space beside the remove action.
Field and operator controls use EnterUI Select with labelled triggers and keyboard navigation. Value is a labelled text input; optional presets use a native datalist while allowing free text. The remove button is named "Remove filter". Tab order follows the visual control order after wrapping, and focus remains visible.
| Prop | Type | Behavior |
|---|---|---|
fields | FilterBuilderField[] | Available fields with id, label, optional operators, and optional { label, value }[] presets. |
rules | FilterRule[] | Controlled entries containing id, field, operator, and value. |
onChange | (rules: FilterRule[]) => void | Receives the updated list after adding, removing, or editing a rule. |
addLabel | string | Add action label; defaults to "Add filter". |
The component also accepts native div attributes. Use stable, unique rule IDs when persisting filters.
FilterBuilder owns its responsive layout, token colors, control spacing, and focus treatment. Compose it through the documented props; no custom CSS or style/className overrides are needed.