Toolbar
Installation
npx @mielui/svelte add toolbaryarn dlx @mielui/svelte add toolbarbunx @mielui/svelte add toolbarUsage
Root holds one keyboard collection of Buttons, Links, Separators, and Groups of Items. Tab enters the toolbar once and arrow keys move along it, skipping disabled controls and wrapping at the ends unless loop is false. Give Root an aria-label or aria-labelledby, and label every icon-only control.
<script lang="ts">
import * as Toolbar from '@mielui/svelte/components/toolbar';
let formats = $state<string[]>([]);
function clear() {
formats = [];
}
</script>
<Toolbar.Root aria-label="Text formatting">
<Toolbar.Group type="multiple" bind:value={formats} aria-label="Text styles">
<Toolbar.Item value="bold">Bold</Toolbar.Item>
<Toolbar.Item value="italic">Italic</Toolbar.Item>
</Toolbar.Group>
<Toolbar.Separator />
<Toolbar.Button onclick={clear}>Clear</Toolbar.Button>
<Toolbar.Link href="/docs">Help</Toolbar.Link>
</Toolbar.Root>Use Items inside a Group for choices that stay selected: type="single" with a string value, or type="multiple" with an array. Use Button for one-off actions such as Clear. Separator runs perpendicular to the toolbar; set decorative when it is only visual. Every part takes class and bind:element. Use Items for selections instead of nesting a ToggleGroup, which would add a second keyboard collection.
The package also exports a plain Toolbar: a styled element with the toolbar role and arrow-key navigation between whatever buttons you put in it.
Examples
Design tools
Icon tools with shortcut tooltips sit beside zoom buttons, and a status line names the selected tool.
Move selected ยท 100% zoom
Depth
The default toolbar is a flat grey track with one hover wash that travels between keys. variant="depth" floats it on a raised shell with raised keys and recessed selections. Depth follows the shadow and motion settings of the theme.
Move selected ยท 100% zoom
Multiple selection
A note for the team.
API reference
Toolbar.Root
childrenSnippet<[]>Content rendered inside.
idstringId of the element.
stylestring | StyleProperties | nullInline styles for the element.
loopbooleanWhether or not to loop through the toolbar items when navigating with the keyboard.
orientationOrientationThe orientation of the toolbar. This determines how keyboard navigation will work within the toolbar.
Default
'horizontal'variant"default" | "depth"depthgives the toolbar raised keys and a floating shell.Default
'default'elementBindableHTMLDivElement | nullBindable reference to the DOM element.
Default
null
Toolbar.Button
childrenSnippet<[]>Content rendered inside.
idstringId of the element.
stylestring | StyleProperties | nullInline styles for the element.
disabledboolean | nullWhether the button is disabled or not.
elementBindableHTMLButtonElement | nullBindable reference to the DOM element.
Default
null
Toolbar.Group
childrenSnippet<[]>Content rendered inside.
idstringId of the element.
stylestring | StyleProperties | nullInline styles for the element.
disabledbooleanWhether the toggle group is disabled or not.
typeRequired"single" | "multiple"singlekeeps one value.multipleallows several and makesvaluean array.valueBindablestring | string[]Selected tool, or an array in multiple mode. Bindable.
onValueChange((value: string) => void) | ((value: string[]) => void)Called with the new value when it changes.
elementBindableHTMLDivElement | nullBindable reference to the DOM element.
Default
null
Toolbar.Item
childrenSnippet<[ToggleGroupItemSnippetProps]>Content rendered inside.
idstringId of the element.
stylestring | StyleProperties | nullInline styles for the element.
disabledboolean | nullWhether the toggle item is disabled or not.
valueRequiredstringThe value of the toggle item.
elementBindableHTMLButtonElement | nullBindable reference to the DOM element.
Default
null
Toolbar.Link
childrenSnippet<[]>Content rendered inside.
idstringId of the element.
stylestring | StyleProperties | nullInline styles for the element.
elementBindableHTMLAnchorElement | nullBindable reference to the DOM element.
Default
null
Toolbar.Separator
idstringId of the element.
stylestring | StyleProperties | nullInline styles for the element.
orientationOrientationThe orientation of the separator.
decorativebooleanWhether the separator is decorative and should be hidden from assistive technologies.
elementBindableHTMLDivElement | nullBindable reference to the DOM element.
Default
null
Toolbar
Groups related controls.
class(string & (ClassValue | null))Classes added to the element.
childrenSnippet<[]>Content rendered inside.
pnpm dlx @mielui/svelte add toolbar