Skip to content

Tabs

Tabs organize content into distinct panels, displayed one at a time.

Demo

tabs.html
<div x-init x-tabs>
<div x-tabs:list>
<button x-tabs:tab="accordion">Accordion</button>
<button x-tabs:tab="dialog">Dialog</button>
<button x-tabs:tab="flyout">Flyout</button>
</div>
<div x-tabs:panel="accordion">
An accordion is a vertical list of headers that reveal or hide content
sections when clicked.
</div>
<div x-tabs:panel="dialog" x-cloak>
A dialog creates a window overlaid on top of a page window, rendering the
content underneath inert.
</div>
<div x-tabs:panel="flyout" x-cloak>
A flyout displays content in an overlay, triggered by a button.
</div>
</div>

Features

  • Full keyboard navigation
  • Supports horizontal orientation
  • Supports manual/automatic activation
  • Can set default displayed tab

Anatomy

<div x-init x-tabs>
<div x-tabs:list>
<button x-tabs:tab></button>
</div>
<div x-tabs:panel></div>
</div>

Directives

x-tabs

Required

The root element for tabs.

Value
The default tab to be displayed. Otherwise, display the first tab.
EventDescriptiondetail
tabs:changeThe tab that is opened{ tab: string }

x-tabs:list

Required

List of tabs.

ModifierDescription
.loopLoops keyboard navigation (e.g. arrow keys)
.automaticAutomatically show/hide panel with keyboard navigation (e.g. arrow keys)
.vertical | .horizontalOrientation of the accordion for keyboard navigation. Defaults to .horizontal.
EventDescriptiondetail
tabs:changeThe tab that is opened{ tab: string }

x-tabs:tab

Required

Trigger button that shows the corresponding panel.

Value
The value for this tab
EventDescriptiondetail
tabs:changeWhether the tab is open or closed{ open: boolean }
Data AttributeValues
[data-state]active | inactive

x-tabs:panel

Required

Panel that contains content.

Value
The value for this panel, which should match the correct tab.
EventDescriptiondetail
tabs:changeWhether the panel is open or closed{ open: boolean }
Data AttributeValues
[data-state]active | inactive