Used with a component · Tabs
useTabs
The keyboard engine behind <Tabs>: selection, roving focus and arrow key navigation from the ARIA Authoring Practices Guide (APG) tabs pattern. It renders nothing. You render the role="tab" elements and bind onKeydown on the list. <Tabs> adds the markup, ids, panel wiring and the sliding indicators on top. Use the composable when your tabs need markup the #item slot can't give you.
Install
import { useTabs } from 'vael-ui'Examples
<script setup lang="ts">
import { shallowRef, useTemplateRef } from 'vue'
import { useTabs } from 'vael-ui'
const tabs = ['general', 'billing', 'team'] as const
const active = shallowRef<(typeof tabs)[number]>('general')
const listEl = useTemplateRef<HTMLElement>('list')
const { select, onKeydown } = useTabs(active, { items: tabs, listEl })
</script>
<template>
<div ref="list" role="tablist" @keydown="onKeydown">
<button
v-for="tab in tabs"
:key="tab"
role="tab"
:data-tab-value="tab"
:aria-selected="active === tab"
:tabindex="active === tab ? 0 : -1"
@click="select(tab)"
>
{{ tab }}
</button>
</div>
</template>