Tabs web component. Based heavily on the Tabs with Automatic Activation example from WAI-ARIA Authoring Practices
npm install @zachleat/seven-minute-tabs
- Code converted to be a web component.
- All styles have been removed and this component operates correctly without CSS. For longevity of the code all styling is left to independent project-specific themes.
- Progressively enhances from <a> with anchor links pointing to content panels.
- Adds
hiddenattribute to panels using JavaScript so that content still shows when JavaScript is not available. - Adds
tabindexusing JavaScript so that content remains accessibile without JavaScript. - Arrow key support. Adjusts for vertical
aria-orientationvalues. - Home/end key support.
- (Option to delete tabs was removed from the original example)
v3.0.3Addautoheightattribute to set a--smt-heightCSS Custom Property (maximum height across all tabs) to maintain a consistent component height when switching tabs (e.g.seven-minute-tabs [role="tabpanel"]) { min-height: var(--smt-height); })v3.0.1Addsyncattribute to activate all other matching tabs (in other tab groups) with the samedata-tab-persist="group:value".v3.0.0New tab selection persistence (viapersistattribute) logic withdata-tab-persist="group:value". Defaults tolocalStorage. Usepersist="session"forsessionStorage.v2.0.2Addpruneattribute option to remove buttons that don’t have a matching panel.v2.0.1Addpersistattribute option to persist selected tab to sessionStorage.v2.0.0Previous versions of this component required thearia-selected,aria-labelledby,aria-controls, and button/tabidattributes to exist in server rendered markup. If they don’t exist, they are now added automatically.