aforemny/material-components-web-elm/3.0.0

NOTE: the latest version is 9.1.0

Material.Select

Select provides a single-option select menus.

This module concerns the container select. If you are looking for information about select options, refer to Material.Select.Option.

Table of Contents

Resources

Basic Usage

import Material.Select as Select
import Material.Select.Option as SelectOption


type Msg
    = ValueChanged String


main =
    Select.filled
        (Select.config
            |> Select.setLabel (Just "Fruit")
            |> Select.setValue (Just "")
            |> Select.setOnChange ValueChanged
        )
        [ SelectOption.selectOption
            (SelectOption.config |> SelectOption.setValue (Just ""))
            [ text "" ]
        , SelectOption.selectOption
            (SelectOption.config
                |> SelectOption.setValue (Just "Apple")
            )
            [ text "Apple" ]
        ]

Configuration

type Config msg

Configuration of a select

Default configuration of a select

Configuration Options

setOnChange : (String -> msg) -> Config msg -> Config msg

Specify a message when the user changes the select

setLabel : Maybe String -> Config msg -> Config msg

Specify a select's label

setValue : Maybe String -> Config msg -> Config msg

Specify a select's value

setDisabled : Bool -> Config msg -> Config msg

Specify a select to be disabled

Disabled selects cannot be interacted with an have no visual interaction effect.

setRequired : Bool -> Config msg -> Config msg

Specify whether a select is required

setValid : Bool -> Config msg -> Config msg

Specify whether a select is valid

setAttributes : List (Attribute msg) -> Config msg -> Config msg

Specify additional attributes

Filled Select

filled : Config msg -> List (SelectOption msg) -> Html msg

Filled select view function

Outlined Select

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

Select.outlined Select.config
    [ SelectOption.selectOption
        (SelectOption.config
            |> SelectOption.setValue (Just "")
        )
        [ text "" ]
    ]
outlined : Config msg -> List (SelectOption msg) -> Html msg

Outlined select view function

Disabled Select

To disable a select, set its setDisabled configuration option to True.

Select.filled (Select.config |> Select.setDisabled True) []

Required Select

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

Select.filled (Select.config |> Select.setRequired True) []

Select with helper text

TODO(select-with-helper-text)

Select with leading icon

TODO(select-with-leading-icon)