nested_listeners.rs 829 B

123456789101112131415161718192021222324252627282930313233
  1. //! Nested Listeners
  2. //!
  3. //! This example showcases how to control event bubbling from child to parents.
  4. //!
  5. //! Both web and desktop support bubbling and bubble cancelation.
  6. use dioxus::prelude::*;
  7. fn main() {
  8. dioxus::desktop::launch(app);
  9. }
  10. fn app(cx: Scope) -> Element {
  11. cx.render(rsx! {
  12. div {
  13. onclick: move |_| println!("clicked! top"),
  14. button {
  15. onclick: move |_| println!("clicked! bottom propoate"),
  16. "Propogate"
  17. }
  18. button {
  19. onclick: move |evt| {
  20. println!("clicked! bottom no bubbling");
  21. evt.cancel_bubble();
  22. },
  23. "Dont propogate"
  24. }
  25. button {
  26. "Does not handle clicks"
  27. }
  28. }
  29. })
  30. }