The tabbed user interface enables users to jump to their target section quickly. Tabs present like logically group information on the same page. Information should
Users should not need to see content of multiple tabs simultaneously and the user should be able to easily recognise where they are within the content.
The tab module is untested, but contains a modularized version of the jQuery code, so that it can be called on demand. It is what is used in the design system so that the JavaScript can be called at run time (after loading content).
...
.tab-group { margin: 2rem 0 1rem 0; } .tab-group > ul { display: -webkit-box; display: -ms-flexbox; display: flex; margin: 0; padding: 0; } .tab-group > ul li.separator { border-bottom: 1px solid var(--color-grey); border-left: 1px solid var(--color-grey); display: inline-block; margin: 0.45rem 0 0 0; width: 100%; } .tab-group .tab-hidden { display: none; } .tab-group [role=tab] { background-color: var(--color-white); border-left: 1px solid var(--color-grey); border-top: 1px solid var(--color-grey); border-radius: 0.5rem 0.5rem 0 0; margin: 0; display: inline; padding: 1rem 1.5rem 0.14rem 1.5rem; z-index: 2; } .tab-group [role=tab]:last-of-type { border-right: 1px solid var(--color-grey); } .tab-group [role=tab]:not(.selected) { background-color: var(--color-grey-xxl); border-bottom: 1px solid var(--color-grey); } .tab-group [role=tab] span { display: block; margin: 0 0 0.5rem 0; } .tab-group [role=tabpanel] { background-color: var(--color-white); border: 1px solid var(--color-grey); border-top: none; padding: 1rem; z-index: 1; } .tab-group [role=tabpanel]:not(.open) { display: none; }
@mixin tabs { .tab-group { margin: 2rem 0 1rem 0; > ul { display: flex; margin: 0; padding: 0; li.separator { border-bottom: 1px solid var(--color-grey); border-left: 1px solid var(--color-grey); display: inline-block; margin: .45rem 0 0 0; width: 100%; } } .tab-hidden { display: none; } [role="tab"] { background-color: var(--color-white); border-left: 1px solid var(--color-grey); border-top: 1px solid var(--color-grey); border-radius: .5rem .5rem 0 0; margin: 0; display: inline; padding: 1rem 1.5rem .14rem 1.5rem; z-index: 2; &:last-of-type { border-right: 1px solid var(--color-grey); } &:not(.selected) { background-color: var(--color-grey-xxl); border-bottom: 1px solid var(--color-grey); } span { display: block; margin: 0 0 .5rem 0; } } [role="tabpanel"] { background-color: var(--color-white); border: 1px solid var(--color-grey); border-top: none; padding: 1rem; z-index: 1; &:not(.open) { display: none; } @content; } } }
export function tabs($) { $(".tab-group").each(function(){ let tabgroup = $(this).attr("id"), tablist = ""; $(this).children("*").each(function(){ let tab = $(this).attr("data-tab"); if (typeof tab !== 'undefined' && tab !== false) { let tabID = tab.replace(/\W+/g,"-").toLowerCase(); $(this).wrap(``); tablist += `