Toolbar
A container that groups a set of buttons and controls.
<script setup lang="ts">
import { h } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Select } from '@vase-ui/vue/select';
import { Toggle } from '@vase-ui/vue/toggle';
import { ToggleGroup } from '@vase-ui/vue/toggle-group';
import { Toolbar } from '@vase-ui/vue/toolbar';
import styles from './index.module.css';
const ICON_PROPS = {
width: '16',
height: '16',
viewBox: '0 0 16 16',
style: { display: 'block' },
};
const CaretUpDownIcon: FunctionalComponent = (_, { attrs }) =>
h('svg', { ...ICON_PROPS, fill: 'currentColor', ...attrs }, [
h('path', { d: 'M11 10H5l3 3.5zm0-4H5l3-3.5z' }),
]);
const CheckIcon: FunctionalComponent = (_, { attrs }) =>
h('svg', { ...ICON_PROPS, fill: 'none', stroke: 'currentColor', ...attrs }, [
h('path', { d: 'm2.5 8.5 4 4 7-9' }),
]);
const popupHiddenClass = styles.PopupHidden;
</script>
<template>
<Toolbar.Root :class="styles.Toolbar">
<ToggleGroup :class="styles.Group" aria-label="Alignment">
<Toolbar.Button aria-label="Align left" :class="styles.Button">
<template #element="{ props, elementRef }">
<Toggle v-bind="props" :ref="elementRef" value="align-left">Align Left</Toggle>
</template>
</Toolbar.Button>
<Toolbar.Button aria-label="Align right" :class="styles.Button">
<template #element="{ props, elementRef }">
<Toggle v-bind="props" :ref="elementRef" value="align-right">Align Right</Toggle>
</template>
</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 default-value="Helvetica">
<Toolbar.Button :class="styles.Button" aria-label="Font">
<template #element="{ props, elementRef }">
<Select.Trigger v-bind="props" :ref="elementRef">
<Select.Value />
<Select.Icon>
<CaretUpDownIcon />
</Select.Icon>
</Select.Trigger>
</template>
</Toolbar.Button>
<Select.Portal>
<Select.Positioner
:class="styles.Positioner"
:side-offset="4"
:align-item-with-trigger="false"
>
<Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
<Select.Popup :class="styles.Popup">
<Select.Item :class="styles.Item" value="Helvetica" v-slot="{ state }">
<span v-if="state.selected" :class="styles.ItemIndicator">
<CheckIcon />
</span>
<Select.ItemText :class="styles.ItemText">Helvetica</Select.ItemText>
</Select.Item>
<Select.Item :class="styles.Item" value="Arial" v-slot="{ state }">
<span v-if="state.selected" :class="styles.ItemIndicator">
<CheckIcon />
</span>
<Select.ItemText :class="styles.ItemText">Arial</Select.ItemText>
</Select.Item>
</Select.Popup>
</Transition>
</Select.Positioner>
</Select.Portal>
</Select.Root>
<Toolbar.Separator :class="styles.Separator" />
<Toolbar.Link :class="styles.Link" href="#">Edited 51m ago</Toolbar.Link>
</Toolbar.Root>
</template>.Toolbar {
box-sizing: border-box;
display: flex;
align-items: center;
gap: 1px;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
padding: 1px;
width: 37.5rem;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
}
}
.Group {
display: flex;
gap: 1px;
}
.Button {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
min-width: 2rem;
height: 2rem;
padding: 0;
margin: 0;
border: 0;
background-color: transparent;
color: oklch(14.5% 0 0deg);
-webkit-user-select: none;
user-select: none;
font-family: inherit;
font-size: 0.875rem;
font-weight: 400;
line-height: 1;
white-space: nowrap;
@media (prefers-color-scheme: dark) {
color: white;
}
@media (hover: hover) {
&:hover:not(:disabled, [aria-disabled='true'], [data-pressed], [aria-pressed='true']) {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:active:not(:disabled, [aria-disabled='true'], [data-pressed], [aria-pressed='true']) {
background-color: oklch(92.2% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
&[aria-pressed] {
padding: 0 0.75rem;
}
&[aria-pressed='true'] {
background-color: oklch(14.5% 0 0deg);
color: white;
@media (prefers-color-scheme: dark) {
background-color: white;
color: oklch(14.5% 0 0deg);
}
}
@media (hover: hover) {
&[aria-pressed='true']:hover:not(:disabled, [aria-disabled='true']) {
background-color: oklch(14.5% 0 0deg);
color: white;
@media (prefers-color-scheme: dark) {
background-color: white;
color: oklch(14.5% 0 0deg);
}
}
}
&[role='combobox'] {
min-width: 8rem;
justify-content: space-between;
padding: 0 0.5rem;
&[data-pressed] {
background-color: oklch(97% 0 0deg);
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
color: white;
}
}
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: 1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Separator {
width: 1px;
height: 16px;
margin: 0.25rem;
background-color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: white;
}
}
.Link {
color: oklch(55.6% 0 0deg);
font-family: inherit;
font-size: 0.875rem;
line-height: 1.25rem;
text-decoration: none;
align-self: center;
flex: 0 0 auto;
margin-inline: auto 0.875rem;
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
@media (hover: hover) {
&:hover {
color: oklch(48.8% 0.243 264.376deg);
@media (prefers-color-scheme: dark) {
color: oklch(62.3% 0.214 259.815deg);
}
}
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Positioner {
outline: none;
-webkit-user-select: none;
user-select: none;
z-index: 10;
}
.Popup {
box-sizing: border-box;
outline: 0;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
background-clip: padding-box;
color: oklch(14.5% 0 0deg);
min-width: var(--anchor-width);
transform-origin: var(--transform-origin);
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
transition:
transform 100ms ease-out,
opacity 100ms ease-out;
overflow-y: auto;
max-height: var(--available-height);
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
box-shadow: none;
}
&[data-side='none'] {
transition: none;
transform: translateY(1px);
opacity: 1;
min-width: calc(var(--anchor-width) + 1.75rem);
}
}
/* The enter-from and leave-to class of the `<Transition>` around the popup. */
.PopupHidden {
opacity: 0;
transform: scale(0.98);
}
.Item {
box-sizing: border-box;
outline: 0;
font-size: 0.875rem;
line-height: 1.25rem;
padding-block: 0.375rem;
padding-left: 0.625rem;
padding-right: 1rem;
display: grid;
gap: 0.5rem;
align-items: center;
grid-template-columns: 1rem 1fr;
cursor: default;
-webkit-user-select: none;
user-select: none;
@media (pointer: coarse) {
padding-block: 0.625rem;
}
&[data-highlighted] {
background-color: oklch(14.5% 0 0deg);
color: white;
@media (prefers-color-scheme: dark) {
background-color: white;
color: oklch(14.5% 0 0deg);
}
}
}
.ItemIndicator {
grid-column-start: 1;
}
.ItemText {
grid-column-start: 2;
}<script setup lang="ts">
import { h } from 'vue';
import type { FunctionalComponent } from 'vue';
import { Select } from '@vase-ui/vue/select';
import { Toggle } from '@vase-ui/vue/toggle';
import { ToggleGroup } from '@vase-ui/vue/toggle-group';
import { Toolbar } from '@vase-ui/vue/toolbar';
const ICON_PROPS = {
width: '16',
height: '16',
viewBox: '0 0 16 16',
style: { display: 'block' },
};
const CaretUpDownIcon: FunctionalComponent = (_, { attrs }) =>
h('svg', { ...ICON_PROPS, fill: 'currentColor', ...attrs }, [
h('path', { d: 'M11 10H5l3 3.5zm0-4H5l3-3.5z' }),
]);
const CheckIcon: FunctionalComponent = (_, { attrs }) =>
h('svg', { ...ICON_PROPS, fill: 'none', stroke: 'currentColor', ...attrs }, [
h('path', { d: 'm2.5 8.5 4 4 7-9' }),
]);
const popupHiddenClass = 'scale-[0.98] opacity-0';
</script>
<template>
<Toolbar.Root
class="flex w-150 items-center gap-px border border-neutral-950 bg-white p-px dark:border-white dark:bg-neutral-950"
>
<ToggleGroup class="flex gap-px" aria-label="Alignment">
<Toolbar.Button
aria-label="Align left"
class="flex h-8 min-w-8 items-center justify-center gap-2 border-0 bg-transparent px-3 font-[inherit] text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-disabled:not-aria-disabled:bg-neutral-100 active:not-disabled:not-aria-disabled:not-aria-pressed:bg-neutral-200 aria-pressed:bg-neutral-950 aria-pressed:text-white aria-pressed:hover:not-disabled:not-aria-disabled:bg-neutral-950 aria-pressed:hover:not-disabled:not-aria-disabled:text-white dark:text-white dark:hover:not-disabled:not-aria-disabled:bg-neutral-800 dark:active:not-disabled:not-aria-disabled:not-aria-pressed:bg-neutral-700 dark:aria-pressed:bg-white dark:aria-pressed:text-neutral-950 dark:aria-pressed:hover:not-disabled:not-aria-disabled:bg-white dark:aria-pressed:hover:not-disabled:not-aria-disabled:text-neutral-950 focus-visible:bg-transparent focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
>
<template #element="{ props, elementRef }">
<Toggle v-bind="props" :ref="elementRef" value="align-left">Align Left</Toggle>
</template>
</Toolbar.Button>
<Toolbar.Button
aria-label="Align right"
class="flex h-8 min-w-8 items-center justify-center gap-2 border-0 bg-transparent px-3 font-[inherit] text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-disabled:not-aria-disabled:bg-neutral-100 active:not-disabled:not-aria-disabled:not-aria-pressed:bg-neutral-200 aria-pressed:bg-neutral-950 aria-pressed:text-white aria-pressed:hover:not-disabled:not-aria-disabled:bg-neutral-950 aria-pressed:hover:not-disabled:not-aria-disabled:text-white dark:text-white dark:hover:not-disabled:not-aria-disabled:bg-neutral-800 dark:active:not-disabled:not-aria-disabled:not-aria-pressed:bg-neutral-700 dark:aria-pressed:bg-white dark:aria-pressed:text-neutral-950 dark:aria-pressed:hover:not-disabled:not-aria-disabled:bg-white dark:aria-pressed:hover:not-disabled:not-aria-disabled:text-neutral-950 focus-visible:bg-transparent focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
>
<template #element="{ props, elementRef }">
<Toggle v-bind="props" :ref="elementRef" value="align-right">Align Right</Toggle>
</template>
</Toolbar.Button>
</ToggleGroup>
<Toolbar.Separator class="m-1 h-4 w-px bg-neutral-950 dark:bg-white" />
<Toolbar.Group class="flex gap-px" aria-label="Numerical format">
<Toolbar.Button
class="flex h-8 min-w-8 items-center justify-center gap-2 border-0 bg-transparent font-[inherit] text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-disabled:not-aria-disabled:bg-neutral-100 active:not-disabled:not-aria-disabled:not-data-pressed:bg-neutral-200 data-pressed:bg-neutral-950 data-pressed:text-white data-pressed:hover:not-disabled:not-aria-disabled:bg-neutral-950 data-pressed:hover:not-disabled:not-aria-disabled:text-white dark:text-white dark:hover:not-disabled:not-aria-disabled:bg-neutral-800 dark:active:not-disabled:not-aria-disabled:not-data-pressed:bg-neutral-700 dark:data-pressed:bg-white dark:data-pressed:text-neutral-950 dark:data-pressed:hover:not-disabled:not-aria-disabled:bg-white dark:data-pressed:hover:not-disabled:not-aria-disabled:text-neutral-950 focus-visible:bg-transparent focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
aria-label="Format as currency"
>$</Toolbar.Button
>
<Toolbar.Button
class="flex h-8 min-w-8 items-center justify-center gap-2 border-0 bg-transparent font-[inherit] text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-disabled:not-aria-disabled:bg-neutral-100 active:not-disabled:not-aria-disabled:not-data-pressed:bg-neutral-200 data-pressed:bg-neutral-950 data-pressed:text-white data-pressed:hover:not-disabled:not-aria-disabled:bg-neutral-950 data-pressed:hover:not-disabled:not-aria-disabled:text-white dark:text-white dark:hover:not-disabled:not-aria-disabled:bg-neutral-800 dark:active:not-disabled:not-aria-disabled:not-data-pressed:bg-neutral-700 dark:data-pressed:bg-white dark:data-pressed:text-neutral-950 dark:data-pressed:hover:not-disabled:not-aria-disabled:bg-white dark:data-pressed:hover:not-disabled:not-aria-disabled:text-neutral-950 focus-visible:bg-transparent focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
aria-label="Format as percent"
>%</Toolbar.Button
>
</Toolbar.Group>
<Toolbar.Separator class="m-1 h-4 w-px bg-neutral-950 dark:bg-white" />
<Select.Root default-value="Helvetica">
<Toolbar.Button
class="flex h-8 min-w-32 cursor-default items-center justify-between gap-2 border-0 bg-transparent px-2 font-[inherit] text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-disabled:not-aria-disabled:bg-neutral-100 active:not-disabled:not-aria-disabled:not-data-pressed:bg-neutral-200 data-pressed:bg-neutral-100 data-pressed:text-neutral-950 dark:text-white dark:hover:not-disabled:not-aria-disabled:bg-neutral-800 dark:active:not-disabled:not-aria-disabled:not-data-pressed:bg-neutral-700 dark:data-pressed:bg-neutral-800 dark:data-pressed:text-white focus-visible:bg-transparent focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
aria-label="Font"
>
<template #element="{ props, elementRef }">
<Select.Trigger v-bind="props" :ref="elementRef">
<Select.Value />
<Select.Icon>
<CaretUpDownIcon />
</Select.Icon>
</Select.Trigger>
</template>
</Toolbar.Button>
<Select.Portal>
<Select.Positioner class="z-10 outline-none select-none" :side-offset="4">
<Transition :enter-from-class="popupHiddenClass" :leave-to-class="popupHiddenClass">
<Select.Popup
class="group max-h-[var(--available-height)] min-w-[var(--anchor-width)] origin-[var(--transform-origin)] overflow-y-auto border border-neutral-950 bg-white bg-clip-padding text-neutral-950 shadow-[0.25rem_0.25rem_0] shadow-black/12 outline-none transition-[scale,opacity] duration-100 ease-out data-[side=none]:min-w-[calc(var(--anchor-width)+1.75rem)] data-[side=none]:translate-y-px data-[side=none]:scale-100 data-[side=none]:opacity-100 data-[side=none]:transition-none dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none"
>
<Select.Item
class="grid cursor-default grid-cols-[1rem_1fr] items-center gap-2 py-1.5 pr-4 pl-2.5 text-sm outline-none select-none data-highlighted:bg-neutral-950 data-highlighted:text-white pointer-coarse:py-2.5 dark:data-highlighted:bg-white dark:data-highlighted:text-neutral-950"
value="Helvetica"
v-slot="{ state }"
>
<span v-if="state.selected" class="col-start-1">
<CheckIcon />
</span>
<Select.ItemText class="col-start-2">Helvetica</Select.ItemText>
</Select.Item>
<Select.Item
class="grid cursor-default grid-cols-[1rem_1fr] items-center gap-2 py-1.5 pr-4 pl-2.5 text-sm outline-none select-none data-highlighted:bg-neutral-950 data-highlighted:text-white pointer-coarse:py-2.5 dark:data-highlighted:bg-white dark:data-highlighted:text-neutral-950"
value="Arial"
v-slot="{ state }"
>
<span v-if="state.selected" class="col-start-1">
<CheckIcon />
</span>
<Select.ItemText class="col-start-2">Arial</Select.ItemText>
</Select.Item>
</Select.Popup>
</Transition>
</Select.Positioner>
</Select.Portal>
</Select.Root>
<Toolbar.Separator class="m-1 h-4 w-px bg-neutral-950 dark:bg-white" />
<Toolbar.Link
class="mr-[0.875rem] ml-auto flex-none self-center font-[inherit] text-sm text-neutral-500 no-underline hover:text-blue-700 dark:text-neutral-400 dark:hover:text-blue-500 focus-visible:outline-2 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
href="#"
>Edited 51m ago</Toolbar.Link
>
</Toolbar.Root>
</template>Usage guidelines
To make a toolbar accessible and helpful, follow these guidelines:
- Use inputs sparingly: In an input, the left and right arrow keys move the text cursor. In a horizontal toolbar, the same keys move the focus between the controls. Put at most one input in a horizontal toolbar. Make it the last item of the toolbar.
Anatomy
Import the component and assemble its parts:
<script setup lang="ts">
import { Toolbar } from '@vase-ui/vue/toolbar';
</script>
<template>
<Toolbar.Root>
<Toolbar.Button />
<Toolbar.Link />
<Toolbar.Separator />
<Toolbar.Group>
<Toolbar.Button />
<Toolbar.Button />
</Toolbar.Group>
<Toolbar.Input />
</Toolbar.Root>
</template>Examples
Using with other components
Render a part of another component in the element slot of a toolbar part. Bind props and elementRef to it. The element then joins the keyboard navigation of the toolbar and keeps the behavior of the other part.
<script setup lang="ts">
import { Menu } from '@vase-ui/vue/menu';
import { Toolbar } from '@vase-ui/vue/toolbar';
</script>
<template>
<Toolbar.Root>
<Menu.Root>
<Toolbar.Button>
<template #element="{ props, elementRef }">
<Menu.Trigger v-bind="props" :ref="elementRef">Align</Menu.Trigger>
</template>
</Toolbar.Button>
<Menu.Portal><!-- Compose the rest of the menu --></Menu.Portal>
</Menu.Root>
</Toolbar.Root>
</template>- Popups with a trigger, such as Alert Dialog, Dialog, Drawer, Menu, Popover and Select: render the trigger in the
elementslot of<Toolbar.Button>, as the sample does. Setdisabledon<Toolbar.Button>, not on the trigger, so that the button stays in the keyboard navigation of the toolbar. - Tooltip: render
<Toolbar.Button>in theelementslot of<Tooltip.Trigger>. - Toggle: render a
Togglein theelementslot of<Toolbar.Button>, also in aToggleGroup, as the demo at the top of this page does. - Number Field: render
<NumberField.Input>in theelementslot of<Toolbar.Input>. Keep it inside<NumberField.Root>and<NumberField.Group>with the increment and decrement buttons. ASwitch, aCheckboxor aRadioalso goes in that slot. With a part in the slot,Toolbar.Inputrenders noInput, so givev-modelto that part.
See how attributes are merged for how the two parts combine.
API reference
Toolbar.Root
A container for a set of controls, such as buttons, toggle groups or menus. The toolbar is one
tab stop, so give no tabindex to a part. Remove an item with v-if, because an item that CSS
hides can still be the tab stop.
Renders a <div> element with the role toolbar.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
disabled | boolean | undefined | false | The user cannot use an item of the toolbar. A link stays enabled. |
loopFocus | boolean | undefined | true | The arrow keys move the focus from the last item to the first, and from the first to the last. |
orientation | ToolbarOrientation | undefined | 'horizontal' | The axis of the arrow keys. |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: ToolbarRootState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: ToolbarRootState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[aria-orientation="vertical"] | The toolbar is vertical. |
[data-disabled] | The toolbar is disabled. |
Toolbar.Button
A button of the toolbar. Its element slot makes a trigger or a toggle an item of the toolbar.
Renders a <button> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
disabled | boolean | undefined | false | The user cannot press the button. The toolbar stops each click, press and key on it. Tab, Escape, F1 to F12 and the keys with Ctrl, Alt or Meta pass. Hover and focus events pass too, so a tooltip can say why the button is disabled. |
focusableWhenDisabled | boolean | undefined | true | A disabled button stays in the arrow keys of the toolbar, and keeps the focus. With false, the
arrow keys pass it. |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: ToolbarButtonState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: ToolbarButtonState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[data-orientation] | The orientation of the toolbar: horizontal or vertical. |
[aria-disabled="true"] | The button is disabled, and it keeps the focus or is not a native button. |
:disabled | The button is a native button, it is disabled, and it does not keep the focus. |
Toolbar.Link
A link of the toolbar. It is never disabled.
Renders an <a> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: ToolbarLinkState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: ToolbarLinkState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[data-orientation] | The orientation of the toolbar: horizontal or vertical. |
Toolbar.Input
A text input of the toolbar. Its element slot makes another control an item of the toolbar.
A text input keeps ArrowLeft and ArrowRight while its caret can move. A textarea in the element
slot also keeps ArrowUp and ArrowDown while its caret can move.
Renders the Input part, an <input> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
defaultValue | NonNullable<string | number | string[] | undefined> | undefined | The text of an input that owns its text, at the mount and at a native reset of the form. | |
disabled | boolean | undefined | false | The user cannot edit the input. |
focusableWhenDisabled | boolean | undefined | true | A disabled input stays in the arrow keys of the toolbar, and keeps the focus. It is read-only.
With false, the arrow keys pass it. |
id | string | undefined | The id of the input, or of the element of the element slot. | |
modelValue | NonNullable<string | number | readonly string[] | undefined> | undefined | The text of the input. With no value, the input owns its text. | |
name | string | undefined | The name of the input in the form data. | |
readonly | boolean | undefined | The user cannot edit the text. A disabled input that keeps the focus is read-only too. |
Slots
| Slot | Slot props | Description |
|---|---|---|
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: ToolbarInputState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Events
| Event | Arguments | Description |
|---|---|---|
valueChange | [value: string, details: InputChangeEventDetails] | The user changes the text. details.cancel() keeps the text as it was. |
update:modelValue | [value: string] | Comes after the change event with the new value, unless a listener cancels the change. v-model uses it. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[data-orientation] | The orientation of the toolbar: horizontal or vertical. |
[aria-disabled="true"] | The input is disabled and keeps the focus. |
:disabled | The input is disabled and does not keep the focus. |
Toolbar.Group
Groups several toolbar items or toggles.
Renders a <div> element with the role group.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
disabled | boolean | undefined | false | The user cannot use an item of the group. A link stays enabled. |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: ToolbarGroupState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: ToolbarGroupState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[data-orientation] | The orientation of the toolbar: horizontal or vertical. |
[data-disabled] | The group or the toolbar is disabled. |
Toolbar.Separator
A separator of the toolbar, across the toolbar.
Renders the Separator part, a <div> element with the role separator.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
orientation | "horizontal" | "vertical" | undefined | The orientation of the separator. With no value, it is across the toolbar: vertical in a horizontal toolbar. | |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: ToolbarSeparatorState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: ToolbarSeparatorState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLDivElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[aria-orientation="vertical"] | The separator is vertical. |
Toolbar.Orientation
The orientation of the toolbar.
'horizontal' | 'vertical'
Differences from Base UI
Vase UI ports Toolbar from Base UI 1.9.0.
API
| Base UI | Vase UI |
|---|---|
Toolbar.Button prop nativeButton | The part reads the element that it renders, so it needs no nativeButton. as or the element slot renders another element. |
Added in Vase UI
| Part | Member | Why |
|---|---|---|
Toolbar.Input | modelValue prop | Toolbar.Input gives v-model to the Input that it renders. |
Toolbar.Input | valueChange event | Toolbar.Input gives the change event of the Input that it renders, with its details. |
Toolbar.Input | update:modelValue event | Toolbar.Input gives the model update of the Input that it renders, for v-model. |
Behavior
| Vase UI | Evidence |
|---|---|
When the item that has the tab stop of a composite becomes disabled while the focus is outside the composite, and the arrow keys skip that item, the tab stop moves to the active item when the arrow keys reach it, or else to the first item that they reach. When the item becomes disabled while it has the focus, the tab stop moves when the focus leaves. At the mount, a checked radio that is a disabled native button also gives the tab stop to the first radio that the arrow keys reach. The arrow keys skip a natively disabled item. They also skip an aria-disabled item, unless the root gives disabledIndices and the item is not in it. Thus the Tab key does not focus a radio that the arrow keys skip in a Radio Group with no checked radio, and a Toggle Group or a Menubar stays in the order of the Tab key. Toolbar.Root keeps the tab stop on a disabled item that stays focusable. An active item that becomes disabled keeps the tab stop while it can get focus, as at the mount. In Base UI, an item that becomes disabled keeps the tab stop, and at the mount a checked radio keeps it also when it is a disabled native button. The Tab key then focuses a disabled radio, or it skips a whole Radio Group, Toggle Group or Menubar, because the item with the tab stop has the disabled attribute. A native control also follows its fieldset when it or its wrapper moves. Controls in the first legend keep the native exemption. |
|
| A key in the list of a popup, such as an arrow key, reaches the listeners of the elements around the popup, as each DOM event does. Only an Escape that the popup handles stops at the popup. A toolbar around the trigger moves no focus for a key that comes from the popup. Base UI stops the propagation of the arrow keys in the popup. | |
A button part knows the element of a component in as or of the element slot only at the mount, and it needs no prop that says what the element is. Until the mount, the element has the attributes that suit a <button> and each other element: type="button", role="button", a tab stop, and the disabled state of both. So in the server HTML, Tab reaches a <div> before a lazy hydration, and a <button> does not submit its form. At the mount, the part keeps the attributes of its element. Base UI needs nativeButton set to false for an element that is not a <button>. |
|
The handbook gives the differences that all components share: Styling, Animation, Composition, Customization, Forms and TypeScript.