Skip to contents

Toolbar

A container for grouping a set of buttons and controls.

Usage guidelines

To ensure that toolbars are accessible and helpful, follow these guidelines:

  • Use inputs sparingly: Left and right arrow keys are used to both move the text insertion cursor in an input, and to navigate among controls in horizontal toolbars. When using an input in a horizontal toolbar, use only one and place it as the last element of the toolbar.

Anatomy

Import the component and assemble its parts:

Anatomy

Examples

Using with Menu

All Sveltery Base popup components that provide a Trigger component can be integrated with a toolbar by passing the trigger to <Toolbar.Button> with the render snippet:

Using popups with toolbar

This applies to <AlertDialog>, <Dialog>, <Menu>, <Popover>, and <Select>.

Using with Tooltip

Unlike other popups, the toolbar item should be passed to the render snippet of <Tooltip.Trigger>:

Using popups with toolbar

Using with NumberField

To use a NumberField in the toolbar, pass <NumberField.Input> to <Toolbar.Input> using the render snippet:

Using NumberField with toolbar

API reference

Root

A container for grouping a set of controls. Renders a <div>.

disabled boolean | null false
Description

Whether the toolbar's buttons ignore user interaction. Links stay active.

Type
boolean | null
Default
false
orientation ToolbarOrientation 'horizontal'
Description

The orientation of the toolbar.

Type
ToolbarOrientation
Default
'horizontal'
loopFocus boolean true
Description

When true, keyboard navigation wraps from the last item to the first.

Type
boolean
Default
true
render Snippet<[props: HTMLAttributes<HTMLDivElement>, state: ToolbarRootState, children: Snippet | undefined]> —
Name
Description

Replace the default <div>. Spread props onto the host element.

Type
Snippet<[props: HTMLAttributes<HTMLDivElement>, state: ToolbarRootState, children: Snippet | undefined]>
disabled boolean
Name
disabled
Description

Whether the toolbar should ignore user interaction.

Type
boolean
orientation ToolbarOrientation
Name
orientation
Description

The toolbar orientation.

Type
ToolbarOrientation
data-orientation
Indicates the orientation of the toolbar.
data-disabled
Present when the toolbar is disabled.

Button

A button in a toolbar. Renders a <button>.

disabled boolean | null false
Description

Whether the button should ignore user interaction.

Type
boolean | null
Default
false
focusableWhenDisabled boolean true
Description

Whether a disabled button stays in the toolbar's arrow order.

Type
boolean
Default
true
nativeButton boolean true
Description

Whether the host is a native <button>. Set false when render supplies a non-button element.

Type
boolean
Default
true
onclick MouseEventHandler<HTMLButtonElement> | null —
Name
Description

Runs for a click the button does not ignore.

Type
MouseEventHandler<HTMLButtonElement> | null
render Snippet<[props: ToolbarButtonHostProps, state: ToolbarButtonState, children: Snippet | undefined]> —
Name
Description

Replace the default <button>. Spread props onto the host element.

Type
Snippet<[props: ToolbarButtonHostProps, state: ToolbarButtonState, children: Snippet | undefined]>
disabled boolean
Name
disabled
Description

Whether the button should ignore user interaction.

Type
boolean
focusable boolean
Name
focusable
Description

Whether the button remains focusable when disabled.

Type
boolean
orientation ToolbarOrientation
Name
orientation
Description

The toolbar orientation.

Type
ToolbarOrientation
data-orientation
Indicates the orientation of the toolbar.
data-disabled
Present when the button is disabled.
data-focusable
Present when the button remains focusable when disabled.

A link in a toolbar. Renders an <a>.

render Snippet<[props: ToolbarLinkHostProps, state: ToolbarLinkState, children: Snippet | undefined]> —
Name
Description

Replace the default <a>. Spread props onto the host element.

Type
Snippet<[props: ToolbarLinkHostProps, state: ToolbarLinkState, children: Snippet | undefined]>
orientation ToolbarOrientation
Name
orientation
Description

The toolbar orientation.

Type
ToolbarOrientation
data-orientation
Indicates the orientation of the toolbar.

Input

A native input in a toolbar's arrow order. Renders an <input>.

disabled boolean | null false
Description

Whether the input should ignore user interaction. A disabled input gets aria-disabled, not the disabled attribute.

Type
boolean | null
Default
false
focusableWhenDisabled boolean true
Description

Whether a disabled input stays in the toolbar's arrow order.

Type
boolean
Default
true
render Snippet<[props: ToolbarInputHostProps, state: ToolbarInputState]> —
Name
Description

Replace the default <input>. Spread props onto the host element.

Type
Snippet<[props: ToolbarInputHostProps, state: ToolbarInputState]>
disabled boolean
Name
disabled
Description

Whether the input should ignore user interaction.

Type
boolean
focusable boolean
Name
focusable
Description

Whether the input remains focusable when disabled.

Type
boolean
orientation ToolbarOrientation
Name
orientation
Description

The toolbar orientation.

Type
ToolbarOrientation
data-orientation
Indicates the orientation of the toolbar.
data-disabled
Present when the input is disabled.
data-focusable
Present when the input remains focusable when disabled.

Group

Groups several toolbar items. Renders a <div>.

disabled boolean | null false
Description

Whether every button in the group ignores user interaction. Links stay active.

Type
boolean | null
Default
false
render Snippet<[props: HTMLAttributes<HTMLDivElement>, state: ToolbarGroupState, children: Snippet | undefined]> —
Name
Description

Replace the default <div>. Spread props onto the host element.

Type
Snippet<[props: HTMLAttributes<HTMLDivElement>, state: ToolbarGroupState, children: Snippet | undefined]>
disabled boolean
Name
disabled
Description

Whether the toolbar should ignore user interaction.

Type
boolean
orientation ToolbarOrientation
Name
orientation
Description

The toolbar orientation.

Type
ToolbarOrientation
data-orientation
Indicates the orientation of the toolbar.
data-disabled
Present when the group is disabled.

Separator

A separator in a toolbar. Renders a <div>.

orientation ToolbarOrientation 'horizontal'
Description

The orientation of the separator. Defaults to the opposite of the toolbar's orientation, so a horizontal toolbar renders vertical separators.

Type
ToolbarOrientation
Default
'horizontal'
render Snippet<[props: HTMLAttributes<HTMLDivElement>, state: SeparatorState, children: Snippet | undefined]> —
Name
Description

Replace the default <div>. Spread props onto the host element.

Type
Snippet<[props: HTMLAttributes<HTMLDivElement>, state: SeparatorState, children: Snippet | undefined]>
orientation 'horizontal' | 'vertical'
Name
orientation
Description

The orientation of the separator.

Type
'horizontal' | 'vertical'
data-orientation
Indicates the orientation of the separator, which is perpendicular to the toolbar.