Tabs
Related content, neatly organized. Full keyboard navigation included.
<div class="tabs">
<div><div>Overview</div><div><h3>One implementation. Every website.</h3><p>Use semantic content, shared design tokens, and small ES modules to build your next website.</p><a class="button-secondary" href="#get-started">Get started</a></div></div>
<div><div>Installation</div><div><h3>Copy. Customize. Ship.</h3><p>Install the source from the registry or copy the HTML, CSS, and JavaScript files. There is no framework to adopt.</p></div></div>
<div><div>Compatibility</div><div><h3>Native by design.</h3><p>Standalone verified, EDS markup compatible. Use your existing AEM loader when integrating into EDS.</p></div></div>
</div>.tabs [role="tablist"] { display: flex; gap: 0.3rem; padding: 0.3rem; background: var(--secondary); border-radius: var(--radius); overflow: auto; }
.tabs [role="tab"] { flex: 1; white-space: nowrap; padding: 0.6rem 1rem; border: 0; border-radius: calc(var(--radius) - 3px); background: transparent; color: var(--muted-foreground); font-size: 13px; }
.tabs [aria-selected="true"] { background: var(--background); color: var(--foreground); box-shadow: var(--shadow); }
.tabs [role="tabpanel"] { padding: 1.5rem 0; }export default function decorate(block) {
if (block.querySelector('[role="tablist"]')) return;
const rows = [...block.children].filter((row) => row.children.length >= 2);
if (!rows.length) return;
const list = document.createElement('div');
list.setAttribute('role', 'tablist');
list.setAttribute('aria-label', block.dataset.label || 'Content');
const uid = `tabs-${crypto.randomUUID()}`;
const buttons = [];
const panels = [];
rows.forEach((row, index) => {
const [label, panel] = row.children;
const button = document.createElement('button');
button.type = 'button';
button.textContent = label.textContent;
button.id = `${uid}-tab-${index}`;
button.setAttribute('role', 'tab');
button.setAttribute('aria-controls', `${uid}-panel-${index}`);
panel.id = `${uid}-panel-${index}`;
panel.setAttribute('role', 'tabpanel');
panel.setAttribute('aria-labelledby', button.id);
panel.tabIndex = 0;
buttons.push(button);
panels.push(panel);
list.append(button);
});
function activate(index, focus = false) {
buttons.forEach((button, i) => {
button.setAttribute('aria-selected', String(i === index));
button.tabIndex = i === index ? 0 : -1;
panels[i].hidden = i !== index;
});
if (focus) buttons[index].focus();
}
const onClick = (event) => {
const index = buttons.indexOf(event.target.closest('button'));
if (index >= 0) activate(index);
};
const onKey = (event) => {
const index = buttons.indexOf(event.target);
if (index < 0 || !['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(event.key)) return;
event.preventDefault();
const next = event.key === 'Home' ? 0 : event.key === 'End' ? buttons.length - 1 : (index + (event.key === 'ArrowRight' ? 1 : -1) + buttons.length) % buttons.length;
activate(next, true);
};
list.addEventListener('click', onClick);
list.addEventListener('keydown', onKey);
block.replaceChildren(list, ...panels);
activate(0);
return () => {
list.removeEventListener('click', onClick);
list.removeEventListener('keydown', onKey);
block.replaceChildren(...rows.map((row, index) => {
const label = document.createElement('div');
label.textContent = buttons[index].textContent;
const panel = panels[index];
panel.hidden = false;
['id', 'role', 'aria-labelledby', 'tabindex'].forEach((attribute) => panel.removeAttribute(attribute));
row.replaceChildren(label, panel);
return row;
}));
};
}Installation
Run the source CLI from a Blocks UI checkout. This package is not published to npm.
node packages/cli/index.js add tabsOr copy the source files above. Include tokens.css and base.css once in your project.
Usage
Use the authored row-and-column structure, then let the standalone runtime discover and enhance the block.
<div class="tabs">
<div><div>Overview</div><div><h3>One implementation. Every website.</h3><p>Use semantic content, shared design tokens, and small ES modules to build your next website.</p><a class="button-secondary" href="#get-started">Get started</a></div></div>
<div><div>Installation</div><div><h3>Copy. Customize. Ship.</h3><p>Install the source from the registry or copy the HTML, CSS, and JavaScript files. There is no framework to adopt.</p></div></div>
<div><div>Compatibility</div><div><h3>Native by design.</h3><p>Standalone verified, EDS markup compatible. Use your existing AEM loader when integrating into EDS.</p></div></div>
</div>import decorate from './blocks/tabs/tabs.js';
document.querySelectorAll('.tabs').forEach(decorate);Variants
Choose a variant in the live preview. Add its class to the authored block.
defaultAccessibility & behavior
Use Left and Right Arrow to move between tabs. Home and End reach the first and last tab. Each panel is linked to its tab and hidden when inactive.
Multiple instances are supported. Layouts adapt to smaller viewports. No npm dependencies are required at runtime.
AEM usage
Copy the canonical CSS and JavaScript into your EDS block folder. Use the same row-and-column authoring structure shown above and let your existing AEM loader call the default decorator.
Standalone verified. EDS markup compatible. Live AEM integration has not been verified.