Rerouted (cache, verified). The original is gone. This copy comes from a Lamdera package cache made before it went. The Lamdera package server serves a copy recovered from a Lamdera package cache from 2021-02-13.
What we checked: Rebuilt from the unpacked sources in a Lamdera package cache (5 copies agree), which Elm only writes after the published SHA-1 checked out; elm.json is byte-identical to package.elm-lang.org's; the exposed modules match docs.json; the zip is our own, so its SHA-1 is not the published one.
The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.
Details · package.elm-lang.org's zip: https://github.com/altayaydemir/style-elements/zipball/1.0.0/
This module is mirrored nearly completely from Html.Events
The only difference is that the HTML.Events are turned into Element.Events
Capture input
events for things like text fields or text areas.
It grabs the string value at event.target.value, so it will not work if
you need some other type of information. For example, if you want to track
inputs on a range slider, make a custom handler with on.
For more details on how onInput works, check out targetValue.
Capture change
events on checkboxes. It will grab the boolean value from event.target.checked
on any input event.
Check out targetChecked for more details on how this works.
Capture a submit
event with preventDefault
in order to prevent the form from changing the page’s location. If you need
different behavior, use onWithOptions to create a customized version of
onSubmit.
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 variation 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!
A Json.Decoder for grabbing event.target.value. We use this to define
onInput as follows:
import Json.Decode as Json
onInput : (String -> msg) -> Attribute msg
onInput tagger =
on "input" (Json.map tagger targetValue)You probably will never need this, but hopefully it gives some insights into how to make custom event handlers.
A Json.Decoder for grabbing event.target.checked. We use this to define
onCheck as follows:
import Json.Decode as Json
onCheck : (Bool -> msg) -> Attribute msg
onCheck tagger =
on "input" (Json.map tagger targetChecked)A Json.Decoder for grabbing event.keyCode. This helps you define
keyboard listeners like this:
import Json.Decode as Json
onKeyUp : (Int -> msg) -> Attribute msg
onKeyUp tagger =
on "keyup" (Json.map tagger keyCode)Note: It looks like the spec is moving away from event.keyCode and
towards event.key. Once this is supported in more browsers, we may add
helpers here for onKeyUp, onKeyDown, onKeyPress, etc.