nested_listeners.rs 866 B

1234567891011121314151617181920212223242526272829303132333435
  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. "- div"
  15. button {
  16. onclick: move |_| println!("clicked! bottom propoate"),
  17. "Propogate"
  18. }
  19. button {
  20. onclick: move |evt| {
  21. println!("clicked! bottom no bubbling");
  22. evt.cancel_bubble();
  23. },
  24. "Dont propogate"
  25. }
  26. button {
  27. "Does not handle clicks - only propogate"
  28. }
  29. }
  30. })
  31. }