Toolbar
A row of grouped controls.
Anatomy
<script>
import { Toolbar } from '@shardsui/svelte/toolbar'
</script>
<Toolbar.Root>
<Toolbar.Button />
<Toolbar.Link />
<Toolbar.Separator />
<Toolbar.Group>
<Toolbar.Button />
<Toolbar.Button />
</Toolbar.Group>
<Toolbar.Input />
</Toolbar.Root>Usage guidelines
- Name the toolbar and its groups:
Toolbar.Rootrendersrole="toolbar"andToolbar.Grouprendersrole="group", so give each anaria-labeloraria-labelledby. Icon-only buttons need anaria-labelof their own. - Use inputs sparingly: in a horizontal toolbar, left and right arrows both move the text cursor inside an input and step between the surrounding controls. To avoid that conflict, include at most one input and place it last.
Examples
Using with Select
Mount <Select.Root> inside the toolbar and let its own trigger be the control. <Select.Trigger> detects the surrounding toolbar and registers itself as a toolbar item, so it joins the arrow-key navigation and shares the toolbar's single tab stop. Toggle Group integrates the same way, and its toggles become the toolbar's items.
<Toolbar.Root>
<Toolbar.Button>Bold</Toolbar.Button>
<Toolbar.Separator />
<Select.Root>
<Select.Trigger>
<Select.Value />
</Select.Trigger>
<!-- Compose the rest of the select -->
</Select.Root>
</Toolbar.Root>Using an input
Toolbar.Input joins the toolbar's single tab stop. Arrow-key focus selects the whole value, and an arrow key steps on to the next control only once the cursor sits collapsed at the matching edge of the text. Keep inputs to a minimum and place them last:
<Toolbar.Root>
<Toolbar.Button>Bold</Toolbar.Button>
<Toolbar.Input placeholder="Search" />
</Toolbar.Root>Disabled items
Toolbar.Root and Toolbar.Group cascade disabled to the buttons and inputs inside them; links are never disabled. A disabled item keeps its place in the arrow-key sequence and carries aria-disabled instead of the native disabled attribute, so screen reader users still meet it:
<Toolbar.Root disabled>
<Toolbar.Button>Bold</Toolbar.Button>
<Toolbar.Button>Italic</Toolbar.Button>
</Toolbar.Root>API reference
Root
A container for grouping a set of controls, such as buttons, toggle groups, or menus.
Renders a <div> element with role="toolbar".
Keyboard:
The toolbar is one tab stop: Tab enters it at the item focused last — the first item to begin with — and leaves it altogether. Home and End are left to the focused control.
Button
A button that can be used as-is or as a trigger for other components.
Renders a <button> element.
Link
A link that joins the toolbar's arrow-key navigation.
Renders an <a> element. Toolbar and group disabled never reach it.
Input
A native input that takes part in the toolbar's keyboard navigation.
Renders an <input> element.
Group
Groups several toolbar items or toggles.
Renders a <div> element with role="group".
Separator
A Separator oriented perpendicular to the toolbar.
Renders a <div> element with role="separator".