Make it possible to toggle the state of checkboxes via accessibility

This commit is contained in:
Simon Hausmann 2024-05-27 14:47:30 +02:00 committed by Simon Hausmann
parent 28cff6628d
commit b162e9df45
6 changed files with 84 additions and 1 deletions

View file

@ -19,6 +19,7 @@ export component CheckBox {
accessible-label: root.text;
accessible-checked <=> root.checked;
accessible-role: checkbox;
accessible-action-default => { state-layer.clicked(); }
forward-focus: state-layer;
states [

View file

@ -20,6 +20,10 @@ export component CheckBox {
accessible-label: root.text;
accessible-checked <=> root.checked;
accessible-role: checkbox;
accessible-action-default => {
root.checked = !root.checked;
root.toggled();
}
forward-focus: i-focus-scope;
states [

View file

@ -19,6 +19,10 @@ export component CheckBox {
accessible-label: root.text;
accessible-checked <=> root.checked;
accessible-role: checkbox;
accessible-action-default => {
root.checked = !root.checked;
root.toggled();
}
forward-focus: i-focus-scope;
states [

View file

@ -18,6 +18,10 @@ export component CheckBox {
accessible-checkable: true;
accessible-checked <=> root.checked;
accessible-role: checkbox;
accessible-action-default => {
root.checked = !root.checked;
root.toggled();
}
forward-focus: i-focus-scope;
states [

View file

@ -6,4 +6,8 @@ export component CheckBox inherits NativeCheckBox {
accessible-checked <=> root.checked;
accessible-label <=> root.text;
accessible-role: checkbox;
}
accessible-action-default => {
root.checked = !root.checked;
root.toggled();
}
}

View file

@ -0,0 +1,66 @@
// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
import { CheckBox } from "std-widgets.slint";
export component TestCase inherits Window {
in-out property <string> toggled;
in-out property <bool> checked <=> a.checked;
HorizontalLayout {
alignment: start;
a := CheckBox {
text: "Aaa";
toggled => {
root.toggled += "a";
}
}
}
}
/*
```rust
use slint::{SharedString};
let instance = TestCase::new().unwrap();
assert_eq!(instance.get_checked(), false);
let mut result = slint_testing::ElementHandle::find_by_element_id(&instance, "TestCase::a").collect::<Vec<_>>();
assert_eq!(result.len(), 1);
let aaa = result.pop().unwrap();
assert_eq!(aaa.accessible_label().unwrap(), "Aaa");
assert_eq!(aaa.accessible_value(), None);
assert_eq!(aaa.accessible_value_maximum(), None);
assert_eq!(aaa.accessible_value_minimum(), None);
assert_eq!(aaa.accessible_value_step(), None);
assert_eq!(aaa.accessible_checked(), Some(false));
assert_eq!(aaa.accessible_checkable(), Some(true));
aaa.invoke_accessible_default_action();
assert_eq!(instance.get_checked(), true, "CheckBox a was not checked");
assert_eq!(aaa.accessible_checked(), Some(true));
assert_eq!(instance.get_toggled(), SharedString::from("a"));
```
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
auto label_search = slint::testing::ElementHandle::find_by_element_id(handle, "TestCase::a");
assert(label_search.size() == 1);
auto aaa = label_search[0];
assert_eq(aaa.accessible_label().value(), "Aaa");
assert(!aaa.accessible_value());
assert(!aaa.accessible_value_maximum());
assert(!aaa.accessible_value_minimum());
assert(!aaa.accessible_value_step());
assert_eq(aaa.accessible_checked().value(), false);
assert_eq(aaa.accessible_checkable().value(), true);
aaa.invoke_accessible_default_action();
assert_eq(instance.get_checked(), true);
assert_eq(aaa.accessible_checked().value(), true);
assert_eq(instance.get_toggled(), "a");
```
*/