Skip to content

Commit 1d0399c

Browse files
authored
[switch] fix accessible_default_action when switch is disabled (#10174)
1 parent 710f0c1 commit 1d0399c

File tree

7 files changed

+38
-11
lines changed

7 files changed

+38
-11
lines changed

internal/compiler/widgets/cosmic/switch.slint

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ export component Switch {
3333
accessible-checked <=> root.checked;
3434
accessible-role: switch;
3535
accessible-action-default => {
36-
root.checked = !root.checked;
37-
root.toggled();
36+
if(root.enabled) {
37+
root.checked = !root.checked;
38+
root.toggled();
39+
}
3840
}
3941
forward-focus: state-layer;
4042

internal/compiler/widgets/cupertino/switch.slint

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ export component Switch {
3434
accessible-checked <=> root.checked;
3535
accessible-role: switch;
3636
accessible-action-default => {
37-
root.checked = !root.checked;
38-
root.toggled();
37+
if (root.enabled) {
38+
root.checked = !root.checked;
39+
root.toggled();
40+
}
3941
}
4042
forward-focus: i-focus-scope;
4143

internal/compiler/widgets/fluent/switch.slint

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ export component Switch {
3333
accessible-checked <=> root.checked;
3434
accessible-role: switch;
3535
accessible-action-default => {
36-
root.checked = !root.checked;
37-
root.toggled();
36+
if(root.enabled) {
37+
root.checked = !root.checked;
38+
root.toggled();
39+
}
3840
}
3941
forward-focus: focus-scope;
4042

internal/compiler/widgets/material/switch.slint

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ export component Switch {
3030
accessible-checked <=> root.checked;
3131
accessible-role: switch;
3232
accessible-action-default => {
33-
root.checked = !root.checked;
34-
root.toggled();
33+
if(root.enabled) {
34+
root.checked = !root.checked;
35+
root.toggled();
36+
}
3537
}
3638

3739
states [

internal/compiler/widgets/qt/switch.slint

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ export component Switch inherits NativeCheckBox {
88
accessible-label <=> root.text;
99
accessible-role: switch;
1010
accessible-action-default => {
11-
root.checked = !root.checked;
12-
root.toggled();
11+
if(root.enabled) {
12+
root.checked = !root.checked;
13+
root.toggled();
14+
}
1315
}
1416
}

tests/cases/widgets/switch.slint

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export component TestCase inherits Window {
66

77
in-out property <string> toggled;
88
in-out property <bool> checked <=> a.checked;
9+
in-out property <bool> enabled <=> a.enabled;
910

1011
HorizontalLayout {
1112
alignment: start;
@@ -40,6 +41,15 @@ aaa.invoke_accessible_default_action();
4041
assert_eq!(instance.get_checked(), true, "Switch a was not checked");
4142
assert_eq!(aaa.accessible_checked(), Some(true));
4243
assert_eq!(instance.get_toggled(), SharedString::from("a"));
44+
45+
assert_eq!(aaa.accessible_enabled(), Some(true));
46+
instance.set_enabled(false);
47+
assert_eq!(aaa.accessible_enabled(), Some(false));
48+
assert_eq!(instance.get_toggled(), SharedString::from("a"));
49+
50+
aaa.invoke_accessible_default_action();
51+
assert_eq!(instance.get_toggled(), SharedString::from("a"));
52+
4353
```
4454
4555
```cpp
@@ -61,6 +71,13 @@ assert_eq(instance.get_checked(), true);
6171
assert_eq(aaa.accessible_checked().value(), true);
6272
assert_eq(instance.get_toggled(), "a");
6373
74+
assert_eq(aaa.accessible_enabled().value(), true);
75+
76+
instance.set_enabled(false);
77+
assert_eq(aaa.accessible_enabled().value(), false);
78+
assert_eq(instance.get_toggled(), "a");
79+
aaa.invoke_accessible_default_action();
80+
assert_eq(instance.get_toggled(), "a");
6481
```
6582
6683
*/

ui-libraries/material/src/ui/components/switch.slint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export component Switch {
2626
accessible-checkable: true;
2727
accessible-checked <=> root.checked;
2828
accessible-role: switch;
29-
accessible-action-default => { touch_area.clicked(); }
29+
accessible-action-default => { if(root.enabled) {touch_area.clicked();} }
3030
forward_focus: touch_area;
3131

3232
touch_area := FocusTouchArea {

0 commit comments

Comments
 (0)