aforemny/material-components-web-elm/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

Material.Select

MDC Select provides Material Design single-option select menus. It supports using the browser's native <select> element, or a MDC Menu. It is fully accessible, and fully RTL-aware.

Table of Contents

Resources

Basic Usage

import Material.Select
    exposing
        ( select
        , selectConfig
        , selectOption
        , selectOptionConfig
        )


type Msg
    = ValueChanged String


main =
    filledSelect
        { selectConfig
            | label = "Fruit"
            , value = Just ""
            , onChange = Just ValueChanged
        }
        [ selectOption
            { selectOptionConfig | value = "" }
            [ text "" ]
        , selectOption
            { selectOptionConfig | value = "Apple" }
            [ text "Apple" ]
        ]
filledSelect : SelectConfig msg -> List (SelectOption msg) -> Html msg

Filled select view function

selectConfig : SelectConfig msg

Default configuration of a select

type alias SelectConfig msg =
{ label : String
, value : Maybe String
, additionalAttributes : List (Attribute msg)
, onChange : Maybe (String -> msg)
}

Configuration of a select

selectOption : SelectOptionConfig msg -> List (Html msg) -> SelectOption msg

Select option view function

selectOptionConfig : SelectOptionConfig msg

Default configuration of a select option

type alias SelectOptionConfig msg =
{ disabled : Bool
, value : String
, additionalAttributes : List (Attribute msg)
}

Configuration of a select option

type SelectOption msg

Select option type

Outlined select

Instead of a filled select, you may choose a select with a outline by using the outlinedSelect view function.

outlinedSelect selectConf
    [ selectOption selectOptionConf "" ]
outlinedSelect : SelectConfig msg -> List (SelectOption msg) -> Html msg

Outlined select view function

Disabled select

To disable a select, set its disabled configuration field to True.

filledSelect
    { selectConfig | disabled = True }
    [ selectOption { selectOptionConfig | value = "" }
        [ text "" ]
    ]

Disabled options

To disable one select's option, set its disabled configuration field to True.

selectOption { selectOptionConfig | disabled = True }
    [ text "" ]

This is particularly useful on the first emply option if you have a select that must be filled but is not initially filled.

Select with helper text

TODO

Select with leading icon

TODO