Tabs
标签页

选项卡切换组件。

何时使用

提供平级的区域将大块内容进行收纳和展现,保持界面整洁。

Namu Design 依次提供了三级选项卡,分别用于不同的场景。

  • 卡片式的页签,提供可关闭的样式,常用于容器顶部。
  • 既可用于容器顶部,也可用于容器内部,是最通用的 Tabs。
  • Radio.Button 可作为更次级的页签来使用。

代码演示

Content of Tab Pane 1

默认选中第一项。

expand codeexpand code
Tab 1

禁用某一项。

expand codeexpand code
Content of Tab Pane 1

标签居中展示。

expand codeexpand code
Tab 2

有图标的标签。

expand codeexpand code
Content of tab 1

可以左右、上下滑动,容纳更多标签。

expand codeexpand code
Content of tab 1



You can also specify its direction or both side


Content of tab 1

可以在页签两边添加附加操作。

expand codeexpand code
Content of tab 1
Content of card tab 1

大号页签用在页头区域,小号用在弹出框等较狭窄的容器内。

expand codeexpand code
Tab position:
Content of Tab 1

有四个位置,tabPosition="left|right|top|bottom"。在移动端下,left|right 会自动切换成 top

expand codeexpand code
Content of Tab Pane 1

另一种样式的页签,不提供对应的垂直样式。

expand codeexpand code
Content of Tab 1

只有卡片样式的页签支持新增和关闭选项。使用 closable={false} 禁止关闭。

expand codeexpand code
Content of Tab Pane 1

隐藏默认的页签增加图标,给自定义触发器绑定事件。

expand codeexpand code
Content of Tab Pane 1

使用 react-sticky-boxrenderTabBar 实现吸顶效果。

expand codeexpand code
Content of Tab Pane 1

使用 dnd-kit 实现标签可拖拽。

expand codeexpand code

API

通用属性参考:通用属性

Tabs

参数说明类型默认值版本
activeKey当前激活 tab 面板的 keystring-
addIcon自定义添加按钮ReactNode-4.4.0
animated是否使用动画切换 Tabs`boolean| { inkBar: boolean, tabPane: boolean }{ inkBar: true, tabPane: false }
centered标签居中展示booleanfalse4.4.0
defaultActiveKey初始化选中面板的 key,如果没有设置 activeKeystring第一个面板
hideAdd是否隐藏加号图标,在 type="editable-card" 时有效booleanfalse
items配置选项卡内容TabItemType[]4.23.0
moreIcon自定义折叠 iconReactNode<EllipsisOutlined />4.14.0
popupClassName更多菜单的 classNamestring-4.21.0
renderTabBar替换 TabBar,用于二次封装标签头(props: DefaultTabBarProps, DefaultTabBar: React.ComponentClass) => React.ReactElement-
size大小,提供 large middlesmall 三种大小stringmiddle
tabBarExtraContenttab bar 上额外的元素ReactNode | {left?: ReactNode, right?: ReactNode}-object: 4.6.0
tabBarGuttertabs 之间的间隙number-
tabBarStyletab bar 的样式对象CSSProperties-
tabPosition页签位置,可选值有 top right bottom leftstringtop
destroyInactiveTabPane被隐藏时是否销毁 DOM 结构booleanfalse
type页签的基本样式,可选 linecard editable-card 类型stringline
onChange切换面板的回调function(activeKey) {}-
onEdit新增和删除页签的回调,在 type="editable-card" 时有效(action === 'add' ? event : targetKey, action): void-
onTabClicktab 被点击的回调function(key: string, event: MouseEvent)-
onTabScrolltab 滚动时触发function({ direction: left | right | top | bottom })-4.3.0

更多属性查看 rc-tabs tabs

TabItemType

参数说明类型默认值
closeIcon自定义关闭图标,在 type="editable-card" 时有效。5.7.0:设置为 nullfalse 时隐藏关闭按钮boolean | ReactNode-
disabled禁用某一项booleanfalse
forceRender被隐藏时是否渲染 DOM 结构booleanfalse
key对应 activeKeystring-
label选项卡头显示文字ReactNode-
children选项卡头显示内容ReactNode-

Design Token

组件 Token

全局 Token

  • Table表格Tag标签