Tabs
Switch between sections of content.
Demos
Project overview and recent updates.
Usage
<script setup lang="ts">
import { Accordion } from '~/components/ui/accordion'
const items = [
{ value: 'source', label: 'Do I own the source?', content: 'Yes. Copy and adapt the files.' },
]
</script>
<template>
<Accordion :items="items" />
</template>
The default soft variant uses inset segmented pills with a sliding selection background. Items and the indicator follow the control radius for the selected size; the container adds 4px to that radius. At sm, the inner radius is 6px and the outer radius is 10px. The surface stays flat, without a resting shadow. The line variant uses a sliding underline. Both respect reduced-motion preferences.
Panels share one grid area by default, reserving room for the tallest retained panel and switching content with a 60ms fade-out followed by a 140ms, 4px slide-fade. Only one panel is painted at a time, so text does not overlap during the transition. Inactive panels stay hidden from interaction. If you enable unmountOnHide, use ui.panels to reserve any minimum height your layout needs.
Installation
Complete the shared installation. Copy Tabs.vue and index.ts into app/components/ui/tabs/.
<script setup lang="ts">
import { DateField as Primitive } from 'akaza-ui'
import { computed, nextTick, useAttrs, useTemplateRef } from 'vue'
import { cn, mergeRecipeSlots } from '../../../utils/ui'
import { calendarVariants } from '../calendar'
import uiConfig from '../ui.config'
import {
dateFieldVariants,
resolveDateFieldVariants,
type DateFieldProps,
type DateFieldSlots,
} from './index'
defineOptions({ inheritAttrs: false })
// Preserve Akaza defaults when optional props, including Boolean aliases, are omitted.
const props = withDefaults(defineProps<DateFieldProps>(), {
id: undefined,
name: undefined,
locale: undefined,
dir: undefined,
placeholder: undefined,
minValue: undefined,
maxValue: undefined,
isDateUnavailable: undefined,
required: undefined,
disabled: undefined,
readOnly: undefined,
invalid: undefined,
selectOnFocus: undefined,
autoAdvance: undefined,
showCalendar: true,
calendarLabel: undefined,
calendarSide: undefined,
calendarAlign: undefined,
calendarSideOffset: undefined,
calendarTeleport: 'body',
ariaLabel: undefined,
ariaLabelledby: undefined,
ariaDescribedby: undefined,
ui: undefined,
modelValue: undefined,
calendarOpen: undefined,
})
defineSlots<DateFieldSlots>()
const attrs = useAttrs()
const resolved = computed(() => resolveDateFieldVariants(props, uiConfig))
const styles = computed(() => dateFieldVariants(resolved.value))
const mergedUi = computed(() => {
const overrides = props.ui as Record<string, string | undefined> | undefined
const flat = Object.fromEntries(
Object.entries(styles.value)
.filter(([part]) => !['calendar'].includes(part))
.map(([part, style]) => [
part,
cn(style(), overrides?.[part], part === 'root' ? props.class : undefined),
]),
)
return {
...flat,
calendar: mergeRecipeSlots(calendarVariants({ size: resolved.value.size }), {
...props.ui?.calendar,
root: cn(styles.value.calendar(), props.ui?.calendar?.root),
}),
}
})
const primitiveProps = computed(() => {
const { class: _class, ui: _ui, size: _size, variant: _variant, ...native } = props
return native
})
const primitive = useTemplateRef<InstanceType<typeof Primitive>>('primitive')
async function onFieldClick(event: MouseEvent) {
const target = event.target as HTMLElement
if (
props.showCalendar &&
!props.disabled &&
!props.readOnly &&
target.closest('.akaza-date-field-segments')
) {
primitive.value?.openCalendar(event)
// Calendar initial focus belongs to its button; clicking a segment must keep typing focus.
await nextTick()
await nextTick()
target.focus({ preventScroll: true })
}
}
defineExpose({
get validationState() {
return primitive.value!.validationState
},
get clear() {
return primitive.value!.clear
},
get closeCalendar() {
return primitive.value!.closeCalendar
},
get focus() {
return primitive.value!.focus
},
get openCalendar() {
return primitive.value!.openCalendar
},
get setValue() {
return primitive.value!.setValue
},
get toggleCalendar() {
return primitive.value!.toggleCalendar
},
})
</script>
<template>
<component
:is="Primitive"
ref="primitive"
v-bind="{ ...primitiveProps, ...attrs }"
:ui="mergedUi"
@click="onFieldClick"
>
<template v-for="(_, name) in $slots" #[name]="scope"
><slot :name="name as keyof DateFieldSlots" v-bind="scope ?? {}"
/></template>
<template v-if="!$slots['calendar-trigger']" #calendar-trigger
><svg
class="size-4 shrink-0"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.75"
aria-hidden="true"
>
<path
d="M8 2v4m8-4v4M3 10h18M5 4h14a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2Z"
/></svg
></template>
</component>
</template>
API
Variants and defaults
| Prop | Values | Default |
|---|---|---|
size | xs, sm, md, lg, xl | sm |
variant | soft, line | soft |
Props
| Prop | Type | Default | Description |
|---|---|---|---|
items | TabsItem[] | โ | Required. List of tab items. |
modelValue | string | "" | Currently active tab value. |
orientation | "horizontal" | "vertical" | "horizontal" | Tab list direction. |
activationMode | "automatic" | "manual" | "automatic" | automatic: arrow keys activate. manual: arrow keys move focus only. |
unmountOnHide | boolean | false | Use v-if instead of v-show for inactive panels. |
ariaLabel | string | โ | aria-label for the tab list. |
labelKey | string | "label" | Property to use as label when items are objects. |
ui | TabsUi | โ | CSS class overrides. |
Slots
| Slot | Scoped props | Description |
|---|---|---|
tab | { item, isActive, select } | Each tab button. Defaults to rendering the item's label. |
panel-{value} | { item, isActive } | Content panel for the tab with the matching value. |
Events
| Event | Payload | Description |
|---|---|---|
value-change | [value: string, details] | Fired when selected tab changes. |
Keyboard
| Key | Behavior |
|---|---|
ArrowLeft / ArrowRight | Moves through enabled horizontal tabs and loops. |
ArrowUp / ArrowDown | Moves through enabled vertical tabs and loops. |
Home / End | Focuses first or last enabled tab. |
Enter / Space | Activates focused tab. Required in manual activation mode. |
Tab | Moves from active tab into active panel or next focusable control. |
Automatic mode activates during arrow movement. Manual mode moves focus only until activation.