vael-ui v0.5.7

Actions

Layout

Toolbar

A strip of related controls with arrow-key focus and an overflow menu for what doesn’t fit. Use it to group the actions for one view or one editor.

Install

import { Toolbar } from 'vael-ui'

Playground

Placement, behaviour and animation

Usage
<script setup lang="ts">
import { Toolbar, Button } from 'vael-ui'
</script>

<template>
  <Toolbar>
    <Button variant="ghost" size="sm">Bold</Button>
    <Button variant="ghost" size="sm">Italic</Button>
    <Button variant="ghost" size="sm" data-toolbar-overflow>Cut</Button>
    <Button variant="ghost" size="sm" data-toolbar-overflow>Copy</Button>
    <Button variant="ghost" size="sm" data-toolbar-overflow>Paste</Button>
  </Toolbar>
</template>

Props

NameTypeDefaultDescription
orientation'horizontal' | 'vertical''horizontal'Lays the controls out in a row or a column; arrow keys follow the axis.
overflowLabelstring'More'Accessible label for the overflow (…) menu button.
uiPartial<Record<'root' | 'group' | 'overflowTrigger', UiPartValue>>Class and style overrides for each part.
motionToolbarMotionHow it moves: its appearance, control by control ({ initial: { item: { opacity: 0, y: 4 } }, stagger: 0.03 }), over root, item (each control in a group) and the hover indicator. spring retimes the indicator; move hands its moves to your own animation. false turns its own animation off.

Events

No events.

Slots

NameTypeDescription
startanyControls at the start of the toolbar. Mark a child data-toolbar-overflow to let it collapse into the … menu.
defaultanyControls in the start group, after #start.
centeranyControls in the center group.
endanyControls at the end of the toolbar, before the … overflow menu.

Exposed

NameTypeDescription
elHTMLElement | nullRoot element.
highlightElHTMLElement | nullThe hover and keyboard highlight, sliding between buttons. Under a ConfigProvider with motion: false it moves at once, for your own animation.
partsRecord<string, HTMLElement | HTMLElement[] | null>Its elements by part name, for your own animation; a repeated part is an array.

Motion New

Toolbar: its appearance, and how the hover highlight moves.

<Toolbar
  :motion="{ initial: { item: { opacity: 0, y: 4 } } }"
/>
NameTypeDescription
initialexitrootitemindicatorSets where each part comes in from and leaves to: any CSS property, plus x, y and blur. A plain number is px, or degrees for rotate.
enterleave(parts, context) => animationAnimates the parts with GSAP, motion or element.animate(). Return the animation and the component waits for it, and stops it if interrupted.
move(parts, context) => animationMoves its sliding indicator. A spring retimes it, and a move hook animates it with your own library, starting from context.from.
springdurationeasing{ damping, response } | number | stringTimes all of it: a spring, or a duration in ms with an easing. Never both.
falsebooleanTurns its motion off, for an animation of your own on its exposed elements.

Accessibility

Follows the Toolbar pattern from the WAI-ARIA Authoring Practices Guide.

KeyAction
TabMoves focus to the item focused last, then out of the toolbar.
ArrowRightArrowLeftMoves to the next or previous item in a horizontal toolbar, wrapping at the ends.
ArrowDownArrowUpMoves to the next or previous item in a vertical toolbar, wrapping at the ends.
HomeEndMoves to the first or last item.
  • Renders role="toolbar", with aria-orientation="vertical" when vertical. Pass aria-label to name it.
  • Items use a roving tabindex, so the toolbar is one Tab stop. Disabled items are skipped. Text fields, selects and editable areas inside keep their own arrow keys, Home and End, as does a child that calls preventDefault.
  • Items that overflow are hidden and listed in a Menu behind a button named by overflowLabel (a translated “More” by default). Toggles with aria-pressed show there as checkbox rows.
  • Right to left, ArrowLeft and ArrowRight swap.