| Copyright | (C) 2016-2026 David M. Johnson |
|---|---|
| License | BSD3-style (see the file LICENSE) |
| Maintainer | David M. Johnson <code@dmj.io> |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Miso.Event.Types
Description
Overview
Miso.Event.Types defines the payload types for browser DOM events and
the Events map that controls which events are delegated to the miso
runtime and at which Phase of the event lifecycle.
Event delegation
Miso uses
event delegation:
a single listener is attached at the root of the component's DOM subtree
and catches all matching events as they bubble or capture past it.
The Events map ()
declares which event names participate and their phase.Map MisoString Phase
The default set (defaultEvents) covers the most common interactions.
Additional event groups can be merged in when constructing a component:
myComponent = (componentmodel update view) {events=defaultEvents<>keyboardEvents<>pointerEvents}
Event groups
defaultEvents- blur, change, click, contextmenu, dblclick, focus, input, select, submit
keyboardEvents- keydown, keypress, keyup
mouseEvents- mouseup, mousedown, mouseenter, mouseleave, mouseover, mouseout, contextmenu
dragEvents- drag, dragstart, dragend, dragenter, dragleave, dragover, drop
pointerEvents- pointerup, pointerdown, pointerenter, pointerleave, pointerover, pointerout, pointercancel, contextmenu
mediaEvents- play, pause, ended, timeupdate, volumechange, …
clipboardEvents- cut, copy, paste
touchEvents- touchstart, touchend, touchmove, touchcancel
Payload types
KeyCode/KeyInfo— keyboard event key code and modifier state.Checked— checkboxcheckedboolean.PointerEvent/PointerType— pointer position, pressure, tilt, and device type.Options— per-handler flags:preventDefault,stopPropagation.
See also
- Miso.Event.Decoder —
Decoderand pre-built decoders for these types - Miso.Html.Event —
onClick,onInput,onKeyDown, … combinators
Synopsis
- type Events = Map MisoString Phase
- data Phase
- data KeyInfo = KeyInfo {}
- newtype KeyCode = KeyCode Int
- newtype Checked = Checked Bool
- data PointerEvent = PointerEvent {}
- data PointerType
- data Options = Options {}
- defaultOptions :: Options
- preventDefault :: Options
- stopPropagation :: Options
- defaultEvents :: Events
- keyboardEvents :: Events
- mouseEvents :: Events
- dragEvents :: Events
- pointerEvents :: Events
- mediaEvents :: Events
- clipboardEvents :: Events
- touchEvents :: Events
Types
Phase during which event listener is invoked.
Since: 1.9.0.0
KeyboardEvent
Type useful for both KeyCode and additional key press information.
Constructors
| KeyInfo | |
Fields
| |
Type used for Keyboard events.
See https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode#Browser_compatibility
CheckedEvent
Type used for Checkbox events.
PointerEvent
data PointerEvent Source #
Type used for Pointer events. https://w3c.github.io/pointerevents
Constructors
| PointerEvent | |
Fields
| |
Instances
| Show PointerEvent Source # | |
Defined in Miso.Event.Types Methods showsPrec :: Int -> PointerEvent -> ShowS # show :: PointerEvent -> String # showList :: [PointerEvent] -> ShowS # | |
| Eq PointerEvent Source # | |
Defined in Miso.Event.Types | |
data PointerType Source #
Instances
| Show PointerType Source # | |
Defined in Miso.Event.Types Methods showsPrec :: Int -> PointerType -> ShowS # show :: PointerType -> String # showList :: [PointerType] -> ShowS # | |
| Eq PointerType Source # | |
Defined in Miso.Event.Types | |
| FromJSON PointerType Source # | |
Defined in Miso.Event.Types | |
Options
Options for handling event propagation.
Constructors
| Options | |
Fields
| |
defaultOptions :: Options Source #
Default value for Options.
defaultOptions = Options { preventDefault = False, stopPropagation = False }preventDefault :: Options Source #
Smart constructor for specifying preventDefault
Since: 1.9.0.0
stopPropagation :: Options Source #
Smart constructor for specifying stopPropagation
Since: 1.9.0.0
Events
defaultEvents :: Events Source #
Default delegated events
keyboardEvents :: Events Source #
Keyboard events
mouseEvents :: Events Source #
Mouse events
dragEvents :: Events Source #
Drag events
pointerEvents :: Events Source #
Pointer events
mediaEvents :: Events Source #
Audio video events
For use with the audio and video tags.
myApp ::AppModel Action myApp = (componentmodel update view){ events =defaultEvents<>mediaEvents}
clipboardEvents :: Events Source #
Clipboard events
touchEvents :: Events Source #
Touch events