nested_listeners.rs 842 B

12345678910111213141516171819202122232425262728293031323334
  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 cancellation.
  6. use dioxus::prelude::*;
  7. fn main() {
  8. dioxus::launch(app);
  9. }
  10. fn app() -> Element {
  11. rsx! {
  12. div {
  13. onclick: move |_| println!("clicked! top"),
  14. "- div"
  15. button {
  16. onclick: move |_| println!("clicked! bottom propagate"),
  17. "Propagate"
  18. }
  19. button {
  20. onclick: move |evt| {
  21. println!("clicked! bottom no bubbling");
  22. evt.stop_propagation();
  23. },
  24. "Dont propagate"
  25. }
  26. button {
  27. "Does not handle clicks - only propagate"
  28. }
  29. }
  30. }
  31. }