Navigation & menus
Layout
Tabs
A row of tabs that switches between panels, with a sliding indicator under the active tab. Use it to split related content into views on one page.
Install
import { Tabs } from 'vael-ui'Playground
horizontal
automatic
Usage
<script setup lang="ts">
import { ref } from 'vue'
import { Tabs } from 'vael-ui'
const items = ['Overview', 'Activity', 'Settings']
const active = ref('Overview')
</script>
<template>
<Tabs :items="items" v-model:active="active">
<template #default="{ items, itemProps, indicatorProps }">
<div v-bind="indicatorProps()" />
<button v-for="item in items" :key="item" type="button" v-bind="itemProps(item)">
{{ item }}
</button>
</template>
</Tabs>
</template>Motion New
Tabs's motion: values or hooks for its parts (TabsPart), how its indicator moves (a move hook). false turns it off.
<Tabs
:motion="{ initial: { item: { opacity: 0, y: 4 } } }"
/>| Name | Type | Description |
|---|---|---|
initialexit | listitemindicator | Sets 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) => animation | Animates 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) => animation | Moves 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 | string | Times all of it: a spring, or a duration in ms with an easing. Never both. |
false | boolean | Turns its motion off, for an animation of your own on its exposed elements. |
Accessibility
Follows the Tabs pattern from the WAI-ARIA Authoring Practices Guide.
| Key | Action |
|---|---|
| ArrowRightArrowLeft | Moves to the next or previous tab, wrapping at the ends and skipping disabled tabs. |
| ArrowDownArrowUp | Moves to the next or previous tab when orientation is vertical. |
| HomeEnd | Moves to the first or last enabled tab. |
| EnterSpace | Selects the focused tab when activation is manual. |
- The root has
role="tablist", witharia-orientation="vertical"when vertical. Attributes such asaria-labelgo on it. itemProps(item)gives each tabrole="tab",type="button",aria-selected, anidand a rovingtabindex. Inautomaticmode, arrow keys select as they move. Inmanualmode, Tab back into the list lands on the selected tab.- Set
idBaseso tabs getaria-controls, and spread the exposedpanelProps(value)on each panel forrole="tabpanel",aria-labelledby, andtabindex="0"on the selected one. - Right to left, ArrowLeft and ArrowRight swap.