elm-ui icon indicating copy to clipboard operation
elm-ui copied to clipboard

Custom onLoad event handler does not work for images

Open eniac314 opened this issue 6 years ago • 4 comments

I can't find a way to catch a loading event from an image rendered with elm-ui. Here is an ellie displaying two images, one with elm-ui and the other with the Html library. The custom handler only works for the second picture.

https://ellie-app.com/3fQjtP4GsPqa1

Expected behavior it should work for both pictures.

  • OS: Ubuntu 16.04
  • Browser: Firefox 61.0.1
  • elm 0.19
  • elm-ui 1.0.0

eniac314 avatar Sep 05 '18 13:09 eniac314

Looks like the event listener for the first image is getting added to the wrapper div, instead of the image element

SidneyNemzer avatar Oct 17 '18 19:10 SidneyNemzer

I'm experiencing the same issue - elm-ui 1.1.0

thetechnaddict avatar Mar 18 '19 19:03 thetechnaddict

This is my work around:


image :
    List (E.Attribute msg)
    ->
        { src : String
        , description : String
        , onLoad : Maybe (Json.Decode.Decoder msg)
        }
    -> Element msg
image attrs { src, description, onLoad } =
    E.el
        (E.htmlAttribute (Html.Attributes.class "ic")
            :: attrs
        )
        (E.html
            (Html.img
                (List.concat
                    [ [ Html.Attributes.src src
                      , Html.Attributes.alt description
                      , Html.Attributes.style "width" "100%"
                      , Html.Attributes.style "height" "100%"
                      ]
                    , case onLoad of
                        Just ol ->
                            [ Html.Events.on "load" ol ]

                        Nothing ->
                            []
                    ]
                )
                []
            )
        )

It is not exactly equivalent to Element.image as elm-ui does not expose all it's internals. Specifically, the width and height of the image have been hacked into something that seems to work for me. It also relys on elm-ui not changing the css classes it uses.

harrysarson avatar Mar 26 '20 13:03 harrysarson

also relys on elm-ui not changing the css classes it uses.

We can replace (Html.Attributes.class "ic") with (Html.Attributes.style "display" "block"). The ic class seems to only apply this one property.

NduatiK avatar May 14 '21 14:05 NduatiK