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 4F86E1FF09F for ; Tue, 01 Dec 2026 09:06:00 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id D2549209A0; Tue, 01 Dec 2026 09:05:59 +0100 (CET) Message-ID: <957f2a59-c1dd-4db2-b3be-9776f75e2183@proxmox.com> Date: Tue, 1 Dec 2026 09:05:54 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: applied: [PATCH yew-widget-toolkit] widget: dropdown: keep the input element when the triggers change To: Dominik Csapak , yew-devel@lists.proxmox.com References: <20261130155220.3720061-1-d.csapak@proxmox.com> Content-Language: en-US From: Dietmar Maurer In-Reply-To: <20261130155220.3720061-1-d.csapak@proxmox.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1796112354959 X-SPAM-LEVEL: Spam detection results: 0 AWL 1.835 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: AR6AXUAISG7FQFJ2IWQUPSCOTQVWRIQ6 X-Message-ID-Hash: AR6AXUAISG7FQFJ2IWQUPSCOTQVWRIQ6 X-MailFrom: dietmar@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: applied On 11/30/26 4:52 PM, Dominik Csapak wrote: > 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! {}); >