Skip to content

Instantly share code, notes, and snippets.

@Chadtech
Last active June 30, 2018 23:43
Show Gist options
  • Save Chadtech/baba5b5d01ceb320b00d41d5464fe1b6 to your computer and use it in GitHub Desktop.
Save Chadtech/baba5b5d01ceb320b00d41d5464fe1b6 to your computer and use it in GitHub Desktop.
import Json.Decoder as Decode
import Html.Events exposing (keyCode, on)
onEnter : msg -> Attribute msg
onEnter msg =
on "keydown" (keyCode |> Decode.andThen (enterDecoder msg))
enterDecoder : msg -> Int -> Decoder msg
enterDecoder msg keyCode =
case keyCode of
13 ->
Decode.succeed msg
_ ->
Decode.fail "Not enter key"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment