Tabs

July 31, 2019 ยท View on GitHub

Displays a tab row of navigation buttons.

Main features

  • Use text, icon, or combination
  • Automatically fit display
  • Centered display
  • Compact display
  • Make all tabs as wide as the widest tab
  • Hide tab indicator
  • Remove indicator slide effect
  • Custom button behaviour
  • Scrollable
  • Custom scroll buttons
  • Display tabs as mobile navigation menu

Usage

Options

Tabs options

ParameterRequiredTypeDefaultDescription
activeSelectedoptionalBooleanfalseSet to true to enable clicks/taps on the selected tab button
alloptionalOptions ObjectTab button options that will be applied to all tabs, see "Tab button options" below
autofitoptionalBooleanfalseSet to true to let the buttons fill the entire button row
centeredoptionalBooleanfalseSet to true to center the button row; this automatically sets autofit to false
hideIndicatoroptionalBooleanfalseSet to true to hide the "current tab" indicator
largestWidthoptionalBooleanfalseSet to true to give all tabs the width of the largest tab
menuoptionalBooleanfalseSet to true to make the tabs behave like a mobile navigation menu; this removes the minimum width settings from the tab buttons and compresses padding and label font size
noIndicatorSlideoptionalBooleanfalseSet to true not let the "current tab" indicator slide to the new position
onChangeoptionalFunction ({ index: number, options: TabButtonOptions, el: HTMLElement }) => undefinedCallback function that receives the tabs state
scrollableoptionalBooleanfalseSet to true to make the button row scrollable; this automatically sets autofit to false; on non-touch devices, 2 scroll buttons will be added to navigate tabs
scrollIconBackwardoptionalIcon options objectOverrides default arrow icon
scrollIconForwardoptionalIcon options objectOverrides default arrow icon
selectedTabIndexoptionalNumber0The Array index of the selected tab. Overridden when one of the tabs has option selected.
smalloptionalBooleanfalseSet to true to reduce the tab widths on larger screens
tabsuse content or tabsArray of tab button option objectsButton row content

Tab button options

Tab buttons use the same parameters as button, except for wash (disabled), raised and shadowDepth (makes visually no difference).

These options can be grouped into tabsOpts and applied to all tabs.

ParameterRequiredTypeDefaultDescription
classNameoptionalStringExtra CSS class appended to "pe-button pe-tabs__tab"
disabledoptionalBooleanfalseDisables the button
elementoptionalString"a" (if url is passed) or "div"HTML element tag
eventsoptionalObjectButton events; options object containing one or more events like onclick
inkoptionalBooleantrueSet to false to disable the ripple effect on click/tap
labelrequiredStringThe button label
selectedoptionalBooleanfalseSet to true to show the button as selected
urloptionalObject with href, optionally oncreate (for Mithril 1.x) or onClick (for React) or to (for React Router)URL location; Mithril 2.x: for in-app route linking set only use url.href and set element to m.route.Link; Mithril 1.x: for in-app route linking set oncreate : m.route.link; React: for in-app route linking use onClick and a router such as react-router-dom

Common component options

ParameterRequiredTypeDefaultDescription
afteroptionalString, hyperscript or componentExtra content after main content; note that this content is placed right of preceding elements with a higher stacking depth
beforeoptionalString, hyperscript or componentExtra content before main content; note that this content is placed left of subsequent elements with a lower stacking depth
classNameoptionalStringExtra CSS class appended to pe-tabs
contentuse content or tabsArray of option objectsButton row content
elementoptionalString"div"HTML element tag
idoptionalStringHTML element id
styleoptionalObjectFor setting simple style attributes
toneoptionalString: "dark" or "light"Renders the component light on dark (sets class pe-dark-tone); use "light" to locally inverse (sets class pe-light-tone)

Composition

Tabs is composed from:

Tabs sometimes uses:

  • Icon (when icon is passed instead of label)

CSS classes