Skip to content

Commit 63d66d0

Browse files
authored
Switch gains checked_state_changed callback() (#9520)
1 parent 2fc4d46 commit 63d66d0

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

ui-libraries/material/docs/src/content/docs/components/switch.mdx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,9 @@ A tooltip text that appears when hovering over the switch.
6060
## Functions
6161

6262
### toggle()
63-
Toggles the switch state between checked and unchecked.
63+
Toggles the switch state between checked and unchecked.
64+
65+
## Callbacks
66+
67+
### checked_state_changed(checked: bool)
68+
The switch state changed.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export component Switch {
1717
property <bool> has_icon: (root.checked && root.on_icon.width > 0 && root.on_icon.height > 0) || (root.off_icon.width > 0 && root.off_icon.height > 0);
1818
property <color> foreground: root.checked ? MaterialPalette.on_primary_container : MaterialPalette.surface_container_highest;
1919

20+
callback checked_state_changed(checked: bool);
21+
2022
min_width: MaterialStyleMetrics.size_52;
2123
min_height: MaterialStyleMetrics.size_32;
2224

@@ -125,6 +127,10 @@ export component Switch {
125127
root.checked = !root.checked;
126128
}
127129

130+
changed checked => {
131+
root.checked_state_changed(root.checked);
132+
}
133+
128134
states [
129135
disabled when !root.enabled : {
130136
state_layer.display_background: false;

0 commit comments

Comments
 (0)