Skip to main content

Switch

Properties

PropertyTypeDescription
checkedbooleanWhether the switch is checked
defaultCheckedbooleanWhether the switch is checked by default
disabledbooleanWhether the switch is disabled
loadingbooleanWhether the switch is loading
size"default", "small"Size of the switch
autoFocusbooleanWhether the switch has focus
checkedChildrenstring, tableContent displayed in the switch when checked
unCheckedChildrenstring, tableContent 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,
})

image

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.

image

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.

image

size

What size the switch will have, can either be "default" or "small".

image

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":

image

Or a table with icon as a value of a string: checkedChildren = {icon = "QuestionCircleOutlined"}:

image

unCheckedChildren

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