Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Styles get lost after model update #164

Open
simonh1000 opened this issue Feb 10, 2020 · 1 comment
Open

Styles get lost after model update #164

simonh1000 opened this issue Feb 10, 2020 · 1 comment

Comments

@simonh1000
Copy link

simonh1000 commented Feb 10, 2020

Take a look at https://ellie-app.com/7ZFCDMKy54sa1 .

Look at the red square using the dev console and note the padding is a mixture of 5 and 20px.
Click the button.

Expect: padding-top of 5px
Actual: All mention of padding has been removed from html being rendered

module Main exposing (main)

import Browser
import Dict exposing (Dict)
import Html exposing (Html, button, div, text)
import Html.Attributes exposing (..)
import Html.Events exposing (onClick)


type alias Model =
    { styles : Dict String Int }


initialModel : Model
initialModel =
    { styles =
        Dict.fromList
            [ ( "width", 100 )
            , ( "height", 100 )
            , ( "padding", 20 )
            , ( "padding-top", 5 )
            ]
    }


type Msg
    = Increment


update : Msg -> Model -> Model
update msg model =
    case msg of
        Increment ->
            { model | styles = Dict.remove "padding" model.styles }


view : Model -> Html Msg
view model =
    let
        attrs =
            model.styles
                |> Dict.map (\k v -> style k (String.fromInt v ++ "px"))
                |> Dict.values
    in
    div []
        [ div (style "backgroundColor" "red" :: attrs) []
        , button [ onClick Increment ] [ text "Remove one" ]
        ]


main : Program () Model Msg
main =
    Browser.sandbox
        { init = initialModel
        , view = view
        , update = update
        }

Comments:

@lydell
Copy link

lydell commented Jun 30, 2024

Probably related: elm/html#145

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants