Switch
Properties
Property | Type | Description |
---|---|---|
checked | boolean | Whether the switch is checked |
defaultChecked | boolean | Whether the switch is checked by default |
disabled | boolean | Whether the switch is disabled |
loading | boolean | Whether the switch is loading |
size | "default", "small" | Size of the switch |
autoFocus | boolean | Whether the switch has focus |
checkedChildren | string, table | Content displayed in the switch when checked |
unCheckedChildren | string, table | Content displayed in the switch when unchecked |
Ant Design Switch | ||
List of Icons |
Children
Switch does not support children.
Example
local switch = myUI:createElement("Switch", {
checkedChildren = "On",
unCheckedChildren = {icon = "QuestionCircleOutlined"},
onChange = function(_, _, checked, event)
print("onChange: ", checked, json.encode(event))
end,
onClick = function(_, _, checked, event)
print("onClick: ", checked, json.encode(event))
end,
})
checked
Weather the switch is checked, when you set this you'll have to handle the checking/unchecking of the switch yourself.
Luckily thats very simple:local switch; switch = myUI:createElement("Switch", {
checked = true,
onChange = function(_, _, checked, event)
switch.checked = checked
-- Your code here
end,
})
defaultChecked
Weather the switched is checked by default.
disabled
Weather the switch is disabled, when disabled the user can not interact with it.

loading
Weather the switch is loading, when true the switch will have a loading icon.
User will be unable to interact with the switch when true.
size
What size the switch will have, can either be "default" or "small".

autoFocus
Weather the switch will have focus when displayed to the user.
checkedChildren
What is displayed within the switch when it's checked.
Can be either a string:checkedChildren = "ON"
:

checkedChildren = {icon = "QuestionCircleOutlined"}
:

unCheckedChildren
Same as the checkedChildren, but it's what's displayed when the switch is unchecked.