All components
Toolbar
A row of buttons, links, inputs and toggle groups with a single Tab stop and arrow-key navigation.
1234567891011121314151617181920import { Toolbar } from "#components/ui/base-ui/toolbar.tsx";import { ToggleGroup } from "#components/ui/base-ui/toggle-group.tsx";
export function Example() { return ( // one Tab stop; arrow keys rove across every item, toggle-group items // included (Base UI's ToggleGroup joins the toolbar's focus order) <Toolbar.Root variant="surface" size="md" aria-label="Text formatting"> <ToggleGroup.Root multiple aria-label="Formatting"> <ToggleGroup.Item value="bold" aria-label="Bold"><BoldIcon /></ToggleGroup.Item> <ToggleGroup.Item value="italic" aria-label="Italic"><ItalicIcon /></ToggleGroup.Item> </ToggleGroup.Root> <Toolbar.Separator /> <Toolbar.Link href="/history">Edited 5m ago</Toolbar.Link> <Toolbar.Button>Share</Toolbar.Button> </Toolbar.Root> );}
// wrap another component's trigger: <Toolbar.Button render={<Menu.Trigger />}>More</Toolbar.Button>Variants
surface
plain
Sizes
With an input
Toolbar.Input joins the arrow-key order; while it has focus the caret keys edit text until the caret reaches either end.
123456789101112import { Toolbar } from "#components/ui/base-ui/toolbar.tsx";
export function Example() { return ( <Toolbar.Root aria-label="Search"> <Toolbar.Button>Filter</Toolbar.Button> <Toolbar.Input placeholder="Search…" aria-label="Search" /> <Toolbar.Separator /> <Toolbar.Button>Export</Toolbar.Button> </Toolbar.Root> );}Vertical
orientation="vertical" stacks the items, turns separators horizontal and moves focus with Up and Down.
12345678910111213141516import { Toolbar } from "#components/ui/base-ui/toolbar.tsx";import { ToggleGroup } from "#components/ui/base-ui/toggle-group.tsx";
export function Example() { return ( <Toolbar.Root orientation="vertical" aria-label="Alignment"> <ToggleGroup.Root orientation="vertical" defaultValue={["left"]} aria-label="Alignment"> <ToggleGroup.Item value="left" aria-label="Align left"><AlignLeftIcon /></ToggleGroup.Item> <ToggleGroup.Item value="center" aria-label="Align center"><AlignCenterIcon /></ToggleGroup.Item> <ToggleGroup.Item value="right" aria-label="Align right"><AlignRightIcon /></ToggleGroup.Item> </ToggleGroup.Root> <Toolbar.Separator /> <Toolbar.Button aria-label="Bold"><BoldIcon /></Toolbar.Button> </Toolbar.Root> );}Plain
The plain variant drops the panel chrome so the toolbar can sit inside a header or card.
123456<Toolbar.Root variant="plain" aria-label="Actions"> <Toolbar.Button>Reply</Toolbar.Button> <Toolbar.Button>Forward</Toolbar.Button> <Toolbar.Separator /> <Toolbar.Button disabled>Archive</Toolbar.Button></Toolbar.Root>Install
1npx stylexblocks add toolbarSource
components/ui/base-ui/toolbar.tsx
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309import * as stylex from "@stylexjs/stylex";import { Toolbar as BaseToolbar } from "@base-ui/react/toolbar";import { createSlotRecipeContext } from "#lib/base-ui/create-slot-recipe-context.tsx";import { defineSlotRecipe } from "#lib/recipe-props.ts";import { colorPalette } from '@stylexblocks/ui/color-palette.stylex.ts'import { durations } from '@stylexblocks/ui/tokens/durations.stylex.ts'import { fontSizes } from '@stylexblocks/ui/tokens/font-sizes.stylex.ts'import { fontWeights } from '@stylexblocks/ui/tokens/font-weights.stylex.ts'import { lineHeights } from '@stylexblocks/ui/tokens/line-heights.stylex.ts'import { semanticColors } from '@stylexblocks/ui/semantic-tokens/colors.stylex.ts'import { semanticRadii } from '@stylexblocks/ui/semantic-tokens/radii.stylex.ts'import { semanticShadows } from '@stylexblocks/ui/semantic-tokens/shadows.stylex.ts'import { sizes } from '@stylexblocks/ui/tokens/sizes.stylex.ts'import { spacing } from '@stylexblocks/ui/tokens/spacing.stylex.ts'
// A row (or column) of controls. Buttons and links (both the `button` slot)// share the Toggle's ghost metrics so toggle groups sit flush beside them;// orientation is read from the `data-orientation` attribute both engines// emit.
const toolbarRoot = stylex.create({ base: { display: 'flex', alignItems: 'center', flexDirection: { default: 'row', ':is([data-orientation="vertical"])': 'column', }, width: 'fit-content', gap: spacing._1, },})
const toolbarRootVariants = stylex.create({ surface: { backgroundColor: semanticColors.bgPanel, borderWidth: '1px', borderStyle: 'solid', borderColor: semanticColors.border, borderRadius: semanticRadii.panel, boxShadow: semanticShadows.xs, padding: spacing._1, }, plain: {},})
const toolbarRootSizes = stylex.create({ xs: { gap: spacing._0_5, }, sm: { gap: spacing._1, }, md: { gap: spacing._1, }, lg: { gap: spacing._1_5, },})
const toolbarGroup = stylex.create({ base: { display: 'flex', alignItems: 'center', flexDirection: { default: 'row', ':is([data-orientation="vertical"])': 'column', }, gap: spacing._1, },})
const toolbarButton = stylex.create({ base: { display: 'inline-flex', appearance: 'none', alignItems: 'center', justifyContent: 'center', userSelect: 'none', position: 'relative', whiteSpace: 'nowrap', flexShrink: 0, margin: 0, borderWidth: 0, fontFamily: 'inherit', fontWeight: fontWeights.medium, lineHeight: 1.2, textDecoration: 'none', outline: 'none', transitionProperty: 'background-color, border-color, color, box-shadow', transitionDuration: durations.moderate, outlineWidth: { default: null, ':focus-visible': '1px', }, outlineOffset: { default: null, ':focus-visible': '2px', }, outlineStyle: { default: null, ':focus-visible': 'solid', }, outlineColor: { default: null, ':focus-visible': colorPalette.focusRing, }, opacity: { default: null, ':is(:disabled, [disabled], [data-disabled])': 0.5, }, cursor: { default: 'pointer', ':is(:disabled, [disabled], [data-disabled])': 'not-allowed', }, color: { default: semanticColors.fgMuted, ':hover': semanticColors.fg, ':is([data-popup-open], [data-state="open"], [aria-expanded="true"])': semanticColors.fg, }, backgroundColor: { default: 'transparent', ':hover': colorPalette.muted, ':is([data-popup-open], [data-state="open"], [aria-expanded="true"])': colorPalette.subtle, }, },})
const toolbarButtonSizes = stylex.create({ xs: { gap: spacing._1, height: sizes.controlXs, minWidth: sizes.controlXs, borderRadius: semanticRadii.control, paddingInline: spacing._1_5, fontSize: fontSizes.xs, lineHeight: lineHeights.xs, }, sm: { gap: spacing._1_5, height: sizes.controlSm, minWidth: sizes.controlSm, borderRadius: semanticRadii.control, paddingInline: spacing._2, fontSize: fontSizes.sm, lineHeight: lineHeights.sm, }, md: { gap: spacing._2, height: sizes.controlMd, minWidth: sizes.controlMd, borderRadius: semanticRadii.control, paddingInline: spacing._2_5, fontSize: fontSizes.sm, lineHeight: lineHeights.sm, }, lg: { gap: spacing._2, height: sizes.controlLg, minWidth: sizes.controlLg, borderRadius: semanticRadii.control, paddingInline: spacing._3, fontSize: fontSizes.md, lineHeight: lineHeights.md, },})
const toolbarInput = stylex.create({ base: { display: 'inline-flex', appearance: 'none', alignItems: 'center', flexShrink: 0, minWidth: 0, width: '10rem', margin: 0, fontFamily: 'inherit', fontWeight: fontWeights.normal, color: semanticColors.fg, backgroundColor: semanticColors.bg, borderWidth: '1px', borderStyle: 'solid', borderColor: { default: semanticColors.border, ':hover': semanticColors.borderEmphasized, }, cursor: { default: 'text', ':is(:disabled, [disabled], [data-disabled])': 'not-allowed', }, transitionProperty: 'border-color, box-shadow', transitionDuration: durations.moderate, outline: 'none', outlineWidth: { default: null, ':focus-visible': '1px', }, outlineOffset: { default: null, ':focus-visible': '-1px', }, outlineStyle: { default: null, ':focus-visible': 'solid', }, outlineColor: { default: null, ':focus-visible': colorPalette.focusRing, }, opacity: { default: null, ':is(:disabled, [disabled], [data-disabled])': 0.5, }, },})
const toolbarInputSizes = stylex.create({ xs: { height: sizes.controlXs, borderRadius: semanticRadii.control, paddingInline: spacing._2, fontSize: fontSizes.xs, }, sm: { height: sizes.controlSm, borderRadius: semanticRadii.control, paddingInline: spacing._2, fontSize: fontSizes.sm, }, md: { height: sizes.controlMd, borderRadius: semanticRadii.control, paddingInline: spacing._2_5, fontSize: fontSizes.sm, }, lg: { height: sizes.controlLg, borderRadius: semanticRadii.control, paddingInline: spacing._3, fontSize: fontSizes.md, },})
const toolbarSeparator = stylex.create({ base: { flexShrink: 0, alignSelf: 'stretch', backgroundColor: semanticColors.border, width: { default: '1px', ':is([data-orientation="horizontal"])': 'auto', }, height: { default: 'auto', ':is([data-orientation="horizontal"])': '1px', }, marginInline: { default: spacing._1, ':is([data-orientation="horizontal"])': 0, }, marginBlock: { default: spacing._1, ':is([data-orientation="horizontal"])': 0, }, },})
export type ToolbarVariant = keyof typeof toolbarRootVariants
export type ToolbarSize = keyof typeof toolbarRootSizes
const toolbarRecipe = defineSlotRecipe({ slots: { root: { styles: toolbarRoot, variants: toolbarRootVariants, sizes: toolbarRootSizes }, group: { styles: toolbarGroup }, button: { styles: toolbarButton, sizes: toolbarButtonSizes }, input: { styles: toolbarInput, sizes: toolbarInputSizes }, separator: { styles: toolbarSeparator }, }, defaultVariants: { variant: "surface", size: "md" },});
const { withProvider, withContext } = createSlotRecipeContext(toolbarRecipe);
/** * Toolbar — Base UI's Toolbar wearing the toolbar slot recipe: * `role="toolbar"`, a single Tab stop and roving focus with the arrow keys * (disabled buttons stay focusable by default). `<Toolbar.Root variant * size>` resolves the recipe once; parts inherit it. A Base UI ToggleGroup * placed inside joins the toolbar's focus order on its own. Wrap triggers * from other components with `<Toolbar.Button render={<Menu.Trigger />} />`. */export const Toolbar = { Root: withProvider(BaseToolbar.Root, "root", "ToolbarRoot"), Group: withContext(BaseToolbar.Group, "group", "ToolbarGroup"), Button: withContext(BaseToolbar.Button, "button", "ToolbarButton"), Link: withContext(BaseToolbar.Link, "button", "ToolbarLink"), Input: withContext(BaseToolbar.Input, "input", "ToolbarInput"), Separator: withContext(BaseToolbar.Separator, "separator", "ToolbarSeparator"),};
export type ToolbarRootProps = React.ComponentProps<typeof Toolbar.Root>;export type ToolbarButtonProps = React.ComponentProps<typeof Toolbar.Button>;export type ToolbarLinkProps = React.ComponentProps<typeof Toolbar.Link>;export type ToolbarInputProps = React.ComponentProps<typeof Toolbar.Input>;