aforemny/material-components-web-elm/3.0.1

NOTE: the latest version is 9.1.0

Material.TextField

Text fields allow users to input, edit, and select text.

Table of Contents

Resources

Basic Usage

import Material.TextField as TextField


type Msg
    = ValueChanged String


main =
    TextField.filled
        (TextField.config
            |> TextField.setLabel (Just "My text field")
            |> TextField.setValue (Just "hello world")
            |> TextField.setOnInput ValueChanged
        )

Configuration

type Config msg

Configuration of a text field

Default configuration of a text field

Configuration Options

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

Specify a message when the user changes the value inside the text field

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

Specify a message when the user confirms a changed value inside the text field

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

Specify a text field's label

setFullwidth : Bool -> Config msg -> Config msg

Specify a text field to be fullwidth

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

Specify a text field's value

setPlaceholder : Maybe String -> Config msg -> Config msg

Specify a text field's placeholder

setDisabled : Bool -> Config msg -> Config msg

Specify a text field to be disabled

Disabled text fields cannot be interacted with and have no visual interaction effect.

setRequired : Bool -> Config msg -> Config msg

Specify a text field to be required

setValid : Bool -> Config msg -> Config msg

Specify a text field to be valid

setMinLength : Maybe Int -> Config msg -> Config msg

Specify a text field's minimum length

setMaxLength : Maybe Int -> Config msg -> Config msg

Specify a text field's maximum length

setPattern : Maybe String -> Config msg -> Config msg

Specify a text field's pattern

setType : Maybe String -> Config msg -> Config msg

Specify a text field's type

setMin : Maybe Int -> Config msg -> Config msg

Specify a text field's minimum value

setMax : Maybe Int -> Config msg -> Config msg

Specify a text field's maximum value

setStep : Maybe Int -> Config msg -> Config msg

Specify a text field's step value

setLeadingIcon : Maybe (Icon msg) -> Config msg -> Config msg

Specify a text field's leading icon

setTrailingIcon : Maybe (Icon msg) -> Config msg -> Config msg

Specify a text field's trailing icon

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

Specify additional attributes

Filled Text Field

Filled Text Field

TextField.filled TextField.config
filled : Config msg -> Html msg

Filled text field view function

Outlined Text Field

Text fields may have a visible outlined around them by using their outlined variant.

TextField.outlined TextField.config

Note that setFullwidth does not have any effect on an outlined text field.

outlined : Config msg -> Html msg

Outlined text field view function

Full Width Text Field

To make a text field span all of its available width, set its setFullwidth configuration option to True.

TextField.filled
    (TextField.config |> TextField.setFullwidth True)

Full width text fields do not support a label and will ignore the setLabel configuration option. You may use setPlaceholder or provide an extraneous label for a full width text field.

Outlined text fields do not support setFullwidth and wll ignore this configuration option.

Disabled Text Field

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

TextField.filled
    (TextField.config |> TextField.setDisabled True)

Password Text Field

To mark a text field as an input for entering a passwort, use its setType configuration option to specify "password".

TextField.filled
    (TextField.config |> TextField.setType (Just "password"))

Other input types besides "password" may or may not be supported.

Required Text Field

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

TextField.filled
    (TextField.config |> TextField.setRequired True)

Valid Text Field

To mark a text field as valid, set its setValid configuration option to True.

TextField.filled
    (TextField.config |> TextField.setValid True)

Text Field with Leading Icon

To have a text field display a leading icon, use its setLeadingIcon configuration option to specify a value of Icon.

TextField.filled
    (TextField.config
        |> TextField.setLeadingIcon
            (Just (TextField.icon [] "wifi"))
    )
type Icon msg

Text field trailing or leading icon -

icon : List (Attribute msg) -> String -> Icon msg

A text field's icon, either leading or trailing

Text Field with Trailing Icon

To have a text field display a trailing icon, use its setTrailingIcon configuration option to specify a value of Icon.

TextField.filled
    (TextField.config
        |> TextField.setTrailingIcon
            (Just (TextField.icon [] "clear"))
    )

Text Field with Character Counter

To have a text field display a character counter, specify its setMaxLength configuration option, and also add a HelperText.characterCounter as a child of HelperText.helperLine.

[ TextField.filled
    (TextField.config |> TextField.setMaxLength (Just 18))
, HelperText.helperLine [] [ HelperText.characterCounter [] ]
]