I am attempting to upgrade an elm application from 0.18 to 0.19.
I am stuck with this error -
Detected errors in 1 module.
-- BAD IMPORT ---------------------------------------- src/Views/Interaction.elm
The `Html.Events` module does not expose `onWithOptions`:
13| import Html.Events exposing (onWithOptions)
^^^^^^^^^^^^^
These names seem close though:
onMouseEnter
onMouseLeave
onMouseOut
onMouseOver
The documentation shows that onWithOptions
should be available.
My code is
module Views.Interaction exposing (onClickNoBubble)
{-| Helper functions for page interactions.
# Helpers
@docs onClickNoBubble
-}
import Html
import Html.Events exposing (onWithOptions)
import Json.Decode as Decode
{-| Replicates the onClick function but prevents bubbling
-}
onClickNoBubble : msg -> Html.Attribute msg
onClickNoBubble message =
onWithOptions "click" { stopPropagation = True, preventDefault = True } (Decode.succeed message)
How do I move forward?
Elm 0.19 does not use elm-lang/html
. You're reading the wrong documentation. It has been replaced by elm/html
which has a custom
function that serves the same purpose:
onClickNoBubble : msg -> Html.Attribute msg
onClickNoBubble message =
Html.Events.custom "click" (Decode.succeed { message = message, stopPropagation = True, preventDefault = True })
I made a little helper function to get this to work.
onCustomClick : msg -> Html.Attribute msg
onCustomClick msg =
custom "click"
(Decode.succeed
{ message = msg
, stopPropagation = True
, preventDefault = True
}
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With