Skip to content

Html.Keyed.node does not preserve scroll positions across children #183

@pravdomil

Description

@pravdomil

The __3_REORDER patch removes nodes from DOM and that causes scroll positions to reset.

I think that it can use only insertBefore function to preserve node state.

SSCCE

module Main exposing (..)

import Browser
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Html.Keyed


main : Program () Bool ()
main =
    Browser.sandbox
        { init = False
        , view = view
        , update = always not
        }


view : Bool -> Html ()
view model =
    div []
        [ Html.Keyed.node "div"
            []
            ([ content "A"
             , content "B"
             ]
                |> (\x ->
                        if model then
                            List.reverse x

                        else
                            x
                   )
            )
        , button [ onClick () ] [ text "Swap" ]
        ]


content a =
    ( a
    , div
        [ id a
        , style "overflow" "auto"
        , style "height" "100px"
        , style "width" "100px"
        , style "padding" "10px"
        , style "border" "1px solid blue"
        ]
        [ text (String.repeat 5000 (a ++ " "))
        ]
    )

related to #178

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions