From: Dominik Csapak <d.csapak@proxmox.com>
To: yew-devel@lists.proxmox.com
Subject: [PATCH yew-widget-toolkit] widget: dropdown: keep the input element when the triggers change
Date: Mon, 30 Nov 2026 16:49:53 +0100 [thread overview]
Message-ID: <20261130155220.3720061-1-d.csapak@proxmox.com> (raw)
Since the triggers were added as direct siblings of the input element,
adding or removing one changes the number of children. Yew matches
unkeyed children from the end, so it reuses the input element for the
new trigger and creates a new input element, which loses the focus.
This happens for example with a non-editable selector without the
'required' flag: after picking a value, it adds its clear trigger and
the focus goes to the document body. Components that react to the
focus leaving them, like a popup that closes then, behave as if the
user clicked somewhere else.
To fix that, wrap the triggers in 'display: contents' containers, like
the field already does, so the number of children stays the same.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/widget/dropdown.rs | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/src/widget/dropdown.rs b/src/widget/dropdown.rs
index 68ec2c3..9463b5d 100644
--- a/src/widget/dropdown.rs
+++ b/src/widget/dropdown.rs
@@ -519,22 +519,25 @@ impl Component for PwtDropdown {
})
.onclick(onclick);
- for (trigger, right) in &props.trigger {
- if !right {
- let outer_class = "pwt-flex-fill-first-child pwt-d-flex pwt-align-self-center";
- select.add_child(html! {<div class={outer_class}>{trigger}</div>});
- }
- }
-
- select.add_child(input);
+ // Always create the same children, so that adding a trigger (e.g. the clear trigger of a
+ // selector) does not replace the input element, which would lose the focus.
+ let mut left_triggers = Container::new().style("display", "contents");
+ let mut right_triggers = Container::new().style("display", "contents");
for (trigger, right) in &props.trigger {
+ let outer_class = "pwt-flex-fill-first-child pwt-d-flex pwt-align-self-center";
+ let trigger = html! {<div class={outer_class}>{trigger}</div>};
if *right {
- let outer_class = "pwt-flex-fill-first-child pwt-d-flex pwt-align-self-center";
- select.add_child(html! {<div class={outer_class}>{trigger}</div>});
+ right_triggers.add_child(trigger);
+ } else {
+ left_triggers.add_child(trigger);
}
}
+ select.add_child(left_triggers);
+ select.add_child(input);
+ select.add_child(right_triggers);
+
select
.add_child(html! {<i onclick={trigger_onclick} tabindex="-1" class={trigger_cls}></i>});
--
2.47.3
next reply other threads:[~2026-11-30 15:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 15:49 Dominik Csapak [this message]
2026-12-01 8:05 ` applied: [PATCH yew-widget-toolkit] widget: dropdown: keep the input element when the triggers change Dietmar Maurer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130155220.3720061-1-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=yew-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.