Are you an LLM? You can read better optimized documentation at /docs/components/toolbar.md for this page in Markdown format
Toolbar
A container for grouping a set of buttons and controls.
vue
<script setup lang="ts">
import {
Toggle,
ToggleGroup,
ToolbarButton,
ToolbarGroup,
ToolbarLink,
ToolbarRoot,
ToolbarSeparator,
} from 'base-ui-vue'
</script>
<template>
<ToolbarRoot class="flex w-[37.5rem] items-center gap-px rounded-md border border-gray-200 bg-gray-50 p-0.5" aria-label="Text formatting">
<ToggleGroup class="flex gap-1" aria-label="Alignment">
<ToolbarButton :as="Toggle" class="flex h-8 items-center justify-center rounded-xs px-3 font-[inherit] text-sm font-normal text-gray-600 select-none hover:bg-gray-100 focus-visible:bg-none focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-blue-800 active:bg-gray-200 data-[pressed]:bg-gray-100 data-[pressed]:text-gray-900" value="align-left" aria-label="Align left">
Align Left
</ToolbarButton>
<ToolbarButton :as="Toggle" class="flex h-8 items-center justify-center rounded-xs px-3 font-[inherit] text-sm font-normal text-gray-600 select-none hover:bg-gray-100 focus-visible:bg-none focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-blue-800 active:bg-gray-200 data-[pressed]:bg-gray-100 data-[pressed]:text-gray-900" value="align-right" aria-label="Align right">
Align Right
</ToolbarButton>
</ToggleGroup>
<ToolbarSeparator class="m-1 h-4 w-px bg-gray-300" />
<ToolbarGroup class="flex gap-1" aria-label="Number format">
<ToolbarButton class="flex size-8 items-center justify-center rounded-xs px-3 font-[inherit] text-sm font-normal text-gray-600 select-none hover:bg-gray-100 focus-visible:bg-none focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-blue-800 active:bg-gray-200 data-[pressed]:bg-gray-100 data-[pressed]:text-gray-900 data-disabled:text-gray-500" aria-label="Format as currency">
$
</ToolbarButton>
<ToolbarButton class="flex size-8 items-center justify-center rounded-xs px-3 font-[inherit] text-sm font-normal text-gray-600 select-none hover:bg-gray-100 focus-visible:bg-none focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-blue-800 active:bg-gray-200 data-[pressed]:bg-gray-100 data-[pressed]:text-gray-900 data-disabled:text-gray-500" aria-label="Format as percent">
%
</ToolbarButton>
</ToolbarGroup>
<ToolbarSeparator class="m-1 h-4 w-px bg-gray-300" />
<!-- TODO: Replace this HTML select trigger stand-in with Select once the Vue package includes it. -->
<button type="button" role="combobox" aria-label="Font family" aria-haspopup="listbox" aria-expanded="false" class="flex h-8 min-w-[8rem] items-center justify-between gap-3 rounded-xs px-3 text-sm font-normal text-gray-600 select-none hover:bg-gray-100 focus-visible:bg-none focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-blue-800 cursor-default">
<span>Helvetica</span>
<span class="flex" aria-hidden="true">
<svg width="8" height="12" viewBox="0 0 8 12" fill="none" stroke="currentColor" stroke-width="1.5">
<path d="M0.5 4.5L4 1.5L7.5 4.5" />
<path d="M0.5 7.5L4 10.5L7.5 7.5" />
</svg>
</span>
</button>
<ToolbarSeparator class="m-1 h-4 w-px bg-gray-300" />
<ToolbarLink class="ml-auto mr-3.5 self-center flex-none text-sm text-gray-500! no-underline! hover:text-blue-800! focus-visible:rounded-xs focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-blue-800" href="#toolbar-demo">
Edited 51m ago
</ToolbarLink>
</ToolbarRoot>
</template>Usage guidelines
- Use inputs sparingly: In horizontal toolbars, arrow keys are used both for roving focus and for moving the text cursor inside inputs. Keep inputs to a minimum and place them near the end of the toolbar.
Anatomy
Import the components and assemble their parts:
vue
<script setup>
import {
ToolbarButton,
ToolbarGroup,
ToolbarInput,
ToolbarLink,
ToolbarRoot,
ToolbarSeparator,
} from 'base-ui-vue'
</script>
<template>
<ToolbarRoot>
<ToolbarButton />
<ToolbarLink href="#" />
<ToolbarSeparator />
<ToolbarGroup>
<ToolbarButton />
<ToolbarButton />
</ToolbarGroup>
<ToolbarInput />
</ToolbarRoot>
</template>API reference
Root
A container for grouping a set of controls, such as buttons, toggle groups, or menus. Renders a <div> element.
| Prop | Type | Default | Description |
|---|---|---|---|
as | string | Component | 'div' | The element or component to use for the root node. |
disabled | boolean | false | Whether the component is disabled. |
orientation | 'horizontal' | 'vertical' | 'horizontal' | The orientation of the toolbar. |
loop-focus | boolean | true | If true, using keyboard navigation will wrap focus to the other end of the toolbar once the end is reached. |
class | string | ((state: State) => string) | undefined | CSS class applied to the element, or a function that returns a class based on the component state. |
style | StyleValue | ((state: State) => StyleValue) | undefined | Style applied to the element, or a function that returns a style object based on the component state. |
| Attribute | Description |
|---|---|
data-disabled | Present when the toolbar is disabled. |
data-orientation | Indicates the toolbar orientation. |
Button
A button that can be used as-is or as a trigger for other components. Renders a <button> element.
| Prop | Type | Default | Description |
|---|---|---|---|
as | string | Component | 'button' | The element or component to use for the root node. |
disabled | boolean | false | Whether the component is disabled. |
focusable-when-disabled | boolean | true | Whether the component remains focusable when disabled. |
native-button | boolean | true | Whether the component is being rendered as a native button. |
class | string | ((state: State) => string) | undefined | CSS class applied to the element, or a function that returns a class based on the component state. |
style | StyleValue | ((state: State) => StyleValue) | undefined | Style applied to the element, or a function that returns a style object based on the component state. |
| Attribute | Description |
|---|---|
data-disabled | Present when the button is disabled. |
data-focusable | Present when the button remains focusable while disabled. |
data-orientation | Indicates the toolbar orientation. |
Link
A link component. Renders an <a> element.
| Prop | Type | Default | Description |
|---|---|---|---|
as | string | Component | 'a' | The element or component to use for the root node. |
class | string | ((state: State) => string) | undefined | CSS class applied to the element, or a function that returns a class based on the component state. |
style | StyleValue | ((state: State) => StyleValue) | undefined | Style applied to the element, or a function that returns a style object based on the component state. |
| Attribute | Description |
|---|---|
data-orientation | Indicates the toolbar orientation. |
Input
A native input element that integrates with Toolbar keyboard navigation. Renders an <input> element.
| Prop | Type | Default | Description |
|---|---|---|---|
as | string | Component | 'input' | The element or component to use for the root node. |
disabled | boolean | false | Whether the component is disabled. |
focusable-when-disabled | boolean | true | Whether the component remains focusable when disabled. |
default-value | string | number | undefined | The initial input value. |
class | string | ((state: State) => string) | undefined | CSS class applied to the element, or a function that returns a class based on the component state. |
style | StyleValue | ((state: State) => StyleValue) | undefined | Style applied to the element, or a function that returns a style object based on the component state. |
| Attribute | Description |
|---|---|
data-disabled | Present when the input is disabled. |
data-focusable | Present when the input remains focusable while disabled. |
data-orientation | Indicates the toolbar orientation. |
Group
Groups several toolbar items or toggles. Renders a <div> element.
| Prop | Type | Default | Description |
|---|---|---|---|
as | string | Component | 'div' | The element or component to use for the root node. |
disabled | boolean | false | Whether all toolbar items in the group are disabled. |
class | string | ((state: State) => string) | undefined | CSS class applied to the element, or a function that returns a class based on the component state. |
style | StyleValue | ((state: State) => StyleValue) | undefined | Style applied to the element, or a function that returns a style object based on the component state. |
| Attribute | Description |
|---|---|
data-disabled | Present when the group is disabled. |
data-orientation | Indicates the toolbar orientation. |
Separator
A separator element accessible to screen readers. Renders a <div> element.
| Prop | Type | Default | Description |
|---|---|---|---|
as | string | Component | 'div' | The element or component to use for the root node. |
orientation | 'horizontal' | 'vertical' | undefined | The orientation of the separator. Defaults to the opposite of the toolbar orientation when not provided. |
class | string | ((state: State) => string) | undefined | CSS class applied to the element, or a function that returns a class based on the component state. |
style | StyleValue | ((state: State) => StyleValue) | undefined | Style applied to the element, or a function that returns a style object based on the component state. |
| Attribute | Description |
|---|---|
data-orientation | Indicates the orientation of the separator. |