avarda-ab/avarda-ui/3.0.1

NOTE: the latest version is 5.0.3

AvardaUi.Util.KeyPress

Utility functions for handling keyboard events in Elm.

This module provides a way to bind messages to specific keys. It exposes helpers for keydown, keyup, and keypress events, with or without preventDefault.

KeyboardKey type

= Enter
| Esc
| ArrowUp
| ArrowDown
| Tab
| Space

Supported keyboard keys so far.

Event Handlers

onKeyDown : List ( KeyboardKey, msg ) -> Attribute msg

Attach a keydown listener.

onKeyDownPreventDefault : List ( KeyboardKey, msg ) -> Attribute msg

Attach a keydown listener and prevent the default browser action.

onKeyUp : List ( KeyboardKey, msg ) -> Attribute msg

Attach a keyup listener.

onKeyUpPreventDefault : List ( KeyboardKey, msg ) -> Attribute msg

Attach a keyup listener and prevent the default browser action.

onKeyPress : List ( KeyboardKey, msg ) -> Attribute msg

Attach a keypress listener.

onKeyPressPreventDefault : List ( KeyboardKey, msg ) -> Attribute msg

Attach a keypress listener and prevent the default browser action.

Example

import AvardaUi.Util.KeyPress as KeyPressUtil


view : Html Msg
view =
    Html.input
        [ KeyPressUtil.onKeyDown [ ( KeyPress.Enter, HandleSubmit ) ]
        ]
        []