Toolbar
A container for grouping a set of buttons and controls.
import type { JSX } from '@solidjs/web';
import { Toolbar } from 'base-ui-solid/toolbar';
import { ToggleGroup } from 'base-ui-solid/toggle-group';
import { Toggle } from 'base-ui-solid/toggle';
import { Select } from 'base-ui-solid/select';
import styles from './index.module.css';
export default function ExampleToolbar() {
return (
<Toolbar.Root class={styles.Toolbar}>
<ToggleGroup class={styles.Group} aria-label="Alignment">
<Toolbar.Button
render={(props) => <Toggle {...props} />}
aria-label="Align left"
value="align-left"
class={styles.Button}
>
Align Left
</Toolbar.Button>
<Toolbar.Button
render={(props) => <Toggle {...props} />}
aria-label="Align right"
value="align-right"
class={styles.Button}
>
Align Right
</Toolbar.Button>
</ToggleGroup>
<Toolbar.Separator class={styles.Separator} />
<Toolbar.Group class={styles.Group} aria-label="Numerical format">
<Toolbar.Button class={styles.Button} aria-label="Format as currency">
$
</Toolbar.Button>
<Toolbar.Button class={styles.Button} aria-label="Format as percent">
%
</Toolbar.Button>
</Toolbar.Group>
<Toolbar.Separator class={styles.Separator} />
<Select.Root defaultValue="Helvetica">
<Toolbar.Button render={(props) => <Select.Trigger {...props} />} class={styles.Button}>
<Select.Value />
<Select.Icon>
<CaretUpDownIcon />
</Select.Icon>
</Toolbar.Button>
<Select.Portal>
<Select.Positioner class={styles.Positioner} sideOffset={4} alignItemWithTrigger={false}>
<Select.Popup class={styles.Popup}>
<Select.Item class={styles.Item} value="Helvetica">
<Select.ItemIndicator class={styles.ItemIndicator}>
<CheckIcon />
</Select.ItemIndicator>
<Select.ItemText class={styles.ItemText}>Helvetica</Select.ItemText>
</Select.Item>
<Select.Item class={styles.Item} value="Arial">
<Select.ItemIndicator class={styles.ItemIndicator}>
<CheckIcon />
</Select.ItemIndicator>
<Select.ItemText class={styles.ItemText}>Arial</Select.ItemText>
</Select.Item>
</Select.Popup>
</Select.Positioner>
</Select.Portal>
</Select.Root>
<Toolbar.Separator class={styles.Separator} />
<Toolbar.Link class={styles.Link} href="#">
Edited 51m ago
</Toolbar.Link>
</Toolbar.Root>
);
}
function CaretUpDownIcon(props: JSX.IntrinsicElements['svg']) {
return (
<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="currentColor"
{...props}
style={
typeof props.style === 'string'
? `display: block; ${props.style}`
: { display: 'block', ...(typeof props.style === 'object' ? props.style : {}) }
}
>
<path d="M11 10H5l3 3.5zm0-4H5l3-3.5z" />
</svg>
);
}
function CheckIcon(props: JSX.IntrinsicElements['svg']) {
return (
<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
{...props}
style={
typeof props.style === 'string'
? `display: block; ${props.style}`
: { display: 'block', ...(typeof props.style === 'object' ? props.style : {}) }
}
>
<path d="m2.5 8.5 4 4 7-9" />
</svg>
);
}
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:
import { Toolbar } from 'base-ui-solid/toolbar';
<Toolbar.Root>
<Toolbar.Button />
<Toolbar.Link />
<Toolbar.Separator />
<Toolbar.Group>
<Toolbar.Button />
<Toolbar.Button />
</Toolbar.Group>
<Toolbar.Input />
</Toolbar.Root>;
Examples
Using with other components
Use the render prop to combine a toolbar part with a part from another component into a single element.
The element joins the toolbar’s keyboard navigation and keeps the behavior of the other part.
<Toolbar.Root>
<Menu.Root>
<Toolbar.Button render={(props) => <Menu.Trigger {...props} />} />
<Menu.Portal>{/* Compose the rest of the menu */}</Menu.Portal>
</Menu.Root>
</Toolbar.Root>
- Popups with a trigger, such as Alert Dialog, Dialog, Drawer, Menu, Popover, and Select: pass the trigger to the
renderprop of<Toolbar.Button>, as shown above. Setdisabledon<Toolbar.Button>rather than on the trigger, so the button stays in the toolbar’s keyboard navigation. - Tooltip: pass
<Toolbar.Button>to therenderprop of<Tooltip.Trigger>instead. - Number Field: pass
<NumberField.Input>to therenderprop of<Toolbar.Input>, and keep it inside<NumberField.Root>and<NumberField.Group>with the increment and decrement buttons.
See how props are merged for how the two parts combine.
API reference
Root
A container for grouping a set of controls, such as buttons, toggle groups, or menus.
Renders a <div> element.
loopFocusbooleantrue
true, using keyboard navigation will wrap focus to the other end of the toolbar once the end is reached.booleandisabledboolean—
booleanorientationToolbar.Root.Orientation'horizontal'
Toolbar.Root.Orientationclassfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Data attributes
data-orientationUnion—
'horizontal' | 'vertical'data-disabled-—
-Attribute | Description | |
|---|---|---|
data-orientation | Indicates the orientation of the toolbar. | |
data-disabled | Present when the toolbar is disabled. | |
Root.State
type ToolbarRootState = {
/** Whether the component is disabled. */
disabled: boolean;
/** The component orientation. */
orientation: Toolbar.Root.Orientation;
};Root.Orientation
type ToolbarRootOrientation = 'horizontal' | 'vertical';Root.ItemMetadata
type ToolbarRootItemMetadata = { disabled: boolean; focusableWhenDisabled: boolean };Button
A button that can be used as-is or as a trigger for other components.
Renders a <button> element.
focusableWhenDisabledbooleantrue
true the item remains focusable when disabled.booleannativeButtonbooleantrue
<button> element when replacing it
via the render prop.
Set to false if the rendered element is not a button (for example, <div>).booleandisabledbooleanfalse
true the item is disabled.booleanclassfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Data attributes
data-orientationUnion—
'horizontal' | 'vertical'data-disabled-—
-data-focusable-—
-Attribute | Description | |
|---|---|---|
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. | |
Button.State
type ToolbarButtonState = {
/** Whether the component is disabled. */
disabled: boolean;
/** Whether the component remains focusable when disabled. */
focusable: boolean;
/** The component orientation. */
orientation: Toolbar.Root.Orientation;
};Link
A link component.
Renders an <a> element.
classfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Data attributes
data-orientationUnion—
'horizontal' | 'vertical'Attribute | Description | |
|---|---|---|
data-orientation | Indicates the orientation of the toolbar. | |
Link.State
type ToolbarLinkState = {
/** The component orientation. */
orientation: Toolbar.Root.Orientation;
};Input
A native input element that integrates with Toolbar keyboard navigation.
Renders an <input> element.
defaultValueUnion—
string | number | string[]focusableWhenDisabledbooleantrue
true the item remains focusable when disabled.booleandisabledbooleanfalse
true the item is disabled.booleanclassfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Data attributes
data-orientationUnion—
'horizontal' | 'vertical'data-disabled-—
-data-focusable-—
-Attribute | Description | |
|---|---|---|
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. | |
Input.State
type ToolbarInputState = {
/** Whether the component is disabled. */
disabled: boolean;
/** Whether the component remains focusable when disabled. */
focusable: boolean;
/** The component orientation. */
orientation: Toolbar.Root.Orientation;
};Group
Groups several toolbar items or toggles.
Renders a <div> element.
disabledbooleanfalse
true all toolbar items in the group are disabled.booleanclassfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Data attributes
data-orientationUnion—
'horizontal' | 'vertical'data-disabled-—
-Attribute | Description | |
|---|---|---|
data-orientation | Indicates the orientation of the toolbar. | |
data-disabled | Present when the group is disabled. | |
Group.State
type ToolbarGroupState = {
/** Whether the component is disabled. */
disabled: boolean;
/** The component orientation. */
orientation: Toolbar.Root.Orientation;
};Separator
A separator element accessible to screen readers.
Renders a <div> element.
orientationOrientation—
Orientationclassfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Data attributes
data-orientationUnion—
'horizontal' | 'vertical'Attribute | Description | |
|---|---|---|
data-orientation | Indicates the orientation of the separator, which is perpendicular to the toolbar. | |
Separator.State
type ToolbarSeparatorState = {
/** The orientation of the separator. */
orientation: Orientation;
};