Elm’s Html.Events.onInput
lets you handle changes to a textarea, but only if you care about the raw text. If you want to handle keyboard shortcuts, or treating key presses differently when the shift key is held, you need to listen for specific keyboard events.
Examples
View.elm
view =
textarea
[ on "keyup" keyCodeAndShiftDecoder
, placeholder "Your message…"
, value model.message
, onInput MessageUpdate
]
[]
keyCodeAndShiftDecoder : Decoder Msg
keyCodeAndShiftDecoder =
Json.Decode.map2 KeyUp
keyCode
(Json.Decode.at [ "shiftKey" ] Json.Decode.bool)
Links