Skip to content

Commit c5c482f

Browse files
authored
Checkbox: Add documentation and remove not required function (#10007)
* Iintialize tristate * Control the check_box.check_state always using the set_check_state function Reason: Otherwise the tristate is not handled properly * Handle tristate directly in checkbox * fix documentation
1 parent e3da256 commit c5c482f

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

ui-libraries/material/docs/src/content/docs/components/Checkboxes/check_box.mdx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ A `CheckBox` is a control that allows users to select one or more options from a
2727

2828
### check-state
2929
<SlintProperty propName="check-state" typeName="enum" enumName="CheckState" propertyVisibility="in-out">
30-
The current state of the checkbox. Can be `unchecked`, `partially-checked`, or `checked`.
30+
The current state of the checkbox. Can be `unchecked`, `partially-checked`, or `checked`. If the state is `partially-checked`, the tristate property is set to true.
3131

3232
```slint no-test "check-state: CheckState.checked;"
3333
CheckBox {
@@ -60,7 +60,4 @@ Invoked when the checkbox state changes.
6060
## Functions
6161

6262
### toggle()
63-
Toggles the checkbox state. In tristate mode, cycles through unchecked → partially checked → checked → unchecked.
64-
65-
### set-check-state(check-state: CheckState)
66-
Sets the checkbox state. If the state is `partially-checked`, the tristate property is set to true.
63+
Toggles the checkbox state. In tristate mode, cycles through unchecked → partially checked → checked → unchecked.

ui-libraries/material/docs/src/content/docs/components/Checkboxes/check_box_tile.mdx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ A `CheckBoxTile` is a control that combines a text label with a `CheckBox`. See
2828

2929
### check-state
3030
<SlintProperty propName="check-state" typeName="enum" enumName="CheckState" propertyVisibility="in-out">
31-
The current state of the checkbox. Can be `unchecked`, `partially-checked`, or `checked`.
31+
The current state of the checkbox. Can be `unchecked`, `partially-checked`, or `checked`. If the state is `partially-checked`, the tristate property is set to true.
3232

3333
```slint no-test "check-state: CheckState.checked;"
3434
CheckBoxTile {
@@ -66,7 +66,4 @@ Invoked when the checkbox state changes.
6666
## Functions
6767

6868
### toggle()
69-
Toggles the checkbox state. In tristate mode, cycles through unchecked → partially checked → checked → unchecked.
70-
71-
### set-check-state(check-state: CheckState)
72-
Sets the checkbox state. If the state is `partially-checked`, the tristate property is set to true.
69+
Toggles the checkbox state. In tristate mode, cycles through unchecked → partially checked → checked → unchecked.

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ export component CheckBox {
3535
accessible-action-default => { state_area.clicked(); }
3636
forward_focus: state_area;
3737

38+
init() => {
39+
// Initialize tristate as well
40+
if self.check_state == CheckState.partially-checked {
41+
root.tristate = true;
42+
}
43+
}
44+
3845
state_area := StateLayerArea {
3946
width: 100%;
4047
height: 100%;
@@ -71,6 +78,9 @@ export component CheckBox {
7178
}
7279

7380
changed check_state => {
81+
if self.check_state == CheckState.partially-checked {
82+
root.tristate = true;
83+
}
7484
root.checked_state_changed(root.check_state);
7585
}
7686

@@ -84,10 +94,8 @@ export component CheckBox {
8494
root.check_state == CheckState.partially_checked ? CheckState.unchecked : CheckState.checked;
8595
}
8696

97+
// Keep for backward compatibility
8798
public function set_check_state(check_state: CheckState) {
88-
if check_state == CheckState.partially-checked {
89-
root.tristate = true;
90-
}
9199
root.check_state = check_state;
92100
}
93101

@@ -120,10 +128,15 @@ export component CheckBoxTile inherits ListTile {
120128
}
121129
}
122130

131+
// When clicked on this, but not on the checkbox
132+
// apply the click on the checkbox manually
133+
// So the user can click anywhere in the tile to toggle
134+
// the checkbox
123135
clicked => {
124136
check_box.toggle();
125137
}
126138

139+
// Keep function for backward compatibility
127140
public function set_check_state(check-state: CheckState) {
128141
check_box.set_check_state(check_state);
129142
}

0 commit comments

Comments
 (0)