MDUIDocs
Copy llms.txt linkCopy llms-full.txt linkView this page in MarkdownDiscuss this page with ChatGPTDiscuss full project docs with ChatGPT
Preset Colors
Custom Color
Extract from Wallpaper
Please select a wallpaper
Getting Started
AI-Assisted Development
Styles
Integration with Frameworks
Components
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
Functions
Libraries

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 lets you change the tab style.

Tab Placement

Use the placement attribute on the <mdui-tabs> component to set the tab positions.

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

Properties

AttributePropertyReflectTypeDefault
valuevaluestring-

Specifies the value of the tab panel.

Slots

Name
(default)

The content of the tab panel.

mdui-tab API

Properties

AttributePropertyReflectTypeDefault
valuevaluestring-

Specifies the tab value.

iconiconstring-

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

inlineinlinebooleanfalse

Arranges the icon and text horizontally.

autofocusautofocusbooleanfalse

Whether the element is focused when the page loads.

tabindextabIndexnumber-

The element's tab order when navigating with the Tab key.

Methods

NameParametersReturns
click
void

Simulates a mouse click on the element.

focus
  • options: FocusOptions (Optional)
void

Sets focus on the element. An optional object parameter may include 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.

Events

Name
focus

Emitted when the tab gains focus.

blur

Emitted when the tab loses focus.

Slots

Name
(default)

Tab text.

icon

Tab icon.

badge

Badge.

custom

Custom tab content.

CSS Parts

Name
container

Tab container.

icon

Tab icon.

label

Tab text.

mdui-tabs API

Properties

AttributePropertyReflectTypeDefault
variantvariant'primary' | 'secondary''primary'

Defines the tab variant. Possible values:

  • primary: Sits below <mdui-top-app-bar> and is used to switch between main application pages.
  • secondary: Sits within the page and is used to switch 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.
  • top: Top centered.
  • top-end: Top right.
  • bottom-start: Bottom left.
  • bottom: Bottom, centered.
  • bottom-end: Bottom right.
  • left-start: Left top.
  • left: Left, centered.
  • left-end: Left bottom.
  • right-start: Right top.
  • right: Right, centered.
  • right-end: Right bottom.
full-widthfullWidthbooleanfalse

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

Events

Name
change

Emitted when the selected value changes.

Slots

Name
(default)

<mdui-tab> elements.

panel

<mdui-tab-panel> elements.

CSS Parts

Name
container

Container for <mdui-tab> elements.

indicator

Indicator for the active state.

On this page