mica
mica

Examples

Default

Account settings panel.

Password panel. Try the arrow keys — roving tabindex, automatic activation.

Team panel.

Underline

Overall leaders.

Attacking leaders.

Passing leaders.

Defending leaders.

Goalkeeping leaders.

Basic usage

<m-tabs variant="underline">
  <nav aria-label="Leader category">
    <button>Overall</button>
    <button selected>Attacking</button> <!-- optional initial -->
  </nav>
  <section>&#8230;overall panel&#8230;</section>
  <section>&#8230;attacking panel&#8230;</section>
</m-tabs>

<script type="module" src="mica/tabs.js"></script>

API

Attributes

NameTypeDefaultDescription
variantunderlinesegmentedUses the quieter underline treatment without changing behavior.
selectedboolean on a tab buttonfirst tabChooses the optional initial tab before enhancement.
aria-controlspanel IDpositional pairingExplicitly pairs a button with a panel.

Content/markup contract

PartContractDefaultDescription
navdirect childrequiredContains tab buttons.
buttoninside navrequiredPairs positionally with a direct panel unless aria-controls names one.
sectiondirect childrequiredPanel content. Keep all content complete and readable without enhancement.

tabs.js

Optional enhancement that registers m-tabs. It wires tablist, tab, and tabpanel roles; aria-selected; roving tabindex; Arrow Left/Right, Home, and End keys with automatic activation; selected-tab reveal; and position-aware overflow markers.

<script type="module" src="mica/tabs.js"></script>

Without the module, the nav is inert and every panel renders in order: complete, readable content rather than a CSS-only fake.

Script interface

NameTypeDescription
m-on-changeevent, bubblesFires when the user selects a different tab by click or key. detail.index is the new tab's position. Other components fire their own m-on-change (a combobox in a panel, nested tabs), so check event.target is your tabs element.
selectedIndexread-only numberPosition of the selected tab, or -1 before enhancement.
select(index)methodSelects a tab from script. Silent: it fires no m-on-change, like setting a native value. An index with no tab is ignored.

Tabs and panels may be added or removed after enhancement, for example by a framework or a server fragment. The element rescans and keeps the current selection; changes inside a panel don't trigger a rescan. If the selected tab is removed, the element falls back to the first tab without an event: the script that removed it picks the next selection.

Accessibility

The module establishes native ARIA tabs semantics, labels each panel from its button, makes panels focusable, and manages keyboard focus and selection. The unenhanced fallback exposes every panel in document order.

Horizontal overflow

Tab labels never wrap. When the rail is narrower than its tabs, the nav scrolls horizontally with contained overscroll. With tabs.js, a direction marker fades in only on a side with more tabs, selecting a partially visible tab brings it fully into view, and an initial selected tab past the edge is scrolled into view on load. The scrollbar stays hidden, but touch, wheel, and keyboard scrolling still work.

The rail is constrained to 20rem; tabs keep their intrinsic width and overflow scrolls.

Attacking leaders.

Passing leaders.

Defending leaders.

Goalkeeping leaders.

Use tabs for in-page panels. Route navigation and deep links should remain ordinary anchors outside m-tabs, so URLs, open-in-new-tab behavior, and routing stay consumer-owned.

← toastcombobox →