vael-ui v0.5.7

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

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>

Props

NameTypeDefaultDescription
itemsRequiredT[]Tab values, in order; drives keyboard navigation.
orientation'horizontal' | 'vertical''horizontal'Lays the tabs out in a row or a column; arrow keys follow the axis.
activation'manual' | 'automatic''automatic''automatic': arrow keys select. 'manual': arrow keys move focus only, and Enter or Space selects.
idBasestringPrefix for the tab and panel ids. Set it when you render tab panels: each tab then gets aria-controls="{idBase}-panel-{value}", so give each panel that id (or spread the exposed panelProps(value)). Values should be id-safe (no spaces).
uiPartial<Record<'list' | 'item' | 'indicator', UiPartValue>>Class and style overrides for each part.
motionTabsMotionHow it moves: its appearance, tab by tab ({ initial: { item: { opacity: 0, y: 4 } } }), over list, item and your indicator. spring retimes the indicator; move hands its moves to your own animation. false turns its own animation off.
activeRequiredTActive tab value.

Events

NameTypeDescription
change(item: T)Fires when you select a different tab.
update:active(value: T)Fires when active changes (v-model:active).

Slots

NameTypeDescription
default{ active: T; focused: T; select: (item: T) => void; items: T[]; itemProps: (item: T) => { role: "tab"; id: string; 'aria-controls': string | undefined; class: string; style: StyleValue; 'data-tab-value': string; 'aria-selected': boolean; tabindex: 0 | -1; onClick: () => void; }; indicatorProps: (variant?: "background" | "underline" | undefined) => { class: string; style: Record<string, string | undefined>; }; tabId: (item: T) => string; panelId: (item: T) => string; }The tab buttons: bind itemProps(item) on each, and indicatorProps() on an optional sibling for the sliding highlight.

Exposed

NameTypeDescription
elHTMLElement | nullRoot element: the tab list.
listElHTMLElement | nullTab list (root) element.
highlightElHTMLElement | nullThe hover and keyboard highlight, sliding between tabs. Under a ConfigProvider with motion: false it moves at once, for your own animation.
tabId(item: T) => stringThe id a tab carries.
panelId(item: T) => stringThe id a tab's panel should carry.
panelProps(item: T) => { id: string; role: "tabpanel"; 'aria-labelledby': string; tabindex: 0 | undefined; }id, role="tabpanel", aria-labelledby and tabindex for a panel you render.
partsRecord<string, HTMLElement | HTMLElement[] | null>Its elements by part name, for your own animation; a repeated part is an array.

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 } } }"
/>
NameTypeDescription
initialexitlistitemindicatorSets 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 Tabs pattern from the WAI-ARIA Authoring Practices Guide.

KeyAction
ArrowRightArrowLeftMoves to the next or previous tab, wrapping at the ends and skipping disabled tabs.
ArrowDownArrowUpMoves to the next or previous tab when orientation is vertical.
HomeEndMoves to the first or last enabled tab.
EnterSpaceSelects the focused tab when activation is manual.
  • The root has role="tablist", with aria-orientation="vertical" when vertical. Attributes such as aria-label go on it.
  • itemProps(item) gives each tab role="tab", type="button", aria-selected, an id and a roving tabindex. In automatic mode, arrow keys select as they move. In manual mode, Tab back into the list lands on the selected tab.
  • Set idBase so tabs get aria-controls, and spread the exposed panelProps(value) on each panel for role="tabpanel", aria-labelledby, and tabindex="0" on the selected one.
  • Right to left, ArrowLeft and ArrowRight swap.