Example

Filter tickets

SearchInput, Select, Tag, Table and EmptyState.

Preview

16 of 16 tickets

Tickets
TicketTitleStatusPriority
T-120Export fails for large CSV filesOpenHigh
T-121Invoice PDF shows wrong currencyClosedMedium
T-122SSO login loops on SafariIn progressLow
T-123Add VAT number to invoicesOpenHigh
T-124Dashboard loads slowlyClosedMedium
T-125Password reset email delayedIn progressLow
T-126Dark mode contrast on chartsOpenHigh
T-127Bulk archive times outClosedMedium
T-128Timezone wrong in reportsIn progressLow
T-129Typo in onboarding emailOpenHigh
T-130Webhook retries duplicate eventsClosedMedium
T-131Search ignores accentsIn progressLow
T-132Mobile menu does not closeOpenHigh
T-133Add Polish translationClosedMedium
T-134Rate limit message unclearIn progressLow
T-135Attachment preview missingOpenHigh
Example.tsx
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

useFilterParams.ts
// 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]);