From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 413FC1FF186 for ; Fri, 29 Aug 2025 15:46:18 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C109F2F68B; Fri, 29 Aug 2025 15:46:28 +0200 (CEST) From: Dominik Csapak To: yew-devel@lists.proxmox.com Date: Fri, 29 Aug 2025 15:46:18 +0200 Message-ID: <20250829134625.2653743-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250829134625.2653743-1-d.csapak@proxmox.com> References: <20250829134625.2653743-1-d.csapak@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.022 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [yew-devel] [PATCH yew-widget-toolkit 2/2] ui: list tile: implement on_activate callback X-BeenThere: yew-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Yew framework devel list at Proxmox List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Yew framework devel list at Proxmox Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: yew-devel-bounces@lists.proxmox.com Sender: "yew-devel" sometimes it's useful to click a full list tile, so implement the `on_activate` callback like we do for e.g. buttons, triggers, etc. Signed-off-by: Dominik Csapak --- src/widget/list/list_tile.rs | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/widget/list/list_tile.rs b/src/widget/list/list_tile.rs index 2613fb1..3c373c3 100644 --- a/src/widget/list/list_tile.rs +++ b/src/widget/list/list_tile.rs @@ -1,10 +1,11 @@ use std::borrow::Cow; -use yew::html::IntoPropValue; +use wasm_bindgen::JsCast; +use yew::html::{IntoEventCallback, IntoPropValue}; use yew::prelude::*; use yew::virtual_dom::VTag; -use crate::props::{ListenersWrapper, WidgetStdProps}; +use crate::props::{EventSubscriber, ListenersWrapper, WidgetBuilder, WidgetStdProps}; use pwt_macros::{builder, widget}; @@ -43,6 +44,11 @@ pub struct ListTile { #[prop_or_default] #[builder(IntoPropValue, into_prop_value)] force_height: Option, + + /// Activate callback (click, enter, space) + #[builder_cb(IntoEventCallback, into_event_callback, Event)] + #[prop_or_default] + on_activate: Option>, } impl ListTile { @@ -61,12 +67,36 @@ impl ListTile { } impl From for VTag { - fn from(val: ListTile) -> Self { + fn from(mut val: ListTile) -> Self { let classes = classes!( "pwt-list-tile", val.interactive.then_some("pwt-interactive"), val.disabled.then_some("disabled") ); + + if !val.disabled { + if let Some(on_activate) = val.on_activate.clone() { + val.set_tabindex(0); + val.add_onclick({ + let on_activate = on_activate.clone(); + move |event: MouseEvent| { + event.stop_propagation(); + on_activate.emit(event.unchecked_into()); + } + }); + val.add_onkeydown({ + let on_activate = on_activate.clone(); + move |event: KeyboardEvent| match event.key().as_str() { + "Enter" | " " => { + event.stop_propagation(); + on_activate.emit(event.unchecked_into()); + } + _ => {} + } + }); + } + } + val.std_props.into_vtag( Cow::Borrowed("div"), Some(classes), -- 2.47.2 _______________________________________________ yew-devel mailing list yew-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel