aforemny/material-components-web-elm/2.1.0

NOTE: the latest version is 9.1.0

Material.TabBar

Tabs organize and allow navigation between groups of content that are related and at the same level of hierarchy. The Tab Bar contains the Tab Scroller and Tab components.

Table of Contents

Resources

Basic Usage

import Material.TabBar
    exposing
        ( tab
        , tabBar
        , tabBarConfig
        , tabConfig
        )


type Msg
    = TabClicked Int


main =
    tabBar tabBarConfig
        [ tab
            { tabConfig
                | active = True
                , onClick = Just (TabClicked 0)
            }
            { label = "Tab 1", icon = Nothing }
        , tab
            { tabConfig
                | active = False
                , onClick = Just (TabClicked 1)
            }
            { label = "Tab 1", icon = Nothing }
        ]

Tab Bar

tabBar : TabBarConfig msg -> List (Tab msg) -> Html msg

Tab bar view function

tabBarConfig : TabBarConfig msg

Default configuration of a tab bar

type alias TabBarConfig msg =
{ stacked : Bool
, minWidth : Bool
, indicatorSpansContent : Bool
, additionalAttributes : List (Attribute msg)
, tabScrollerConfig : TabScrollerConfig msg
}

Configuration of a tab bar

Tabs

tab : TabConfig msg -> TabContent -> Tab msg

Tab constructor

tabConfig : TabConfig msg

Default configuration of a tab

type alias TabConfig msg =
{ active : Bool
, additionalAttributes : List (Attribute msg)
, onClick : Maybe msg
}

Configuration of a tab

type alias TabContent =
{ label : String
, icon : Maybe String
}

Content of a tab

type Tab msg

Tab

Stacked Tabs

In a stacked tab bar, the label and icon of a tab flow vertically instead of horizontally. To make a tab bar stacked, set its stacked configuration field to True.

Requires that the tabs have both label and icon.

    tabBar
        { tabBarConfig | stacked = True }
        [ tab tabConfig
        { label = "Favorites", icon = Just "favorite" }
        ]

Minimum Width Tabs

Tabs by defauls span a minimum width. If you want tabs to be as narrow as possible, set the tab bar's minWidth configuration field to True.

    tabBar
        { tabBarConfig | minWidth = True }
        [ tab tabConfig
            { label = "Favorites", icon = Nothing }
        ]

Content-Spanning Tab Indicator

The tab's active indicator by default spans the entire tab. If you want active indicators to only span their tab's content, set the tab bar's indicatorSpansContent configuration field to True.

    tabBar
        { tabBarConfig | indicatorSpansContent = True }
        [ tab tabConfig
            { label = "Favorites", icon = Nothing }
        ]

Tab scroller

The tab bar supports tabs overflowing its width and will enable scrolling in that case. You may change the alignment of the elements inside the scroll content.

type alias TabScrollerConfig msg =
{ align : Maybe TabScrollerAlign
, additionalAttributes : List (Attribute msg)
}

Configuration of a tab scroller

tabScrollerConfig : TabScrollerConfig msg

Default configuration of a tab scroller

= TabScrollerAlignStart
| TabScrollerAlignEnd
| TabScrollerAlignCenter

Alignment of a tab scroller

Center-aligned tab scroller

    tabBar
        { tabBarConfig
            | tabScrollerConfig =
              { tabScrollerConfig
                  | align =
                      Just TabBar.TabScrollerAlignCenter
              }
        }
        [ tab
            { tabConfig
                | active = True
                , onClick = Just (TabClicked 0)
            }
            { label = "Tab 1", icon = Nothing }
        , tab
            { tabConfig
                | active = False
                , onClick = Just (TabClicked 1)
            }
            { label = "Tab 1", icon = Nothing }
        ]