From 9e276a8879ea7bd4495223dd11c20e66f3a16276 Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Fri, 23 Feb 2024 15:59:42 -0500 Subject: [PATCH] pass on: to components (and lay basis for passing all other attributes) --- TODO.md | 2 +- examples/parent_child/src/lib.rs | 5 +- leptos/src/into_view.rs | 92 ++++-------- next_tuple/src/lib.rs | 73 +++++---- tachys/src/html/attribute/aria.rs | 139 ++++++----------- tachys/src/html/attribute/custom.rs | 27 +++- tachys/src/html/attribute/global.rs | 209 ++++++++++---------------- tachys/src/html/attribute/mod.rs | 145 +++++++++++++++++- tachys/src/html/class.rs | 17 ++- tachys/src/html/element/elements.rs | 13 +- tachys/src/html/element/inner_html.rs | 34 +++-- tachys/src/html/element/mod.rs | 62 ++++---- tachys/src/html/event.rs | 15 ++ tachys/src/html/node_ref.rs | 34 ++++- tachys/src/html/property.rs | 18 ++- tachys/src/html/style.rs | 17 ++- tachys/src/mathml/mod.rs | 12 +- tachys/src/view/add_attr.rs | 30 ++++ tachys/src/view/mod.rs | 27 +--- tachys/src/view/static_types.rs | 17 ++- tachys/src/view/tuples.rs | 91 +++++++++-- 21 files changed, 644 insertions(+), 435 deletions(-) create mode 100644 tachys/src/view/add_attr.rs diff --git a/TODO.md b/TODO.md index 5c758b87d..65408fe26 100644 --- a/TODO.md +++ b/TODO.md @@ -5,7 +5,7 @@ - [x] todomvc - [x] error_boundary - [x] parent\_child - - [ ] on: on components + - [x] on: on components - [ ] router - [ ] slots - [ ] hackernews diff --git a/examples/parent_child/src/lib.rs b/examples/parent_child/src/lib.rs index 79251fe3c..734c9cac9 100644 --- a/examples/parent_child/src/lib.rs +++ b/examples/parent_child/src/lib.rs @@ -53,7 +53,6 @@ pub fn App() -> impl IntoView { // Button B: pass a closure - // TODO -- on:click on components // Button C: use a regular event listener // setting an event listener on a component like this applies it // to each of the top-level elements the component returns @@ -99,10 +98,12 @@ where } } +use leptos::tachys::view::add_attr::AddAnyAttr; + /// Button C is a dummy: it renders a button but doesn't handle /// its click. Instead, the parent component adds an event listener. #[component] -pub fn ButtonC() -> impl IntoView { +pub fn ButtonC() -> impl IntoView + AddAnyAttr { view! {