MDUI文档
预设颜色
自选颜色
从壁纸提取颜色
请选择一张壁纸
开发指南
样式
与框架集成
组件
Avatar 头像Badge 徽标BottomAppBar 底部应用栏Button 按钮ButtonIcon 图标按钮Card 卡片Checkbox 复选框Chip 纸片CircularProgress 圆形进度指示器Collapse 折叠面板Dialog 对话框Divider 分割线Dropdown 下拉组件Fab 浮动操作按钮Icon 图标Layout 布局LinearProgress 线性进度指示器List 列表Menu 菜单NavigationBar 底部导航栏NavigationDrawer 侧边抽屉栏NavigationRail 侧边导航栏Radio 单选框RangeSlider 范围滑块Select 选择框SegmentedButton 分段按钮Slider 滑块Snackbar 消息条Switch 开关切换Tabs 选项卡TextField 文本框Tooltip 工具提示TopAppBar 顶部应用栏
工具函数
独立包

Tabs 选项卡

Tabs organize content across different screens and views.

Usage

Import the component:

import 'mdui/components/tabs.js';
import 'mdui/components/tab.js';
import 'mdui/components/tab-panel.js';

Import the TypeScript type:

import type { Tabs } from 'mdui/components/tabs.js';
import type { Tab } from 'mdui/components/tab.js';
import type { TabPanel } from 'mdui/components/tab-panel.js';

Example:

Tab 1 Tab 2 Tab 3 Panel 1 Panel 2 Panel 3
<mdui-tabs value="tab-1">
  <mdui-tab value="tab-1">Tab 1</mdui-tab>
  <mdui-tab value="tab-2">Tab 2</mdui-tab>
  <mdui-tab value="tab-3">Tab 3</mdui-tab>

  <mdui-tab-panel slot="panel" value="tab-1">Panel 1</mdui-tab-panel>
  <mdui-tab-panel slot="panel" value="tab-2">Panel 2</mdui-tab-panel>
  <mdui-tab-panel slot="panel" value="tab-3">Panel 3</mdui-tab-panel>
</mdui-tabs>

Examples

Variant

The variant attribute on the <mdui-tabs> component allows you to set the style of the tabs.

Tab Placement

The placement attribute on the <mdui-tabs> component allows you to set the position of the tabs.

Full Width

To make the tabs occupy the entire width and be evenly distributed, add the full-width attribute to the <mdui-tabs> component.

Icons

Add Material Icons to the tabs by setting the icon attribute on the <mdui-tab> component. Alternatively, use the icon slot to add icon elements.

Arrange the icon and text horizontally by adding the inline attribute.

Badge

Add a badge to the <mdui-tab> component using the badge slot.

Custom Content

Use the custom slot in the <mdui-tab> component to fully customize the content of the tabs.

mdui-tab-panel API

属性

HTML 属性JavaScript 属性Reflect类型默认值
valuevaluestring-

Specifies the value of the tab panel.

Slots

名称
默认

The content of the tab panel.

mdui-tab API

属性

HTML 属性JavaScript 属性Reflect类型默认值
valuevaluestring-

Specifies the tab value.

iconiconstring-

Specifies the Material Icons name. Alternatively, use slot="icon".

inlineinlinebooleanfalse

Arranges the icon and text horizontally.

autofocusautofocusbooleanfalse

Determines if the element should be focused when the page loads.

tabindextabIndexnumber-

Specifies the order in which the element receives focus when navigating with the Tab key.

方法

名称参数返回值
click
void

Simulates a mouse click on the element.

focus
  • options: FocusOptions (可选)
void

Sets focus on the element. An optional parameter can be an object with a preventScroll property. If preventScroll is set to true, the page will not scroll to bring the focused element into view.

blur
void

Removes focus from the element.

事件

名称
focus

Emitted when the tab gains focus.

blur

Emitted when the tab loses focus.

Slots

名称
默认

Tab text.

icon

Tab icon.

badge

Badge.

custom

Custom tab content.

CSS Parts

名称
container

Tab container.

icon

Tab icon.

label

Tab text.

mdui-tabs API

属性

HTML 属性JavaScript 属性Reflect类型默认值
variantvariant'primary' | 'secondary''primary'

Defines the tab shape. Possible values:

  • primary: Located below <mdui-top-app-bar>, used for switching between main application pages.
  • secondary: Located within the page, used for switching between related content groups.
valuevaluestring-

Specifies the active <mdui-tab> value.

placementplacement'top-start' | 'top' | 'top-end' | 'bottom-start' | 'bottom' | 'bottom-end' | 'left-start' | 'left' | 'left-end' | 'right-start' | 'right' | 'right-end''top-start'

Defines the tab position. Default is top-start. Possible values:

  • top-start: Top, left-aligned.
  • top: Top, center-aligned.
  • top-end: Top, right-aligned.
  • bottom-start: Bottom, left-aligned.
  • bottom: Bottom, center-aligned.
  • bottom-end: Bottom, right-aligned.
  • left-start: Left, top-aligned.
  • left: Left, center-aligned.
  • left-end: Left, bottom-aligned.
  • right-start: Right, top-aligned.
  • right: Right, center-aligned.
  • right-end: Right, bottom-aligned.
full-widthfullWidthbooleanfalse

If set, the tabs will fill the width of its parent element.

事件

名称
change

Emitted when the selected value changes.

Slots

名称
默认

<mdui-tab> elements.

panel

<mdui-tab-panel> elements.

CSS Parts

名称
container

Container for <mdui-tab> elements.

indicator

Indicator for the active state.

本页目录