redraw/event
Event handlers will receive a React event object. It is also sometimes known as a “synthetic event”.
import redraw/dom/events
import redraw/dom/html
pub fn render() {
html.button(
[
events.on_click(fn (event) {
io.debug(event) // React Event
})
],
[html.text("Exampe")]
)
}
It conforms to the same standard as the underlying DOM events, but fixes some browser inconsistencies.
Some React events do not map directly to the browser’s native events.
For example in on_mouse_leave
, event.native_event(event)
will point to a
MouseEvent
event.
The specific mapping is not part of the public API and may change in the
future. If you need the underlying browser event for some reason, read it
from event.native_event(event)
.
Every events have their implementation as redraw/dom/event/[event_name]
, and
their corresponding functions are implemented in those. Every time you need
to use one of the functions defined here, use to_event
from the
corresponding module.
Types
Synthetic Event sent by React.
It conforms to the same standard as the underlying DOM events, but
fixes some browser inconsistencies.
Documentation
pub type Event
Functions
pub fn bubbles(event: Event) -> Bool
Returns whether the event bubbles through the DOM.
Documetation
pub fn cancelable(event: Event) -> Bool
Returns whether the event can be canceled.
Documentation
pub fn current_target(event: Event) -> Dynamic
Returns the node to which the current handler is attached in the React tree.
Documentation
pub fn default_prevented(event: Event) -> Bool
Returns whether prevent_default
was called.
Documentation
pub fn event_phase(event: Event) -> Int
Returns which phase the event is currently in.
Documentation
pub fn is_default_prevented(event: Event) -> Bool
Returns a boolean value indicating whether prevent_default
was called.
React addition, does not exist in standard browsers.
pub fn is_persistent(event: Event) -> Bool
Not used with React DOM. With React Native, returns whether persist has been called.
React addition, does not exist in standard browsers.
pub fn is_propagation_stopped(event: Event) -> Bool
Returns a boolean value indicating whether stop_propagation
was called.
React addition, does not exist in standard browsers.
pub fn is_trusted(event: Event) -> Bool
Returns whether the event was initiated by user.
Documentation
pub fn native_event(event: Event) -> Dynamic
The original browser event object.
Documentation
pub fn persist(event: Event) -> Event
Not used with React DOM. With React Native, call this to read event’s properties after the event.
React addition, does not exist in standard browsers.
pub fn prevent_default(event: Event) -> Event
Prevents the default browser action for the event.
Documentation
pub fn stop_propagation(event: Event) -> Event
Stops the event propagation through the React tree.
Documentation
pub fn target(event: Event) -> Dynamic
Returns the node on which the event has occurred (which could be a distant child).
Documentation
pub fn time_stamp(event: Event) -> Int
Returns the time when the event occurred.
Documentation