flytreeleft/elm-ui/3.3.2

NOTE: the latest version is 6.2.0

Element.Events

Mouse Events

onClick : msg -> Attribute msg
onDoubleClick : msg -> Attribute msg
onMouseDown : msg -> Attribute msg
onMouseUp : msg -> Attribute msg
onMouseEnter : msg -> Attribute msg
onMouseLeave : msg -> Attribute msg
onMouseMove : msg -> Attribute msg

Focus Events

onFocus : msg -> Attribute msg
onLoseFocus : msg -> Attribute msg

Custom

on : String -> Decoder msg -> Attribute msg

Create a custom event listener. Normally this will not be necessary, but you have the power! Here is how onClick is defined for example:

import Json.Decode as Json


onClick : msg -> Attribute msg
onClick message =
    on "click" (Json.succeed message)

The first argument is the event name in the same format as with JavaScript's addEventListener function. The second argument is a JSON decoder. Read more about these here. When an event occurs, the decoder tries to turn the event object into an Elm value. If successful, the value is routed to your update function. In the case of onClick we always just succeed with the given message. If this is confusing, work through the Elm Architecture Tutorial. It really does help!