DioxusLabs / DioxusLabs/dioxus
Ability to use capturing event handlers
- Dominant language
- Rust
- Stars
- 39.1k
- Forks
- 1.9k
- Avg merge
- 4d 10h
- Merged PRs (30d)
- 4
Description
## Specific Demand
On the web, `EventTarget.addEventListener` [has an extra argument][mdn] that is either an options object or a boolean. The boolean is known as `useCapture`, passing `true` is equivalent to `{ capture: true }`.
When you do this, quoting MDN:
> A boolean value indicating whether events of this type will be dispatched to the registered listener before being dispatched to any EventTarget beneath it in the DOM tree. Events that are bubbling upward through the tree will not trigger a listener designated to use capture. Event bubbling and capturing are two ways of propagating events that occur in an element that is nested within another element, when both elements have registered a handle for that event. The event propagation mode determines the order in which elements receive the event. See DOM Level 3 Events and JavaScript Event order for a detailed explanation. If not specified, useCapture defaults to false.
I wish to be able to set an event handler in dioxus with the capture flag set to true, and have the synthetic event system figure out the details.
[mdn]: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
## Implement Suggestion
EventHandler is already a struct with a call() method, right?. I assume it has a From impl for closures of the right type? If so, just let people construct an EventHandler explicitly and include the options in the constructor (or a builder pattern).
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by tracing EventHandler.call() and the synthetic event system to find how event handlers are registered and dispatched. Confirm how an explicit capture option should be represented, then verify that captured handlers run in the intended order; done means Dioxus users can request capture behavior without managing DOM details themselves.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100