Skip to content
View as Markdown

FilterRail ​

FilterRail shows every filterable axis beside the results instead of hiding it behind a filter dropdown. Each section shows its options up front, so users see what they can filter by without opening anything.

It writes the same CollectionControl a DataTable reads, so there is no second filter engine: a checkbox section is the in operator, a radio section is eq, a range is between.

Import ​

tsx
import { FilterRail, type FilterRailSection } from "@tailor-platform/app-shell";

The runnable examples also import Button, DataTable, Text, useCollectionVariables, useDataTable, and useFilterRailLayout from @tailor-platform/app-shell.

Basic Usage ​

Choose categories and a status to filter the local product rows. The checkbox list supports search and Show more; each section can be collapsed without clearing its selection. Clear product filters restores all rows. This example evaluates only its two configured fields locally; a real application sends the derived query to its backend. There is no second DataTable.Filters surface for the same fields.

tsx
function BasicUsage() {
  type Product = { id: string; name: string; category: string; status: string };
  const { variables, control } = useCollectionVariables({});
  const sections: FilterRailSection<keyof Product & string>[] = [
    {
      id: "category",
      label: "Category",
      control: "checkbox",
      field: "category",
      truncate: 2,
      options: ["Packaging", "Storage", "Office"].map((value) => ({ value, label: value })),
    },
    {
      id: "status",
      label: "Status",
      control: "radio",
      field: "status",
      options: ["Draft", "Published"].map((value) => ({ value, label: value })),
    },
  ];
  const products: Product[] = [
    { id: "1", name: "Small carton", category: "Packaging", status: "Published" },
    { id: "2", name: "Storage box", category: "Storage", status: "Draft" },
    { id: "3", name: "Desk organizer", category: "Office", status: "Published" },
  ];
  const rows = products.filter((row) =>
    control.filters.every((filter) => {
      if (filter.field === "category")
        return Array.isArray(filter.value) && filter.value.includes(row.category);
      if (filter.field === "status") return row.status === filter.value;
      return false;
    }),
  );
  const table = useDataTable<Product>({
    columns: [
      { id: "name", label: "Product", type: "text" },
      { id: "status", label: "Status", type: "badge" },
    ],
    data: { rows },
    control,
  });

  return (
    <div className="space-y-3">
      <div className="flex flex-col gap-4 lg:flex-row">
        <FilterRail.Root control={control} sections={sections} className="lg:w-56 lg:shrink-0">
          <FilterRail.Header title="Product filters">
            <FilterRail.ClearAll>Clear product filters</FilterRail.ClearAll>
          </FilterRail.Header>
          <FilterRail.Sections />
        </FilterRail.Root>
        <div className="min-w-0 flex-1">
          <DataTable.Root value={table}>
            <DataTable.Table />
          </DataTable.Root>
        </div>
      </div>
      <Text.p role="status">Matching products: {rows.length}</Text.p>
      <pre className="overflow-x-auto text-sm">
        {JSON.stringify(variables.query ?? {}, null, 2)}
      </pre>
    </div>
  );
}

Sections and parts ​

What the rail shows is config: sections, one entry per axis, in screen order. How the rail is assembled is parts: leave a part out and that feature is not rendered.

PartRenders
FilterRail.RootThe rail. Takes control, sections, layout.
FilterRail.HeaderA title row with a slot for actions.
FilterRail.ClearAllClears the rail's own filters only. Hidden while none are active.
FilterRail.SettingsShow / hide, reorder and sort sections. Needs layout.
FilterRail.SectionsThe sections, in the user's layout. Scrolls while the header stays put.
FilterRail.ProviderHolds the config when a Trigger sits outside the rail (see Narrow screens).
FilterRail.TriggerThe narrow-screen "Filters" button, placed anywhere inside Provider.

The layout example assembles the header, clear action, settings, and sections. Leave out Settings when users do not need to customize the rail.

Section types ​

Every section has an id, a label and an optional hint. The operator is fixed per section — the user picks values, never operators.

controlCommitsNotes
checkboxin (or nin) with the ticked valuessort, truncate (default 8), pinned, searchThreshold
radioeq (or ne) with one valueAn "Any" row removes the filter; anyLabel: null hides it
booleaneq with true / falseThree states: Any, trueLabel, falseLabel
textcontains, hasPrefix or eqDebounced (debounceMs, default 250)
numberRangebetween { min, max }, or gte / lteCommits on blur / Enter; one end alone is half-open
dateeq, gte or lte a YYYY-MM-DDUses DatePicker
dateRangebetween { min, max }Uses DateRangePicker; optional presets
customWhatever render writesDeclares the fields it owns so Clear all includes them

A checkbox list long enough to be truncated also gets a search box, so a value can be found without scrolling (searchThreshold overrides when it appears).

The following playground covers the other six section types: text, boolean, number range, date, date range, and custom. Text commits after its debounce; numeric bounds commit on blur or Enter. Try the April 2026 preset or Low stock: 1–20, and inspect the generated query below. This playground generates filter values only, not backend results.

tsx
function SectionControls() {
  const { variables, control } = useCollectionVariables({});
  const sections: FilterRailSection[] = [
    {
      id: "name",
      label: "Product name",
      control: "text",
      field: "name",
      operator: "contains",
      placeholder: "Search product names...",
    },
    {
      id: "available",
      label: "Availability",
      control: "boolean",
      field: "available",
      trueLabel: "In stock",
      falseLabel: "Out of stock",
    },
    {
      id: "price",
      label: "Price",
      control: "numberRange",
      field: "price",
      min: 0,
      step: 1,
      unit: "USD",
    },
    {
      id: "delivery",
      label: "Deliver on or after",
      control: "date",
      field: "delivery",
      operator: "gte",
    },
    {
      id: "ordered",
      label: "Order period",
      control: "dateRange",
      field: "ordered",
      presets: [{ label: "April 2026", from: "2026-04-01", to: "2026-04-30" }],
    },
    {
      id: "stock",
      label: "Custom stock filter",
      control: "custom",
      fields: ["stock"],
      render: ({ getFilter, setFilter }) => (
        <Button
          type="button"
          size="sm"
          variant="outline"
          aria-pressed={getFilter("stock") !== undefined}
          onClick={() =>
            setFilter(
              "stock",
              getFilter("stock") ? null : { operator: "between", value: { min: 1, max: 20 } },
            )
          }
        >
          Low stock: 1–20
        </Button>
      ),
    },
  ];

  return (
    <div className="space-y-3">
      <Text.p>
        This playground shows generated query values; it does not fetch or filter records.
      </Text.p>
      <FilterRail.Root control={control} sections={sections} className="max-h-[36rem] max-w-sm">
        <FilterRail.Header title="Section controls">
          <FilterRail.ClearAll>Clear control filters</FilterRail.ClearAll>
        </FilterRail.Header>
        <FilterRail.Sections />
      </FilterRail.Root>
      <pre role="status" className="overflow-x-auto text-sm">
        {JSON.stringify(variables.query ?? {}, null, 2)}
      </pre>
    </div>
  );
}

A field holds one filter, so two sections must not share a field; the rail warns in the console when they do.

Typing fields ​

Give FilterRailSection the row's keys so a field that is not on the table is a type error, the same way createColumnHelper<Row>() types columns. This works with a typed control or a plain one:

tsx
const sections: FilterRailSection<keyof Product & string>[] = [
  { id: "category", label: "Category", control: "checkbox", field: "category", options },
  // field: "categroy" → type error
];

With a typed control (from useCollectionVariables({ tableMetadata })), a section whose field the control does not have is also rejected.

The Custom stock filter in the playground uses getFilter and setFilter to toggle a between filter. Its fields: ["stock"] declaration makes that filter participate in Clear all.

The rail never hides state: a selected option is never truncated away, never disabled and never hidden by a section's search box.

Collapsing sections ​

Each section collapses and expands from the chevron by its title. Sections start expanded; set defaultCollapsed: true to start one collapsed (for a rarely used axis). While a section is collapsed, its header still shows how many values are selected and keeps its Clear, so a collapsed section never hides an applied filter. The open / closed state is kept while the page is open, including across the narrow-screen sheet opening and closing.

tsx
{ id: "warehouse", label: "Warehouse", control: "checkbox", field: "warehouse", options, defaultCollapsed: true }

Choosing a control ​

Checkbox and radio sections list every option, so they are only for small, fixed sets whose values you know up front — status, category, size, a handful of warehouses. Their options are a static array; the rail does not fetch them.

Do not use a checkbox or radio list for a field whose values keep growing — product names, SKUs, customers, suppliers, order numbers. The list gets longer with every new record, takes over the rail, and becomes a scroll hunt. Give those fields a search instead:

The field's values are…Use
A small fixed set (≈ up to 20), pick anycheckbox
A small fixed set, pick oneradio (or boolean for yes / no)
Open-ended and growing (names, codes, customers)text — a search that commits contains, hasPrefix or eq
Open-ended, but users must pick exact recordsa custom section rendering a searchable picker (e.g. an async Combobox)
Numbers or datesnumberRange, date, dateRange

In development the rail warns in the console when a checkbox or radio section lists more than 50 options, as a nudge towards a search.

User layout ​

useFilterRailLayout(storageKey) persists the user's section order, hidden sections and option sort to localStorage. Pass it as layout and add FilterRail.Settings. Hiding a section that carries a filter also clears that filter. To share a layout across a team, pass your own { value, onChange, onReset } binding instead.

Open settings to hide sections, sort checkbox options, or reorder sections by dragging or using the reorder handle's arrow keys. Availability starts collapsed. This example saves only its own preferences under the namespaced key docs:filter-rail:layout-example; settings' Reset restores the authored defaults. The separate Open demo filters trigger appears below the lg breakpoint, without adding application breakpoint code.

tsx
function LayoutAndResponsive() {
  const { variables, control } = useCollectionVariables({});
  const layout = useFilterRailLayout("docs:filter-rail:layout-example");
  const sections: FilterRailSection[] = [
    {
      id: "category",
      label: "Category",
      control: "checkbox",
      field: "category",
      options: ["Storage", "Office", "Packaging"].map((value) => ({ value, label: value })),
    },
    {
      id: "status",
      label: "Status",
      control: "radio",
      field: "status",
      options: ["Draft", "Published"].map((value) => ({ value, label: value })),
    },
    {
      id: "available",
      label: "Availability",
      control: "boolean",
      field: "available",
      defaultCollapsed: true,
    },
  ];

  return (
    <FilterRail.Provider control={control} sections={sections} layout={layout}>
      <div className="space-y-3">
        <Text.p>
          Use settings to hide, reorder, or sort sections. Narrow the browser below 1024px to open
          the same rail in a sheet.
        </Text.p>
        <FilterRail.Trigger>Open demo filters</FilterRail.Trigger>
        <FilterRail.Root className="max-w-sm">
          <FilterRail.Header title="Configurable filters">
            <FilterRail.ClearAll>Clear layout filters</FilterRail.ClearAll>
            <FilterRail.Settings />
          </FilterRail.Header>
          <FilterRail.Sections />
        </FilterRail.Root>
        <pre role="status" className="overflow-x-auto text-sm">
          {JSON.stringify({ layout: layout.value, query: variables.query ?? {} }, null, 2)}
        </pre>
      </div>
    </FilterRail.Provider>
  );
}

Beside a DataTable ​

The rail sits in its own Layout.Column, outside DataTable.Root, which is why control is a prop. Do not also render DataTable.Filters for the same fields — one fact in two places can drift.

Narrow screens ​

Below the lg breakpoint there is no room for a side column, so the rail turns itself into a left sheet behind a Filters button carrying the active count — the same way the Sidebar handles small screens. Apps write no breakpoint code.

By default the button appears where the rail would have been. To put it somewhere else — a table toolbar, a page header — wrap the page in FilterRail.Provider, move the config there, and place FilterRail.Trigger wherever you want it. The Trigger renders nothing on wide screens, and while one is mounted the rail skips its own button.

Narrow the browser below 1024px in the layout example. Open demo filters opens the same sections in a left sheet and shows the active count. Press Escape or click the backdrop to close it, then reopen the sheet to verify that filters and collapsed sections remain intact. The example uses FilterRail.Provider to share configuration with the trigger outside Root, without requiring any Shell layout component.