diff --git a/packages/yew/src/virtual_dom/listeners.rs b/packages/yew/src/virtual_dom/listeners.rs
index 630606f6368..df438572302 100644
--- a/packages/yew/src/virtual_dom/listeners.rs
+++ b/packages/yew/src/virtual_dom/listeners.rs
@@ -357,6 +357,7 @@ impl GlobalHandlers {
cl.as_ref().unchecked_ref(),
&{
let mut opts = web_sys::AddEventListenerOptions::new();
+ opts.capture(true);
if desc.passive {
opts.passive(true);
}
@@ -523,6 +524,7 @@ mod tests {
use std::marker::PhantomData;
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};
+ use web_sys::{Event, EventInit};
wasm_bindgen_test_configure!(run_in_browser);
use crate::{html, html::TargetCast, utils::document, AppHandle, Component, Context, Html};
@@ -531,7 +533,7 @@ mod tests {
#[derive(Clone)]
enum Message {
- Click,
+ Action,
StopListening,
SetText(String),
}
@@ -539,7 +541,7 @@ mod tests {
#[derive(Default)]
struct State {
stop_listening: bool,
- clicked: u32,
+ action: u32,
text: String,
}
@@ -554,15 +556,15 @@ mod tests {
{
if state.stop_listening {
html! {
- {state.clicked}
+ {state.action}
}
} else {
html! {
- {state.clicked}
+ {state.action}
}
}
@@ -593,8 +595,8 @@ mod tests {
fn update(&mut self, _: &Context, msg: Self::Message) -> bool {
match msg {
- Message::Click => {
- self.state.clicked += 1;
+ Message::Action => {
+ self.state.action += 1;
}
Message::StopListening => {
self.state.stop_listening = true;
@@ -706,6 +708,47 @@ mod tests {
assert_after_click!(2);
}
+ #[test]
+ async fn non_bubbling_event() {
+ struct NonBubbling;
+
+ impl Mixin for NonBubbling {
+ fn view(ctx: &Context, state: &State) -> Html
+ where
+ C: Component,
+ {
+ let onblur = ctx.link().callback(|_| Message::Action);
+ html! {
+
+ }
+ }
+ }
+
+ let (_, el) = init::("a");
+
+ assert_count(&el, 0);
+
+ let input = document().get_element_by_id("input").unwrap();
+
+ input
+ .dispatch_event(
+ &Event::new_with_event_init_dict("blur", &{
+ let mut dict = EventInit::new();
+ dict.bubbles(false);
+ dict
+ })
+ .unwrap(),
+ )
+ .unwrap();
+
+ assert_count(&el, 1);
+ }
+
#[test]
fn bubbling() {
struct Bubbling;
@@ -719,16 +762,16 @@ mod tests {
html! {
}
} else {
- let cb = ctx.link().callback(|_| Message::Click);
+ let cb = ctx.link().callback(|_| Message::Action);
html! {
}