debois / elm-mdl

Elm-port of the Material Design Lite CSS/JS library
Apache License 2.0
965 stars 133 forks source link

Textfield floating / placeholders don't disapear. #364

Closed hickscorp closed 6 years ago

hickscorp commented 6 years ago

I'm observing a very odd behavior.

Here is a screenshot after placing text in all the fields. As you can see, the issue doesn't occur with multilines.

image

EDIT: I am providing a full Elm file to make sure you can test easily:

module Pages.Signup exposing (Model, Msg, model, update, view)

import Material
import Material.Grid as Grid exposing (..)
import Material.Textfield as Textfield
import Material.Options as Options
import Html exposing (Html, h3, div, input, text)
import Regex

type alias Model =
    { email : String
    , password : String
    , passwordAgain : String
    , address : String
    , mdl : Material.Model
    }

type PasswordVersion
    = Original
    | Confirmation

type Msg
    = Email String
    | Password PasswordVersion String
    | Mat (Material.Msg Msg)

invalidEmail : String -> Bool
invalidEmail email =
    let
        rx =
            Regex.regex "^(([^<>()\\[\\]\\.,;:\\s@\"]+(\\.[^<>()\\[\\]\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$"
                |> Regex.caseInsensitive
    in
        Regex.contains rx email
            |> not

model : Model
model =
    { email = ""
    , password = ""
    , passwordAgain = ""
    , address = ""
    , mdl = Material.model
    }

update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    case msg of
        Email email ->
            { model | email = email } ! []

        Password version password ->
            case version of
                Original ->
                    { model | password = password } ! []

                Confirmation ->
                    { model | passwordAgain = password } ! []

        Mat msg_ ->
            Material.update Mat msg_ model

view : Model -> Html Msg
view model =
    grid []
        [ cell
            [ size Desktop 4, offset Desktop 1 ]
            [ Textfield.render Mat
                [ 0 ]
                model.mdl
                [ Textfield.label "Email Address"
                , Options.onInput Email
                , Textfield.floatingLabel
                , Textfield.error ("Doesn't look like a valid email address.")
                    |> Options.when (invalidEmail model.email)
                ]
                []
            , Textfield.render Mat
                [ 1 ]
                model.mdl
                [ Textfield.label "Password"
                , Textfield.floatingLabel
                , Textfield.password
                , Options.onInput (Password Original)
                ]
                []
            , Textfield.render Mat
                [ 2 ]
                model.mdl
                [ Textfield.label "Password (Repeat)"
                , Textfield.floatingLabel
                , Textfield.password
                , Options.onInput (Password Confirmation)
                , Textfield.error ("Passwords do not match.")
                    |> Options.when (model.password /= model.passwordAgain)
                ]
                []
            , Textfield.render Mat
                [ 3 ]
                model.mdl
                [ Textfield.label "Bio - tell us a bit about you!"
                , Textfield.floatingLabel
                , Textfield.textarea
                , Textfield.rows 6
                ]
                []
            ]
        ]
hickscorp commented 6 years ago

Solved by providing a Textfield.value option to the components. It'd be nice to have that as a side note in the docs maybe?

For future reference:

    Textfield.render Mat
                [ 0 ]
                model.mdl
                [ Textfield.label "Email Address"
                , Textfield.value model.email
                , Options.onInput Email
                , Textfield.floatingLabel
                ]
                []