From f711249dc086c4dd1e35d4f02d6e1f0412000b08 Mon Sep 17 00:00:00 2001 From: Martin Ball Date: Wed, 18 Nov 2026 22:40:18 +0000 Subject: [PATCH] base-number: a label click focuses the one control in its scope that takes focus, past a unit text beside it --- crates/ui-contract/src/runtime/access/emit.rs | 1 + crates/ui-contract/src/runtime/access/scope.rs | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/ui-contract/src/runtime/access/emit.rs b/crates/ui-contract/src/runtime/access/emit.rs index 527e18d54..6cac465af 100644 --- a/crates/ui-contract/src/runtime/access/emit.rs +++ b/crates/ui-contract/src/runtime/access/emit.rs @@ -328,6 +328,7 @@ pub(crate) fn report(ctx: &Context, own: &Own<'_>) { description: spec.description.clone(), unnamed, inner_stop: None, + focusable: own.focusable, disabled: !own.enabled, }, ); diff --git a/crates/ui-contract/src/runtime/access/scope.rs b/crates/ui-contract/src/runtime/access/scope.rs index 12b8770ae..90fa1dc37 100644 --- a/crates/ui-contract/src/runtime/access/scope.rs +++ b/crates/ui-contract/src/runtime/access/scope.rs @@ -166,6 +166,8 @@ pub(crate) struct ScopeNode { pub unnamed: Option, /// The first focus stop inside a control that has none of its own: where a click on its label moves focus. pub inner_stop: Option, + /// The node takes key focus itself. + pub focusable: bool, /// The control is disabled: a label that names only disabled controls is disabled too. pub disabled: bool, } @@ -576,8 +578,10 @@ pub(crate) fn finish(ctx: &Context, container: Id, merged: Option) { let nodes: Vec<_> = scope.nodes.iter().map(|node| (node.id, node.name.clone(), node.disabled, node.inner_stop.is_some())).collect(); eprintln!("DIAG activation: label {:?} activated, scope nodes {nodes:?}", label.text); } - // A click on a label, as on any form label, moves focus to its one control. - if let (true, [only]) = (label.activated, &scope.nodes[..]) + // A click on a label, as on any form label, moves focus to its one control. A node that takes no focus + // beside it (the unit text after a number field) is not a control the click could mean. + let mut controls = scope.nodes.iter().filter(|node| node.focusable || node.inner_stop.is_some()); + if let (true, Some(only), None) = (label.activated, controls.next(), controls.next()) && !only.disabled { crate::runtime::focus::request(ctx, only.inner_stop.unwrap_or(crate::runtime::focus::FocusTarget::Id(only.id)));