# Toolbar

A page's action and filter bar: the scope, the search and the actions in one row that answers to its own width.

Live variants: https://design.arcadia.is/components/toolbar

```tsx
import { Toolbar } from "@arcadia/ui";
```

Choose a scope, then narrow it by searching. Reset returns focus to search.

```tsx
import { useState, useRef } from "react";
import {
  Button, SegmentedControl, Toolbar, Input, fmtPlural,
} from "@arcadia/ui";

function Usage() {
  const [scope, setScope] = useState("all");
  const [query, setQuery] = useState("");
  const search = useRef<HTMLInputElement>(null);
  const shown = CARDS.filter((card) =>
    (scope === "all" || card.scope === scope) && card.title.toLowerCase().includes(query.trim().toLowerCase()));
  return (
    <div {...stylex.props(cmp.stream)}>
      <Toolbar aria-label="Cards"
        leading={<SegmentedControl size="sm" aria-label="Scope" value={scope} onValueChange={setScope}
          items={[{ value: "all", label: "All" }, { value: "open", label: "Open" }, { value: "done", label: "Done" }]} />}
        search={<Input ref={search} variant="bar" rootStyle={ToolbarStyles.search} leadingIcon="search" placeholder="Search cards" aria-label="Search cards"
          value={query} onChange={(e) => setQuery(e.currentTarget.value)} />}
        actions={<Button size="sm" disabled={query === "" && scope === "all"} onClick={() => {
          setQuery("");
          setScope("all");
          search.current?.focus();
        }}>Reset filters</Button>}
      />
      <div role="status" {...stylex.props(cmp.groupLabel, cmp.num)}>{fmtPlural(shown.length, "matching card")}</div>
      <Toolbar aria-label="Selected cards" selection="2 cards selected" />
    </div>
  );
}
```

## Accessibility

The bar is a group named by `aria-label`, so its parts are read in the order they stand: the scope, the search, the actions, or the selection then the actions. The field in `search` is named by the product, never by the bar. The bar itself takes no focus; the control a person is in keeps it as the bar wraps.

With `selection` given, the scope and the search leave the page rather than hiding: nothing behind the line can still be reached by a keyboard. When the line appears, move the focus to it or to the control that ends the selection, as the product's own flow needs.

## API reference

### Toolbar

- `leading` (`ReactNode`): At the bar's start: the scope the page is read in, its filters, a segmented control.
- `search` (`ReactNode`): The field that narrows the page: it takes the room between the start and the actions, or the line below the leading controls on a narrow bar.
- `actions` (`ReactNode`): At the bar's end: the page's one action, a menu of more.
- `searchFirst` (`boolean`, default `false`)
- `selection` (`ReactNode`): Given, the bar is in its selection state: this line replaces the leading controls and the search, and the actions act on what is selected.
- `aria-label` (`string`): The group's name, for a reader.
- `rootStyle` (`RootStyle`): Typed StyleX override: where the bar sits.
