aforemny/material-components-web-elm/2.1.2

NOTE: the latest version is 9.1.0

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
, disabled : Bool
, required : Bool
, valid : Bool
, 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 "" ]
    ]

Required Select

To mark a select as required, set its required configuration field to True.

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

Disabled Option

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