Elmish.HTML.Events
- Package
- purescript-elmish-html
- Repository
- collegevine/purescript-elmish-html
This module defines types that are used as event objects in React built-in events, as well as some convenience functions on them.
#EventHandler Source
type EventHandler a = EffectFn1 a Unit
Type of every onXyz
property on every HTML tag in this library. This is
the standard shape of all event handlers on React's built-in components
(aka tags).
#InputChangeEvent Source
newtype InputChangeEvent
Event object specifically for the onChange
event of the <input>
tag.
While it doesn't have any special properties relative to SyntheticEvent
,
it's modeled as a separate type so as to support the custom accessors
inputText
and inputChecked
, thus reducing the friction in the most
frequent use case of:
input { type: "text", onChange: dispatch <| MyInputChanged <<< E.inputText }
input { type: "checkbox", onChange: dispatch <| MyCheckboxChanged <<< E.inputChecked }
Constructors
Instances
#KeyboardEvent Source
newtype KeyboardEvent
Event object for keyboard-related events such as onKeyDown
or onKeyPress
. This
type follows React docs at https://reactjs.org/docs/events.html#keyboard-events
Constructors
Instances
#MouseEvent Source
newtype MouseEvent
Event object for mouse-related events such as onMouseDown
or onMouseMove
. This
type follows React docs at https://reactjs.org/docs/events.html#mouse-events
Constructors
Instances
#SelectChangeEvent Source
newtype SelectChangeEvent
Event object specifically for the onChange
event of the <select>
tag.
While it doesn't have any special properties relative to SyntheticEvent
,
it's modeled as a separate type so as to support the custom accessor
selectSelectedValue
, thus reducing the friction in the most frequent use
case of:
select { onChange: dispatch <| MyInputChanged <<< E.selectSelectedValue }
Constructors
Instances
#SyntheticEvent Source
newtype SyntheticEvent
The most generic event object from React, for events that don't have any special properties. This type follows React docs at https://reactjs.org/docs/events.html
Constructors
Instances
#TextAreaChangeEvent Source
newtype TextAreaChangeEvent
Event object specifically for the onChange
event of the <textarea>
tag.
While it doesn't have any special properties relative to SyntheticEvent
,
it's modeled as a separate type so as to support the custom accessor
textareaText
, thus reducing the friction in the most frequent use case of:
textarea { onChange: dispatch <| MyTextareaChanged <<< E.textareaText }
Constructors
Instances
#TouchEvent Source
newtype TouchEvent
Event object for touch-related events such as onTouchStart
or
onTouchMove
. This type follows React docs at https://reactjs.org/docs/events.html#touch-events
Constructors
Instances
#inputChecked Source
inputChecked :: InputChangeEvent -> Boolean
Convenience accessor for extracting the checked state of an
<input type=checkbox>
tag in its onChange
handler.
input { type: "checkbox", onChange: dispatch <| MyCheckboxChanged <<< E.inputChecked }
#inputText Source
inputText :: InputChangeEvent -> String
Convenience accessor for extracting the value of an <input type=text>
tag
in its onChange
handler.
input { type: "text", onChange: dispatch <| MyInputChanged <<< E.inputText }
#selectSelectedValue Source
selectSelectedValue :: SelectChangeEvent -> String
Convenience accessor for extracting the selected value of a <select>
tag
in its onChange
handler.
select { onChange: dispatch <| MyInputChanged <<< E.selectSelectedValue }
#textareaText Source
textareaText :: TextAreaChangeEvent -> String
Convenience accessor for extracting the value of a <textarea>
tag
in its onChange
handler.
textarea { onChange: dispatch <| MyTextareaChanged <<< E.textareaText }
Re-exports from Elmish.Dispatch
#handleEffect Source
handleEffect :: forall event f. HandleEffect event f => f -> EffectFn1 event Unit
An escape-hatch way to create an event handler for when neither
handle
nor handleMaybe
are appropriate, which usually happens when
the event handler must do something else, besides dispatching a
message.
The argument may be either an Effect Unit
or a function from the
event object to Effect Unit
. If a message needs to be dispatched, the
consuming code is expected to do it via calling the Dispatch
function
directly.
div
{ onKeyDown: E.handleEffect \(E.KeyboardEvent e) -> do
window >>= localStorage >>= setItem "Last key pressed" e.key
dispatch PressedKey
, onClick: E.handleEffect \e -> do
E.stopPropagation e
dispatch ClickedDiv
}
Re-exports from Elmish.HTML.Events.Methods
#stopPropagation Source
stopPropagation :: forall e. IsSyntheticEvent e => e -> Effect Unit
Prevents propagation of the event up the React DOM tree. See also https://reactjs.org/docs/events.html
#preventDefault Source
preventDefault :: forall e. IsSyntheticEvent e => e -> Effect Unit
Prevents the default handling of the event by the browser. See also https://reactjs.org/docs/events.html
#getModifierState Source
getModifierState :: forall e. IsKeyboardOrMouseEvent e => String -> e -> Boolean
Returns the state of a given modifier key during an event, as defined in https://reactjs.org/docs/events.html#keyboard-events
This function applies only to certain kinds of events, such as MouseEvent
or KeyboardEvent
.