Last active
December 24, 2021 16:06
-
-
Save svoisen/538d0074c655cdbfe7eef6d8f4e42ef6 to your computer and use it in GitHub Desktop.
Handle onEnter in Elm including input value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
onEnter : (String -> msg) -> Attribute msg | |
onEnter tagger = | |
let | |
isEnter code = | |
if code == 13 then | |
Decode.succeed "" | |
else | |
Decode.fail "" | |
decodeEnter = | |
Decode.andThen isEnter keyCode | |
in | |
on "keydown" <| Decode.map2(\key value -> tagger value) decodeEnter targetValue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this snippet!