Recipes
Filter bar
Search and filters above a list, with removable chips for what is active, a result count people can hear, and a useful empty state.
Example
Filter tickets
SearchInput, Select, Tag, Table and EmptyState.
Status
Priority
16 of 16 tickets
| Ticket | Title | Status | Priority |
|---|---|---|---|
| T-120 | Export fails for large CSV files | Open | High |
| T-121 | Invoice PDF shows wrong currency | Closed | Medium |
| T-122 | SSO login loops on Safari | In progress | Low |
| T-123 | Add VAT number to invoices | Open | High |
| T-124 | Dashboard loads slowly | Closed | Medium |
| T-125 | Password reset email delayed | In progress | Low |
| T-126 | Dark mode contrast on charts | Open | High |
| T-127 | Bulk archive times out | Closed | Medium |
| T-128 | Timezone wrong in reports | In progress | Low |
| T-129 | Typo in onboarding email | Open | High |
| T-130 | Webhook retries duplicate events | Closed | Medium |
| T-131 | Search ignores accents | In progress | Low |
| T-132 | Mobile menu does not close | Open | High |
| T-133 | Add Polish translation | Closed | Medium |
| T-134 | Rate limit message unclear | In progress | Low |
| T-135 | Attachment preview missing | Open | High |
import { Button, EmptyState, HStack, SearchInput, Select, Stack, Table, Tag, Text, type TableColumn } from '@reactloom/ui';
import { useMemo, useRef, useState } from 'react';
import { tickets, type Ticket } from './data';
const columns: Array<TableColumn<Ticket>> = [
{ key: 'id', header: 'Ticket', width: '6rem' },
{ key: 'title', header: 'Title' },
{ key: 'status', header: 'Status' },
{ key: 'priority', header: 'Priority' },
];
const statusOptions = ['Open', 'In progress', 'Closed'].map((v) => ({ value: v, label: v }));
const priorityOptions = ['High', 'Medium', 'Low'].map((v) => ({ value: v, label: v }));
export default function Example() {
const [query, setQuery] = useState('');
const [status, setStatus] = useState<string | null>(null);
const [priority, setPriority] = useState<string | null>(null);
const searchRef = useRef<HTMLInputElement>(null);
const chipsRef = useRef<HTMLDivElement>(null);
const results = useMemo(
() =>
tickets.filter(
(t) =>
(!query || `${t.id} ${t.title}`.toLowerCase().includes(query.toLowerCase())) &&
(!status || t.status === status) &&
(!priority || t.priority === priority),
),
[query, status, priority],
);
const active = [
query && { key: 'query', label: `“${query}”`, clear: () => setQuery('') },
status && { key: 'status', label: `Status: ${status}`, clear: () => setStatus(null) },
priority && { key: 'priority', label: `Priority: ${priority}`, clear: () => setPriority(null) },
].filter(Boolean) as Array<{ key: string; label: string; clear: () => void }>;
// A removed chip takes its button with it: keep keyboard users in place.
const keepFocus = () =>
requestAnimationFrame(() => (chipsRef.current?.querySelector<HTMLElement>('button') ?? searchRef.current)?.focus());
const clearAll = () => {
setQuery('');
setStatus(null);
setPriority(null);
requestAnimationFrame(() => searchRef.current?.focus());
};
return (
<Stack gap="3" style={{ width: '100%' }}>
<HStack gap="3" align="end" wrap role="search" aria-label="Filter tickets">
<div style={{ flex: '1 1 14rem' }}>
<SearchInput ref={searchRef} label="Search" placeholder="Title or ticket number" value={query} onValueChange={setQuery} />
</div>
<div style={{ flex: '0 1 11rem' }}>
<Select label="Status" placeholder="Any status" options={statusOptions} value={status} onValueChange={setStatus} />
</div>
<div style={{ flex: '0 1 11rem' }}>
<Select label="Priority" placeholder="Any priority" options={priorityOptions} value={priority} onValueChange={setPriority} />
</div>
</HStack>
<HStack gap="2" align="center" wrap>
{/* Announced politely as filters change; also visible. */}
<Text size="sm" tone="muted" role="status">
{results.length} of {tickets.length} tickets
</Text>
{active.length > 0 && (
<div ref={chipsRef} style={{ display: 'contents' }}>
{active.map((f) => (
<Tag
key={f.key}
size="sm"
onRemove={() => {
f.clear();
keepFocus();
}}
removeLabel={`Remove filter ${f.label}`}
>
{f.label}
</Tag>
))}
<Button size="sm" variant="link" onClick={clearAll}>
Clear all
</Button>
</div>
)}
</HStack>
<Table
caption="Tickets"
hideCaption
density="compact"
columns={columns}
rows={results}
getRowId={(t) => t.id}
emptyState={
<EmptyState
size="sm"
headingLevel={4}
title="No tickets match these filters"
description="Remove a filter or try a different search."
actions={
<Button size="sm" variant="secondary" onClick={clearAll}>
Clear filters
</Button>
}
/>
}
/>
</Stack>
);
}Details that matter
- The controls sit in a
role="search"region, so screen-reader users can jump to them. - The result count is a polite live region (
role="status"): it is announced after each change without interrupting typing. - Each active filter is a chip with a named remove button (“Remove filter Status: Open”). Removing one moves focus to the next chip or back to search, so keyboard users never land at the top of the page.
- When nothing matches, the empty state says why and offers “Clear filters” — not a blank table.
- Filter on every keystroke for local data; for server data, debounce the search (300 ms) and show the table’s loading state.
Shareable filters
// Keep filters in the URL so results can be shared and survive reload.
const params = new URLSearchParams(location.search);
const [status, setStatus] = useState(params.get('status'));
useEffect(() => {
const next = new URLSearchParams(location.search);
status ? next.set('status', status) : next.delete('status');
history.replaceState(null, '', `?${next}`);
}, [status]);