aforemny/material-components-web-elm/2.0.0

NOTE: the latest version is 9.1.0

Material.TextArea

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

Table of Contents

Resources

Basic Usage

import Material.TextArea
    exposing
        ( textArea
        , textAreaConfig
        )


type Msg
    = ValueChanged String


main =
    textArea
        { textAreaConfig
            | label = "My text area"
            , value = Just "hello world"
            , onInput = Just ValueChanged
            , rows = Just 4
            , columns = Just 20
        }
textArea : TextAreaConfig msg -> Html msg

Text area view function

textAreaConfig : TextAreaConfig msg

Default configuration of a text area

type alias TextAreaConfig msg =
{ label : Maybe String
, outlined : Bool
, fullwidth : Bool
, value : String
, placeholder : Maybe String
, rows : Maybe Int
, cols : Maybe Int
, disabled : Bool
, required : Bool
, valid : Bool
, minLength : Maybe Int
, maxLength : Maybe Int
, additionalAttributes : List (Attribute msg)
, onInput : Maybe (String -> msg)
, onChange : Maybe (String -> msg)
}

Configuration of a text area

Full Width Text Area

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

textArea { textAreaConfig | fullWidth = True }

Full width text areas do not support label and will ignore this configuration field. You may set placeholder or provide an extraneous label for a full width text area.

Full width text areas do not support outlined and will ignore this configuration field.

Disabled Text Area

To disable a text area set its disabled configuration field to True.

textArea { textAreaConfig | disabled = True }

Required Text Area

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

textArea { textAreaConfig | required = True }

Invalid Text Area

To mark a text area as invalid, set its valid configuration field to False.

textArea { textAreaConfig | valid = False }

Outlined Text Area

Text areas may have a visible outlined around them by setting their outlined configuration field to True.

textArea { textAreaConfig | outlined = True }

Note that this does not have any effect for fullwidth text areas.

Text Area with Character Counter

To have a text area display a character counter, set its maxLength configuration field, and also add a characterCounter as a child of helperLine.

[ textArea
    { textAreaConfig
        | maxLength = Just 18
    }
, helperLine [] [ characterCounter [] ]
]
characterCounter : List (Attribute msg) -> Html msg

Character counter view function