Used with a component · Toolbar
useToolbar
The engine behind <Toolbar>: one Tab stop for the whole toolbar, arrow keys between its controls (the APG toolbar pattern), and Priority+ overflow. Controls are the list's buttons, links, inputs, selects, textareas and anything with a non-negative tabindex. Mark controls that may collapse with data-toolbar-overflow; when the toolbar runs out of room, they hide from the end backward and move into collapsedItems. <Toolbar> adds the groups, the hover highlight and a … Menu built from the collapsed controls' labels. Use the composable to give your own toolbar markup the same behavior.
Install
import { useToolbar } from 'vael-ui'Examples
<script setup lang="ts">
import { useTemplateRef } from 'vue'
import { useToolbar } from 'vael-ui'
const toolbarEl = useTemplateRef<HTMLElement>('toolbar')
const { onKeydown, collapsedItems, hasOverflow } = useToolbar(toolbarEl)
</script>
<template>
<div ref="toolbar" role="toolbar" aria-label="Formatting" class="toolbar" @keydown="onKeydown">
<button>Bold</button>
<button>Italic</button>
<button data-toolbar-overflow>Strikethrough</button>
<button data-toolbar-overflow>Code</button>
<button v-if="hasOverflow" data-toolbar-ellipsis aria-label="More">…</button>
</div>
<p>{{ collapsedItems.length }} hidden</p>
</template>
<style scoped>
.toolbar { display: flex; overflow: hidden; }
.toolbar > * { flex-shrink: 0; }
</style>