# Filter bar

A row of native form controls that narrows a list or table.

**Our choice:** No standard exists: a `<form>` in `<search>` with labelled controls, and the result count as a status message.

_Diagram: The filter bar is a row of form controls above a list or table in the content area, with the result count after it._

## Live example

### Filter orders

```html
<search data-filter-bar aria-label="Filter orders">
  <form method="get" id="order-filters">
    <div data-field>
      <label for="filter-q">Search orders</label>
      <input type="search" id="filter-q" name="q" placeholder="Order number">
    </div>
    <div data-field>
      <label for="filter-status">Status</label>
      <select id="filter-status" name="status">
        <option value="">Any status</option>
        <option>Open</option>
        <option>Shipped</option>
        <option>Delivered</option>
      </select>
    </div>
    <dui-combobox>
      <label for="filter-customer">Customer</label>
      <input type="text" id="filter-customer" name="customer" list="filter-customers">
      <datalist id="filter-customers">
        <option value="Analytical Engines Ltd."></option>
        <option value="Bletchley Instruments"></option>
        <option value="Cobol Systems BV"></option>
        <option value="Orbital Mechanics GmbH"></option>
      </datalist>
    </dui-combobox>
    <div data-field>
      <label for="filter-from">Placed on or after</label>
      <input type="date" id="filter-from" name="from">
    </div>
    <div>
      <button type="submit">Apply</button>
      <button type="reset">Reset</button>
    </div>
  </form>
  <p role="status" id="order-count">6 orders</p>
</search>
<section data-scroll="inline" aria-labelledby="orders-caption" tabindex="0">
  <table id="order-table">
    <caption id="orders-caption">Orders</caption>
    <thead>
      <tr><th scope="col">Order</th><th scope="col">Customer</th><th scope="col">Status</th><th scope="col">Placed</th><th scope="col">Total</th></tr>
    </thead>
    <tbody>
        <tr><td>1042</td><td>Analytical Engines Ltd.</td><td>Shipped</td><td><time datetime="2025-03-12">2025-03-12</time></td><td>€1,240.00</td></tr>
        <tr><td>1041</td><td>Bletchley Instruments</td><td>Delivered</td><td><time datetime="2025-03-10">2025-03-10</time></td><td>€48.50</td></tr>
        <tr><td>1040</td><td>Cobol Systems BV</td><td>Open</td><td><time datetime="2025-03-09">2025-03-09</time></td><td>€3,980.00</td></tr>
        <tr><td>1039</td><td>Orbital Mechanics GmbH</td><td>Open</td><td><time datetime="2025-03-07">2025-03-07</time></td><td>€615.90</td></tr>
        <tr><td>1038</td><td>Analytical Engines Ltd.</td><td>Delivered</td><td><time datetime="2025-03-04">2025-03-04</time></td><td>€310.25</td></tr>
        <tr><td>1037</td><td>Cobol Systems BV</td><td>Shipped</td><td><time datetime="2025-03-01">2025-03-01</time></td><td>€72.00</td></tr>
    </tbody>
  </table>
</section>
```

### Compact filter bar

```html
<div data-density="compact">
  <search data-filter-bar aria-label="Filter invoices">
    <form method="get">
      <div data-field>
        <label for="invoice-q">Search invoices</label>
        <input type="search" id="invoice-q" name="q" placeholder="Invoice number">
      </div>
      <div data-field>
        <label for="invoice-status">Status</label>
        <select id="invoice-status" name="status">
          <option value="">Any status</option>
          <option>Draft</option>
          <option>Sent</option>
          <option>Overdue</option>
          <option>Paid</option>
        </select>
      </div>
      <div>
        <button type="submit">Apply</button>
        <button type="reset">Reset</button>
      </div>
    </form>
    <p role="status">42 invoices</p>
  </search>
</div>
```

## Attributes

| Attribute or value | Where | Effect |
| --- | --- | --- |
| `data-filter-bar` | a `<search>` (`aria-label` when the page has several) |  |

Children: a `<form>` of fields (each a `data-field`, or a `<dui-combobox>`) whose last child holds the buttons, then a `role="status"` element with the result count.

### Breakpoint

30rem of the bar's own inline size. A container query condition cannot read a custom property, so it is written as a length.

### Keyboard

| Key | Action |
| --- | --- |
| <kbd>Tab</kbd> | moves through the filters, then Apply and Reset |
| <kbd>Enter</kbd> | in a text field, applies the filters |

## Accessibility

- The status text says what changed ("24 orders match"), and is announced politely without moving focus (WCAG 4.1.3 Status Messages).
- Controls keep their size (36px, 32px compact, 44px on touch: above the 24px of WCAG 2.5.8).

## Specifications

- [HTML `<search>` element](https://html.spec.whatwg.org/multipage/grouping-content.html#the-search-element)
- [WCAG 4.1.3 Status Messages](https://www.w3.org/WAI/WCAG22/Understanding/status-messages.html)
- [MDN `search`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/search)
- [MDN `status` role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/status_role)
- [WCAG Labels or instructions](https://www.w3.org/WAI/WCAG22/Understanding/labels-or-instructions.html)

## See also

- [Organisms](https://domestic-ui.odonckers.dev/organisms/index.md)
- Source: [`css/components/organisms/filter-bar.css`](https://github.com/odonckers/domestic-ui/blob/main/css/components/organisms/filter-bar.css), [`examples/organisms/filter-bar.html`](https://github.com/odonckers/domestic-ui/blob/main/examples/organisms/filter-bar.html)
- Demos: Orders view ([Plain HTML](https://github.com/odonckers/domestic-ui/blob/main/demos/vanilla/orders.html), [React](https://github.com/odonckers/domestic-ui/blob/main/demos/react/src/OrdersPage.tsx), [Angular](https://github.com/odonckers/domestic-ui/tree/main/demos/angular/src/app/orders), [Astro](https://github.com/odonckers/domestic-ui/blob/main/demos/astro/src/pages/orders.astro), [Vue](https://github.com/odonckers/domestic-ui/blob/main/demos/vue/src/OrdersPage.vue), [Svelte](https://github.com/odonckers/domestic-ui/blob/main/demos/svelte/src/OrdersPage.svelte))

## How other systems do it

For comparison only; these are not the standard this system follows.

- Apple Human Interface Guidelines: No equivalent
- [Material Design 3: Chips (filter chips)](https://m3.material.io/components/chips/overview)
- [Vercel Geist: Filter Params](https://vercel.com/geist/filter-params)
