mirror of
https://github.com/DioxusLabs/dioxus
synced 2025-02-26 12:27:22 +00:00
* add prevent default methods to the event * sync prevent default almost working * sync prevent default working * Move event handling into the runtime * update core tests * restore desktop file dialog * implement prevent default on web * add a hint about the new prevent default method * fix web prevent default * Fix CTRL+click on links * fix values memorize in place test * Fix a few more tests * Add a playwright test for sync prevent default * Fix core doc tests * create a deprecated VirtualDom::handle_event * fix macos imports in desktop * Fix onmounted event * Fix liveview support * switch to RefCell for metadata * Remove println * remove prevent default attribute * remove web specific link behavior * Fix liveview links * more liveview fixes for link * Fix merge conflicts * Fix clippy * use the new prevent default in the file upload example
79 lines
2.1 KiB
Rust
79 lines
2.1 KiB
Rust
use dioxus::prelude::*;
|
|
use dioxus_core::ElementId;
|
|
use std::{any::Any, rc::Rc, sync::Mutex};
|
|
|
|
static CLICKS: Mutex<usize> = Mutex::new(0);
|
|
|
|
#[test]
|
|
fn events_propagate() {
|
|
set_event_converter(Box::new(dioxus::html::SerializedHtmlEventConverter));
|
|
|
|
let mut dom = VirtualDom::new(app);
|
|
dom.rebuild(&mut dioxus_core::NoOpMutations);
|
|
|
|
// Top-level click is registered
|
|
let event = Event::new(
|
|
Rc::new(PlatformEventData::new(Box::<SerializedMouseData>::default())) as Rc<dyn Any>,
|
|
true,
|
|
);
|
|
dom.runtime().handle_event("click", event, ElementId(1));
|
|
assert_eq!(*CLICKS.lock().unwrap(), 1);
|
|
|
|
// break reference....
|
|
for _ in 0..5 {
|
|
dom.mark_dirty(ScopeId(0));
|
|
_ = dom.render_immediate_to_vec();
|
|
}
|
|
|
|
// Lower click is registered
|
|
let event = Event::new(
|
|
Rc::new(PlatformEventData::new(Box::<SerializedMouseData>::default())) as Rc<dyn Any>,
|
|
true,
|
|
);
|
|
dom.runtime().handle_event("click", event, ElementId(2));
|
|
assert_eq!(*CLICKS.lock().unwrap(), 3);
|
|
|
|
// break reference....
|
|
for _ in 0..5 {
|
|
dom.mark_dirty(ScopeId(0));
|
|
_ = dom.render_immediate_to_vec();
|
|
}
|
|
|
|
// Stop propagation occurs
|
|
let event = Event::new(
|
|
Rc::new(PlatformEventData::new(Box::<SerializedMouseData>::default())) as Rc<dyn Any>,
|
|
true,
|
|
);
|
|
dom.runtime().handle_event("click", event, ElementId(2));
|
|
assert_eq!(*CLICKS.lock().unwrap(), 3);
|
|
}
|
|
|
|
fn app() -> Element {
|
|
rsx! {
|
|
div { onclick: move |_| {
|
|
println!("top clicked");
|
|
*CLICKS.lock().unwrap() += 1;
|
|
},
|
|
|
|
{vec![
|
|
rsx! {
|
|
problematic_child {}
|
|
}
|
|
].into_iter()}
|
|
}
|
|
}
|
|
}
|
|
|
|
fn problematic_child() -> Element {
|
|
rsx! {
|
|
button { onclick: move |evt| {
|
|
println!("bottom clicked");
|
|
let mut clicks = CLICKS.lock().unwrap();
|
|
if *clicks == 3 {
|
|
evt.stop_propagation();
|
|
} else {
|
|
*clicks += 1;
|
|
}
|
|
} }
|
|
}
|
|
}
|