1.0.0 • Published 4 years ago

@miraidesigns/tabs v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

Tabs

Tabs allow you to organize content into different panels or screens.


HTML

<div class="mdf-tabs">
    <div class="mdf-tabs__bar">
        <button class="mdf-tabs__tab mdf-tabs__tab--selected" role="tab" aria-selected="true">
            <span class="mdf-tabs__content">
                <span class="mdf-tabs__text">Tab 1</span>
            </span>

            <span class="mdf-tabs__selection"></span>
        </button>

        <button class="mdf-tabs__tab" role="tab" aria-selected="false" tabindex="-1">
            <span class="mdf-tabs__content">
                <span class="mdf-tabs__text">Tab 2</span>
            </span>

            <span class="mdf-tabs__selection"></span>
        </button>

        <button class="mdf-tabs__tab" role="tab" aria-selected="false" tabindex="-1">
            <span class="mdf-tabs__content">
                <span class="mdf-tabs__text">Tab 3</span>
            </span>

            <span class="mdf-tabs__selection"></span>
        </button>
    </div>

    <div class="mdf-tabs__panels">
        <div class="mdf-tabs__panel mdf-tabs__panel--active" role="tabpanel" tabindex="0">
            Panel 1
        </div>

        <div class="mdf-tabs__panel" role="tabpanel" tabindex="0">
            Panel 2
        </div>

        <div class="mdf-tabs__panel" role="tabpanel" tabindex="0">
            Panel 3
        </div>
    </div>
</div>

Sass

// Include default styles without configuration
@forward '@miraidesigns/tabs/styles';
// Configure appearance
@use '@miraidesigns/tabs' with (
    $variable: value
);

@include tabs.styles();

TypeScript

import { MDFTabs } from '@miraidesigns/tabs';

new MDFTabs(document.querySelector('.mdf-tabs'));

Implementation

Attributes

Please see the WAI-ARIA page for attributes and best practices regarding tabs.

Classes

NameTypeDescription
mdf-tabsParentContains the tabs elements
mdf-tabs__barParent / ChildHorizontal grid containing the tabs. Child to .mdf-tabs
mdf-tabs__bar--leftModifierMove the tabs to the left of the grid
mdf-tabs__bar--rightModifierMove the tabs to the right of the grid
mdf-tabs__bar--stretchedModifierEvenly stretch the tabs across the entire container width
mdf-tabs__tabParent / ChildContains the tab content. Child to .mdf-tabs__bar
mdf-tabs__tab--selectedModifierSet tab as selected
mdf-tabs__tab--stackedModifierMoves the icon on top of the text
mdf-tabs__contentParent / ChildContains the tab text, icon and selection bar. Child to .mdf-tabs__tab
mdf-tabs__textChildTab text description. Child to .mdf-tabs__content
mdf-tabs__selectionChildSelection bar, shows active tab. Child to .mdf-tabs__content
mdf-tabs__panelsParent / ChildContains the tab panel elements. Child to .mdf-tabs
mdf-tabs__panelChildTab panel element. Child to .mdf-tabs__panels
mdf-tabs__panel--activeChildSet panel as active

Events

NameDataDescription
MDFTabs:changed{index: number, tab: HTMLElement, panel: HTMLElement}Fires whenever the active tab changes. Includes the current index, tab and panel element

Properties

NameTypeDescription
.containerHTMLElementReturns the container element
.panelsHTMLElement[]Returns an Array holding all panel elements
.tabsHTMLElement[]Returns an Array holding all tabs elements