选项卡
Make changes to your account here. Click save when you're done.
特性
- 支持受控与非受控模式
- 支持水平/垂直方向
- 支持自动/手动激活
- 完整键盘导航支持
安装
通过命令行安装该组件。
$ npm add reka-ui结构
导入所有部件并组合使用。
<script setup>
import { TabsContent, TabsIndicator, TabsList, TabsRoot, TabsTrigger } from 'reka-ui'
</script>
<template>
<TabsRoot>
<TabsList>
<TabsIndicator />
<TabsTrigger />
</TabsList>
<TabsContent />
</TabsRoot>
</template>API 参考
Root
包含所有选项卡组件部件。
| Prop | Default | Type |
|---|---|---|
activationMode | 'automatic' | 'automatic' | 'manual'Whether a tab is activated automatically (on focus) or manually (on click). |
as | 'div' | AsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | |
defaultValue | string | numberThe value of the tab that should be active when initially rendered. Use when you do not need to control the state of the tabs | |
dir | 'ltr' | 'rtl'The reading direction of the combobox when applicable. | |
modelValue | string | numberThe controlled value of the tab to activate. Can be bind as | |
orientation | 'horizontal' | 'vertical' | 'horizontal'The orientation the tabs are laid out. Mainly so arrow navigation is done accordingly (left & right vs. up & down) |
unmountOnHide | true | booleanWhen |
| Emit | Payload |
|---|---|
update:modelValue | [payload: StringOrNumber]Event handler called when the value changes |
| Slots (default) | Payload |
|---|---|
modelValue | string | numberCurrent input values |
| Data Attribute | Value |
|---|---|
[data-orientation] | "vertical" | "horizontal" |
List
包含与活动内容边缘对齐的触发器集合。
| Prop | Default | Type |
|---|---|---|
as | 'div' | AsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | |
loop | true | booleanWhen |
| Data Attribute | Value |
|---|---|
[data-orientation] | "vertical" | "horizontal" |
Trigger
激活其关联内容的按钮。
| Prop | Default | Type |
|---|---|---|
as | 'button' | AsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | |
disabled | false | booleanWhen |
value* | string | numberA unique value that associates the trigger with a content. |
| Data Attribute | Value |
|---|---|
[data-state] | "active" | "inactive" |
[data-disabled] | 禁用时呈现 |
[data-orientation] | "vertical" | "horizontal" |
Indicator
高亮当前活动选项卡的指示器。
| Prop | Default | Type |
|---|---|---|
as | 'div' | AsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. |
| CSS Variable | Description |
|---|---|
--reka-tabs-indicator-size | 指示器的尺寸 |
--reka-tabs-indicator-position | 指示器的位置 |
Content
包含与每个触发器关联的内容。
| Prop | Default | Type |
|---|---|---|
as | 'div' | AsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | |
forceMount | booleanUsed to force mounting when more control is needed. Useful when controlling animation with Vue animation libraries. | |
value* | string | numberA unique value that associates the content with a trigger. |
| Data Attribute | Value |
|---|---|
[data-state] | "active" | "inactive" |
[data-orientation] | "vertical" | "horizontal" |
示例
垂直布局
通过使用 orientation 属性可创建垂直选项卡。
<script setup>
import { TabsContent, TabsList, TabsRoot, TabsTrigger } from 'reka-ui'
</script>
<template>
<TabsRoot
default-value="tab1"
orientation="vertical"
>
<TabsList aria-label="选项卡示例">
<TabsTrigger value="tab1">
第一项
</TabsTrigger>
<TabsTrigger value="tab2">
第二项
</TabsTrigger>
<TabsTrigger value="tab3">
第三项
</TabsTrigger>
</TabsList>
<TabsContent value="tab1">
第一个选项卡内容
</TabsContent>
<TabsContent value="tab2">
第二个选项卡内容
</TabsContent>
<TabsContent value="tab3">
第三个选项卡内容
</TabsContent>
</TabsRoot>
</template>无障碍访问
键盘交互
| Key | Description |
|---|---|
Tab | 焦点移入选项卡时,聚焦活动触发器。当触发器获得焦点时,将焦点移至活动内容 |
ArrowDown | 根据 orientation 将焦点移至下一个触发器并激活其关联内容 |
ArrowRight | 根据 orientation 将焦点移至下一个触发器并激活其关联内容 |
ArrowUp | 根据 orientation 将焦点移至上一个触发器并激活其关联内容 |
ArrowLeft | 根据 orientation 将焦点移至上一个触发器并激活其关联内容 |
Home | 将焦点移至第一个触发器并激活其关联内容 |
End | 将焦点移至最后一个触发器并激活其关联内容 |
