diff --git a/crates/ui-contract/src/runtime/access/emit.rs b/crates/ui-contract/src/runtime/access/emit.rs index c63b4a0bf..ac4172e37 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 999882d85..090008904 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, } @@ -572,8 +574,10 @@ pub(crate) fn finish(ctx: &Context, container: Id, merged: Option) { let named = patches.iter().any(|patch| matches!(patch, LabelPatch::LabelledBy { node: id, .. } if *id == node.id)); report_unnamed(ctx, node.unnamed.clone().filter(|_| !named)); } - // 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)));