| 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.Html.Event
Description
Overview
Miso.Html.Event provides pre-wired event-handler Attribute
values for the most common browser events. Each handler is built on the
lower-level on / onWithOptions primitives from
Miso.Event.
This module is re-exported in its entirety by Miso.Html and Miso.
Naming conventions
Handlers follow a consistent naming pattern:
onXxx action- fires
action; no event data extracted onXxxWith (a -> action)- passes extracted event data or
DOMRef onXxxWithOptions opts act- adds
Options(preventDefault/stopPropagation) before firing onXxxCapture action- registers in the capture phase instead of bubble
Quick start
import Miso view :: Model ->ViewModel Action view m =div_[] [button_[onClickIncrement ] [text"+" ] ,input_[onInputSetText ,value_m.text ] [] ,form_[onSubmitSubmit ] [] -- preventDefault by default ]
Event groups
- Mouse:
onClick,onClickCapture,onClickWith,onClickWithOptions,onClickPrevent,onDoubleClick,onDoubleClickWith,onMouseDown,onMouseUp,onMouseEnter,onMouseLeave,onMouseOver,onMouseOut,onContextMenuWithOptions - Keyboard:
onKeyDown,onKeyDownWithInfo,onKeyPress,onKeyUp,onEnter - Form:
onInput,onInputWith,onChange,onChangeWith,onChecked,onSubmit,onSelect - Focus:
onFocus,onBlur - Drag:
onDrag,onDragStart,onDragEnd,onDragEnter,onDragLeave,onDragOver,onDrop(andWithOptionsvariants) - Pointer:
onPointerDown,onPointerUp,onPointerEnter,onPointerLeave,onPointerOver,onPointerOut,onPointerCancel,onPointerMove - Media:
onPlay,onPause,onEnded,onTimeUpdate,onVolumeChange,onLoadedData,onLoadedMetadata, … (andWithvariants) - Touch:
onTouchStart,onTouchEnd,onTouchMove,onTouchCancel(andWithOptionsvariants) - Lifecycle:
onLoad,onUnload,onError
Notes
onSubmitenablespreventDefaultby default to suppress the native form submission.onEnteris a convenience wrapper aroundonKeyDownthat fires different actions depending on whetherkeyCode == 13.- The
WithOptionsvariants requiredefaultEvents(or a superset) to include the relevant event name in the component'seventsmap.
See also
- Miso.Event —
on,onCapture,onWithOptions - Miso.Event.Decoder —
Decoderfor custom event extraction - Miso.Event.Types —
Options,KeyCode,PointerEvent
Synopsis
- onClick :: action -> Attribute action
- onClickPrevent :: action -> Attribute action
- onClickCapture :: action -> Attribute action
- onClickWith :: (DOMRef -> action) -> Attribute action
- onClickWithOptions :: Options -> action -> Attribute action
- onDoubleClick :: action -> Attribute action
- onDoubleClickWith :: (DOMRef -> action) -> Attribute action
- onDoubleClickWithOptions :: Options -> action -> Attribute action
- onMouseDown :: action -> Attribute action
- onMouseUp :: action -> Attribute action
- onMouseEnter :: action -> Attribute action
- onMouseLeave :: action -> Attribute action
- onMouseOver :: action -> Attribute action
- onMouseOut :: action -> Attribute action
- onContextMenuWithOptions :: Options -> action -> Attribute action
- onKeyDown :: (KeyCode -> action) -> Attribute action
- onKeyDownWithInfo :: (KeyInfo -> action) -> Attribute action
- onKeyPress :: (KeyCode -> action) -> Attribute action
- onKeyUp :: (KeyCode -> action) -> Attribute action
- onEnter :: action -> action -> Attribute action
- onInput :: (MisoString -> action) -> Attribute action
- onInputWith :: (MisoString -> DOMRef -> action) -> Attribute action
- onChange :: (MisoString -> action) -> Attribute action
- onChangeWith :: (MisoString -> DOMRef -> action) -> Attribute action
- onChecked :: (Checked -> action) -> Attribute action
- onSubmit :: action -> Attribute action
- onBlur :: action -> Attribute action
- onFocus :: action -> Attribute action
- onDrag :: action -> Attribute action
- onDragWithOptions :: Options -> action -> Attribute action
- onDragLeave :: action -> Attribute action
- onDragLeaveWithOptions :: Options -> action -> Attribute action
- onDragEnter :: action -> Attribute action
- onDragEnterWithOptions :: Options -> action -> Attribute action
- onDragEnd :: action -> Attribute action
- onDragEndWithOptions :: Options -> action -> Attribute action
- onDragStart :: action -> Attribute action
- onDragStartWithOptions :: Options -> action -> Attribute action
- onDragOver :: action -> Attribute action
- onDragOverWithOptions :: Options -> action -> Attribute action
- onDrop :: Options -> action -> Attribute action
- onDropWithOptions :: Options -> action -> Attribute action
- onSelect :: (MisoString -> action) -> Attribute action
- onPointerDown :: (PointerEvent -> action) -> Attribute action
- onPointerUp :: (PointerEvent -> action) -> Attribute action
- onPointerEnter :: (PointerEvent -> action) -> Attribute action
- onPointerLeave :: (PointerEvent -> action) -> Attribute action
- onPointerOver :: (PointerEvent -> action) -> Attribute action
- onPointerOut :: (PointerEvent -> action) -> Attribute action
- onPointerCancel :: (PointerEvent -> action) -> Attribute action
- onPointerMove :: (PointerEvent -> action) -> Attribute action
- onAbort :: action -> Attribute action
- onAbortWith :: (Media -> action) -> Attribute action
- onCanPlay :: action -> Attribute action
- onCanPlayWith :: (Media -> action) -> Attribute action
- onCanPlayThrough :: action -> Attribute action
- onCanPlayThroughWith :: (Media -> action) -> Attribute action
- onDurationChange :: action -> Attribute action
- onDurationChangeWith :: (Media -> action) -> Attribute action
- onEmptied :: action -> Attribute action
- onEmptiedWith :: (Media -> action) -> Attribute action
- onEnded :: action -> Attribute action
- onEndedWith :: (Media -> action) -> Attribute action
- onError :: action -> Attribute action
- onErrorWith :: (Media -> action) -> Attribute action
- onLoad :: action -> Attribute action
- onUnload :: action -> Attribute action
- onLoadedData :: action -> Attribute action
- onLoadedDataWith :: (Media -> action) -> Attribute action
- onLoadedMetadata :: action -> Attribute action
- onLoadedMetadataWith :: (Media -> action) -> Attribute action
- onLoadStart :: action -> Attribute action
- onLoadStartWith :: (Media -> action) -> Attribute action
- onPause :: action -> Attribute action
- onPauseWith :: (Media -> action) -> Attribute action
- onPlay :: action -> Attribute action
- onPlayWith :: (Media -> action) -> Attribute action
- onPlaying :: action -> Attribute action
- onPlayingWith :: (Media -> action) -> Attribute action
- onProgress :: action -> Attribute action
- onProgressWith :: (Media -> action) -> Attribute action
- onRateChange :: action -> Attribute action
- onRateChangeWith :: (Media -> action) -> Attribute action
- onSeeked :: action -> Attribute action
- onSeekedWith :: (Media -> action) -> Attribute action
- onSeeking :: action -> Attribute action
- onSeekingWith :: (Media -> action) -> Attribute action
- onStalled :: action -> Attribute action
- onStalledWith :: (Media -> action) -> Attribute action
- onSuspend :: action -> Attribute action
- onSuspendWith :: (Media -> action) -> Attribute action
- onTimeUpdate :: action -> Attribute action
- onTimeUpdateWith :: (Media -> action) -> Attribute action
- onVolumeChange :: action -> Attribute action
- onVolumeChangeWith :: (Media -> action) -> Attribute action
- onWaiting :: action -> Attribute action
- onWaitingWith :: (Media -> action) -> Attribute action
- onTouchStart :: action -> Attribute action
- onTouchStartWithOptions :: Options -> action -> Attribute action
- onTouchEnd :: action -> Attribute action
- onTouchEndWithOptions :: Options -> action -> Attribute action
- onTouchMove :: action -> Attribute action
- onTouchMoveWithOptions :: Options -> action -> Attribute action
- onTouchCancel :: action -> Attribute action
- onTouchCancelWithOptions :: Options -> action -> Attribute action
Mouse
onClickPrevent :: action -> Attribute action Source #
onClickCapture :: action -> Attribute action Source #
onClickWith :: (DOMRef -> action) -> Attribute action Source #
https://developer.mozilla.org/en-US/docs/Web/Events/click
Like onClick, but passes the DOM reference along (akin to getElementById).
onDoubleClick :: action -> Attribute action Source #
onDoubleClickWith :: (DOMRef -> action) -> Attribute action Source #
onMouseDown :: action -> Attribute action Source #
onMouseEnter :: action -> Attribute action Source #
onMouseLeave :: action -> Attribute action Source #
onMouseOver :: action -> Attribute action Source #
onMouseOut :: action -> Attribute action Source #
onContextMenuWithOptions Source #
Arguments
| :: Options | Propagation options ( |
| -> action | Action to dispatch when the context menu event fires |
| -> Attribute action |
https://developer.mozilla.org/en-US/docs/Web/Events/contextmenu
This can be used to disable right-click context menu from appearing
div_ [ onContextMenuWithOptions NoOp defaultOptions { preventDefault = False } ] [ ]
Since: 1.9.0.0
Keyboard
Arguments
| :: action | The action to call when the keydown *is not* 13 (typically |
| -> action | The action to call when keydown *is* 13. |
| -> Attribute action |
A convenience function for processing the Enter key.
data Action = NoOp | OnEnter type Model = Int view :: Model -> View model Action view entryId = input_ [ onEnter NoOp OnEnter ]
Since: 1.9.0.0
Form
Arguments
| :: (MisoString -> action) | Callback receiving |
| -> Attribute action |
Arguments
| :: (MisoString -> DOMRef -> action) | Callback receiving |
| -> Attribute action |
Arguments
| :: (MisoString -> action) | Callback receiving |
| -> Attribute action |
Arguments
| :: (MisoString -> DOMRef -> action) | Callback receiving |
| -> Attribute action |
onSubmit :: action -> Attribute action Source #
https://developer.mozilla.org/en-US/docs/Web/Events/submit
Note: This has preventDefault enabled by default.
Focus
Drag
onDragLeave :: action -> Attribute action Source #
onDragEnter :: action -> Attribute action Source #
onDragStart :: action -> Attribute action Source #
onDragOver :: action -> Attribute action Source #
Drop
Select
Arguments
| :: (MisoString -> action) | Callback receiving |
| -> Attribute action |
Pointer
Arguments
| :: (PointerEvent -> action) | Callback receiving the full |
| -> Attribute action |
Arguments
| :: (PointerEvent -> action) | Callback receiving the full |
| -> Attribute action |
Arguments
| :: (PointerEvent -> action) | Callback receiving the full |
| -> Attribute action |
Arguments
| :: (PointerEvent -> action) | Callback receiving the full |
| -> Attribute action |
Arguments
| :: (PointerEvent -> action) | Callback receiving the full |
| -> Attribute action |
Arguments
| :: (PointerEvent -> action) | Callback receiving the full |
| -> Attribute action |
Arguments
| :: (PointerEvent -> action) | Callback receiving the full |
| -> Attribute action |
Arguments
| :: (PointerEvent -> action) | Callback receiving the full |
| -> Attribute action |
Media
onAbortWith :: (Media -> action) -> Attribute action Source #
onCanPlayWith :: (Media -> action) -> Attribute action Source #
onCanPlayThrough :: action -> Attribute action Source #
onCanPlayThroughWith :: (Media -> action) -> Attribute action Source #
onDurationChange :: action -> Attribute action Source #
onDurationChangeWith :: (Media -> action) -> Attribute action Source #
onEmptiedWith :: (Media -> action) -> Attribute action Source #
onEndedWith :: (Media -> action) -> Attribute action Source #
onErrorWith :: (Media -> action) -> Attribute action Source #
onLoadedData :: action -> Attribute action Source #
onLoadedDataWith :: (Media -> action) -> Attribute action Source #
onLoadedMetadata :: action -> Attribute action Source #
onLoadedMetadataWith :: (Media -> action) -> Attribute action Source #
onLoadStart :: action -> Attribute action Source #
onLoadStartWith :: (Media -> action) -> Attribute action Source #
onPauseWith :: (Media -> action) -> Attribute action Source #
onPlayWith :: (Media -> action) -> Attribute action Source #
onPlayingWith :: (Media -> action) -> Attribute action Source #
onProgress :: action -> Attribute action Source #
onProgressWith :: (Media -> action) -> Attribute action Source #
onRateChange :: action -> Attribute action Source #
onRateChangeWith :: (Media -> action) -> Attribute action Source #
onSeekedWith :: (Media -> action) -> Attribute action Source #
onSeekingWith :: (Media -> action) -> Attribute action Source #
onStalledWith :: (Media -> action) -> Attribute action Source #
onSuspendWith :: (Media -> action) -> Attribute action Source #
onTimeUpdate :: action -> Attribute action Source #
onTimeUpdateWith :: (Media -> action) -> Attribute action Source #
onVolumeChange :: action -> Attribute action Source #
onVolumeChangeWith :: (Media -> action) -> Attribute action Source #
onWaitingWith :: (Media -> action) -> Attribute action Source #
Touch
onTouchStart :: action -> Attribute action Source #
onTouchEnd :: action -> Attribute action Source #
onTouchMove :: action -> Attribute action Source #
onTouchCancel :: action -> Attribute action Source #