From 889b0481badf75b1453b9e73429ca6b4961304cd Mon Sep 17 00:00:00 2001 From: Stig Johan Berggren Date: Tue, 5 May 2020 12:44:26 +0200 Subject: [PATCH 1/3] Add class, id and placeholder properties to Select --- yew-components/src/select.rs | 45 ++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/yew-components/src/select.rs b/yew-components/src/select.rs index 1e1a003993a..d59543ea9b3 100644 --- a/yew-components/src/select.rs +++ b/yew-components/src/select.rs @@ -66,6 +66,15 @@ pub struct Props { /// Options are available to choose. #[prop_or_default] pub options: Vec, + /// Classes applied to the `` tag + #[prop_or_default] + pub id: String, + /// Placeholder value, shown at the top as a disabled option + #[prop_or(String::from("↪"))] + pub placeholder: String, /// Callback to handle changes. pub on_change: Callback, } @@ -124,9 +133,15 @@ where }; html! { - { for self.props.options.iter().map(view_option) } @@ -160,4 +175,30 @@ mod tests { on_change=on_change /> }; } + + #[test] + fn can_create_select_with_class() { + let on_change = Callback::::default(); + let class = "form-control"; + html! { + on_change=on_change classes=class /> + }; + } + + #[test] + fn can_create_select_with_id() { + let on_change = Callback::::default(); + let id = "test-select"; + html! { + on_change=on_change id=id /> + }; + } + + #[test] + fn can_create_select_with_placeholder() { + let on_change = Callback::::default(); + html! { + on_change=on_change placeholder="--Please choose an option--" /> + }; + } } From e0603915fb32814894cfa5f80eea7867a922c43f Mon Sep 17 00:00:00 2001 From: Stig Johan Berggren Date: Tue, 5 May 2020 12:50:28 +0200 Subject: [PATCH 2/3] Inline attributes --- yew-components/src/select.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/yew-components/src/select.rs b/yew-components/src/select.rs index d59543ea9b3..bdeb3e15e61 100644 --- a/yew-components/src/select.rs +++ b/yew-components/src/select.rs @@ -179,18 +179,16 @@ mod tests { #[test] fn can_create_select_with_class() { let on_change = Callback::::default(); - let class = "form-control"; html! { - on_change=on_change classes=class /> + on_change=on_change classes="form-control" /> }; } #[test] fn can_create_select_with_id() { let on_change = Callback::::default(); - let id = "test-select"; html! { - on_change=on_change id=id /> + on_change=on_change id="test-select" /> }; } From 3411bba898aa32179774a05e97984e2ae8305782 Mon Sep 17 00:00:00 2001 From: Stig Johan Berggren Date: Wed, 6 May 2020 11:52:56 +0200 Subject: [PATCH 3/3] Rename classes to class --- yew-components/src/select.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yew-components/src/select.rs b/yew-components/src/select.rs index bdeb3e15e61..45f983bac34 100644 --- a/yew-components/src/select.rs +++ b/yew-components/src/select.rs @@ -68,7 +68,7 @@ pub struct Props { pub options: Vec, /// Classes applied to the `` tag #[prop_or_default] pub id: String, @@ -136,7 +136,7 @@ where