From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id E6D401FF0B7 for ; Mon, 30 Nov 2026 16:52:25 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 6C8E92094C; Mon, 30 Nov 2026 16:52:25 +0100 (CET) From: Dominik Csapak 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 Message-ID: <20261130155220.3720061-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.246 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: 2JOQHT42TEDAOE6GWW6ZJRH6SKXQCUXD X-Message-ID-Hash: 2JOQHT42TEDAOE6GWW6ZJRH6SKXQCUXD X-MailFrom: d.csapak@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Yew framework devel list at Proxmox List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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! {
{trigger}
}); - } - } - - 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! {
{trigger}
}; if *right { - let outer_class = "pwt-flex-fill-first-child pwt-d-flex pwt-align-self-center"; - select.add_child(html! {
{trigger}
}); + 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! {}); -- 2.47.3