x-tabs is a tab system container that coordinates multiple x-tab triggers and their associated tab panels.
It manages:
x-tabs complements x-tab and provides the coordination layer for a full tab interface.
import { init } from "@vanelsas/baredom/x-tabs";
init();
<x-tabs>
<x-tab value="overview" controls="panel-overview">Overview</x-tab>
<x-tab value="analytics" controls="panel-analytics">Analytics</x-tab>
<x-tab value="reports" controls="panel-reports">Reports</x-tab>
</x-tabs>
<section id="panel-overview">Overview content</section>
<section id="panel-analytics" hidden>Analytics content</section>
<section id="panel-reports" hidden>Reports content</section>
x-tabs will automatically:
value names, or else the first enabled tab marked selected, or else the first enabled tab| Attribute | Type | Default | Description |
|---|---|---|---|
value | string | — | The selected tab. x-tabs writes it only after an accepted value-change-request |
orientation | horizontal | vertical | horizontal |
activation | auto | manual | auto |
label | string | — | Accessible label |
loop | boolean | false | Enables keyboard wrap navigation |
| Property | Type | Description |
|---|---|---|
value | string | Reflects value. null until the page sets it or a request is accepted |
orientation | string | Reflects orientation, default "horizontal" |
activation | string | Reflects activation, default "auto" |
label | string | Reflects label, default "" |
loop | boolean | Reflects loop |
Example:
tabs.value = "analytics";
Fired before the selected tab changes. Cancelable — call event.preventDefault() to block the tab switch (controlled mode).
tabs.addEventListener("value-change-request", event => {
console.log(event.detail.value); // proposed new tab
console.log(event.detail.previousValue); // current tab
event.preventDefault(); // block the switch
});
Event detail:
{
value: string,
previousValue: string
}
Fired after an accepted value-change-request. A move of the shown tab without value (a tab removed or disabled) sends none.
tabs.addEventListener("value-change", event => {
console.log(event.detail.value);
});
Event detail:
{
value: string
}
Keyboard behavior follows the WAI-ARIA tab pattern.
| Key | Action |
|---|---|
| ArrowRight | Next tab |
| ArrowLeft | Previous tab |
| Key | Action |
|---|---|
| ArrowDown | Next tab |
| ArrowUp | Previous tab |
| Key | Action |
|---|---|
| Home | First enabled tab |
| End | Last enabled tab |
Selecting a tab occurs immediately during keyboard navigation.
Arrow keys move focus only. Selection occurs when pressing:
Disabled tabs:
Panels are associated using the controls attribute on x-tab.
Example:
<x-tab value="analytics" controls="panel-analytics">
The container will automatically:
hidden attribute| Node | Attribute | When |
|---|---|---|
each x-tab child | selected | the selection or the tabs change |
the panel a tab names in controls | hidden | the selection or the tabs change |
x-tabs owns these. With a value, it marks the tab that value names and replaces any other mark. Without a value, the marks hold the selection: x-tabs keeps one enabled tab marked, the first marked one or else the first one. So the selection moves when that tab is removed or disabled, and stays where it moved. Set value to pin it.
x-tabs is intentionally lightweight.
Most visual styling is handled by x-tab.
--x-tabs-gap
| Part | Description |
|---|---|
base | Internal container |
x-tabs coordinates the tablist pattern.
| Element | Role |
|---|---|
| internal base | tablist |
| x-tab | tab |
| associated panels | tabpanel (user supplied) |
The component:
x-tabs introduces minimal or no motion.
Any transitions respect:
prefers-reduced-motion
<x-tabs activation="auto">
<x-tab value="overview" controls="p1">Overview</x-tab>
<x-tab value="analytics" controls="p2">Analytics</x-tab>
<x-tab value="reports" controls="p3">Reports</x-tab>
</x-tabs>
<section id="p1">Overview content</section>
<section id="p2" hidden>Analytics content</section>
<section id="p3" hidden>Reports content</section>
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |