From b4aa514653fdf0140f7b548eb9f917a34d8389ea Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Sat, 20 Jun 2026 15:50:58 -0600 Subject: [PATCH] feat(slint-a11y): add keyboard focus rings to shared interactive primitives Give SecondaryButton, ToggleButton, CircleAction, QbzCheckbox, QbzToggle and QbzSelect a keyboard FocusScope (Enter/Space trigger the same action as a click) plus a non-layout focus-ring overlay: a sibling Rectangle with a transparent-default 2px border that turns Theme.focus-ring only when the scope has keyboard focus, with its radius matched to the control (circle for CircleAction) so focus never reflows the layout. The existing TouchArea stays the pointer source on every control; the FocusScope only adds key activation and focusability. Universal: the ring is a per-theme token and only appears on keyboard focus, so it stays visually neutral at rest across all 33 themes (WCAG 2.4.7 focus-visible). cc --- .../ui/primitives/CircleAction.slint | 26 +++++++++++++++++ .../qbz-slint/ui/primitives/QbzCheckbox.slint | 26 +++++++++++++++++ .../qbz-slint/ui/primitives/QbzSelect.slint | 28 +++++++++++++++++++ .../qbz-slint/ui/primitives/QbzToggle.slint | 26 +++++++++++++++++ .../ui/primitives/SecondaryButton.slint | 26 +++++++++++++++++ .../ui/primitives/ToggleButton.slint | 25 +++++++++++++++++ 6 files changed, 157 insertions(+) diff --git a/crates/qbz-slint/ui/primitives/CircleAction.slint b/crates/qbz-slint/ui/primitives/CircleAction.slint index db82ae23a..8109c4a19 100644 --- a/crates/qbz-slint/ui/primitives/CircleAction.slint +++ b/crates/qbz-slint/ui/primitives/CircleAction.slint @@ -62,6 +62,32 @@ export component CircleAction inherits Rectangle { y: Math.round((parent.height - self.height) / 2 / 1px) * 1px; } + // Keyboard activation: Enter/Space fire the same click. The TouchArea below + // stays the pointer source; this only adds key activation + focusability. + fs := FocusScope { + enabled: root.enabled; + key-pressed(event) => { + if (event.text == Key.Return || event.text == " ") { + root.clicked(); + return accept; + } + return reject; + } + } + + // Non-layout focus ring — transparent-bordered overlay shown only on + // keyboard focus, circular to match the button so it never reflows. + Rectangle { + x: 0; + y: 0; + width: parent.width; + height: parent.height; + background: transparent; + border-width: 2px; + border-color: fs.has-focus ? Theme.focus-ring : transparent; + border-radius: root.diameter / 2; + } + ta := TouchArea { mouse-cursor: root.enabled ? pointer : default; clicked => { diff --git a/crates/qbz-slint/ui/primitives/QbzCheckbox.slint b/crates/qbz-slint/ui/primitives/QbzCheckbox.slint index ed3128b6b..77a4ae0e5 100644 --- a/crates/qbz-slint/ui/primitives/QbzCheckbox.slint +++ b/crates/qbz-slint/ui/primitives/QbzCheckbox.slint @@ -31,4 +31,30 @@ export component QbzCheckbox inherits Rectangle { root.toggled(); } } + + // Keyboard activation: Enter/Space toggle the box, same as a click. The + // TouchArea stays the pointer source; this only adds key activation + focus. + fs := FocusScope { + key-pressed(event) => { + if (event.text == Key.Return || event.text == " ") { + root.checked = !root.checked; + root.toggled(); + return accept; + } + return reject; + } + } + + // Non-layout focus ring — transparent-bordered overlay shown only on + // keyboard focus, so it never reflows the checkbox. + Rectangle { + x: 0; + y: 0; + width: parent.width; + height: parent.height; + background: transparent; + border-width: 2px; + border-color: fs.has-focus ? Theme.focus-ring : transparent; + border-radius: parent.border-radius; + } } diff --git a/crates/qbz-slint/ui/primitives/QbzSelect.slint b/crates/qbz-slint/ui/primitives/QbzSelect.slint index 1d8be8782..4aa80d7d5 100644 --- a/crates/qbz-slint/ui/primitives/QbzSelect.slint +++ b/crates/qbz-slint/ui/primitives/QbzSelect.slint @@ -155,6 +155,34 @@ export component QbzSelect inherits Rectangle { } } + // Keyboard activation: Enter/Space open the option list, same as a click. + // The TouchArea stays the pointer source; this only adds key activation + + // focusability on the collapsed control. + fs := FocusScope { + enabled: root.enabled; + key-pressed(event) => { + if (event.text == Key.Return || event.text == " ") { + root.filter = ""; + popup.show(); + return accept; + } + return reject; + } + } + + // Non-layout focus ring — transparent-bordered overlay shown only on + // keyboard focus, matching the control's radius so it never reflows. + Rectangle { + x: 0; + y: 0; + width: parent.width; + height: parent.height; + background: transparent; + border-width: 2px; + border-color: fs.has-focus ? Theme.focus-ring : transparent; + border-radius: parent.border-radius; + } + popup := PopupWindow { // Right-anchored so a list wider than the control grows leftward // and stays on-screen. diff --git a/crates/qbz-slint/ui/primitives/QbzToggle.slint b/crates/qbz-slint/ui/primitives/QbzToggle.slint index b6e123034..c9b3d7f0b 100644 --- a/crates/qbz-slint/ui/primitives/QbzToggle.slint +++ b/crates/qbz-slint/ui/primitives/QbzToggle.slint @@ -35,4 +35,30 @@ export component QbzToggle inherits Rectangle { } } } + + // Keyboard activation: Enter/Space flip the switch, same as a click. The + // TouchArea stays the pointer source; this only adds key activation + focus. + fs := FocusScope { + enabled: root.enabled; + key-pressed(event) => { + if (event.text == Key.Return || event.text == " ") { + root.toggled(!root.checked); + return accept; + } + return reject; + } + } + + // Non-layout focus ring — transparent-bordered overlay shown only on + // keyboard focus, matching the switch's pill radius so it never reflows. + Rectangle { + x: 0; + y: 0; + width: parent.width; + height: parent.height; + background: transparent; + border-width: 2px; + border-color: fs.has-focus ? Theme.focus-ring : transparent; + border-radius: parent.border-radius; + } } diff --git a/crates/qbz-slint/ui/primitives/SecondaryButton.slint b/crates/qbz-slint/ui/primitives/SecondaryButton.slint index 9a0d762d1..881521488 100644 --- a/crates/qbz-slint/ui/primitives/SecondaryButton.slint +++ b/crates/qbz-slint/ui/primitives/SecondaryButton.slint @@ -47,4 +47,30 @@ export component SecondaryButton inherits Rectangle { } } } + + // Keyboard activation: Enter/Space fire the same click. The TouchArea stays + // the pointer source; this only adds key activation + focusability. + fs := FocusScope { + enabled: root.enabled; + key-pressed(event) => { + if (event.text == Key.Return || event.text == " ") { + root.clicked(); + return accept; + } + return reject; + } + } + + // Non-layout focus ring — transparent-bordered overlay shown only on + // keyboard focus, so it never reflows the button. + Rectangle { + x: 0; + y: 0; + width: parent.width; + height: parent.height; + background: transparent; + border-width: 2px; + border-color: fs.has-focus ? Theme.focus-ring : transparent; + border-radius: parent.border-radius; + } } diff --git a/crates/qbz-slint/ui/primitives/ToggleButton.slint b/crates/qbz-slint/ui/primitives/ToggleButton.slint index 3eec061ea..2d044c7cb 100644 --- a/crates/qbz-slint/ui/primitives/ToggleButton.slint +++ b/crates/qbz-slint/ui/primitives/ToggleButton.slint @@ -36,4 +36,29 @@ export component ToggleButton inherits Rectangle { root.clicked(); } } + + // Keyboard activation: Enter/Space fire the same click. The TouchArea stays + // the pointer source; this only adds key activation + focusability. + fs := FocusScope { + key-pressed(event) => { + if (event.text == Key.Return || event.text == " ") { + root.clicked(); + return accept; + } + return reject; + } + } + + // Non-layout focus ring — transparent-bordered overlay shown only on + // keyboard focus, so it never reflows the toggle. + Rectangle { + x: 0; + y: 0; + width: parent.width; + height: parent.height; + background: transparent; + border-width: 2px; + border-color: fs.has-focus ? Theme.focus-ring : transparent; + border-radius: parent.border-radius; + } }