[yew-devel] [PATCH yew-widget-toolkit 4/4] widget: dropdown: use normal input when using rendered values

Dominik Csapak d.csapak at proxmox.com
Thu May 22 13:31:10 CEST 2025


in case we have a renderer for the value of a dropdown, the original
value should not be shown. Type 'hidden' does the job but has a
drawback, default browser behavior regarding label clicks don't work
with it. So instead use a normal input field but hide it via css.

To get the functionality, we have to pass the whole input_props to the
input, not only a select few (most important is 'id', but simply use
all, so we can't forget one).

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/widget/dropdown.rs | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/widget/dropdown.rs b/src/widget/dropdown.rs
index 4f79187..1e1e6f9 100644
--- a/src/widget/dropdown.rs
+++ b/src/widget/dropdown.rs
@@ -369,12 +369,10 @@ impl Component for PwtDropdown {
                 .with_child(rendered_value)
                 .with_child(
                     Input::new()
-                        .name(props.input_props.name.clone())
-                        .disabled(props.input_props.disabled)
-                        .required(props.input_props.required)
+                        .with_input_props(&props.input_props)
                         .onpointerdown(ctx.link().callback(|_| Msg::MouseDownInput))
                         .attribute("value", value)
-                        .attribute("type", "hidden"),
+                        .class("pwt-d-none"), // hide the real input since we render the value ourselves
                 )
                 .onkeydown(onkeydown)
                 .into()
-- 
2.39.5





More information about the yew-devel mailing list