SwitchButton
A Switch represents a button with two states, on and off. Switches are most often used on mobile devices to enable and disable options.
Selector
smart-switch-button
Properties
mousedown
event). release – The switch state changes only when the mouse button is released (mouseup
event), after a complete click. pressAndRelease – The switch state changes on mousedown
, and automatically reverts to the original state on mouseup
.Note: This property is effective only when switchMode
is set to 'click'
.Events
Properties
animation"none" | "simple" | "advanced"
Sets or retrieves the current animation mode. When this property is set to 'none', all animations are disabled. For other valid values, the corresponding animation effects will be enabled according to the specified mode.
Allowed Values
- "none" - animation is disabled
- "simple" - ripple animation is disabled
- "advanced" - all animations are enabled
Default value
"advanced"Example
Set the animation property.
<smart-switch-button animation='none'></smart-switch-button>
Set the animation property by using the HTML Element's instance.
const switchbutton = document.querySelector('smart-switch-button');
switchbutton.animation = 'simple';
Get the animation property.
const switchbutton = document.querySelector('smart-switch-button');
let animation = switchbutton.animation;
clickMode"press" | "release" | "pressAndRelease"
Specifies how the switch button responds to user interaction when the switchMode is set to 'click'. This property determines the exact mouse action that triggers a change in the switch’s state:
- press – The switch state changes immediately when the mouse button is pressed down (
mousedown
event). - release – The switch state changes only when the mouse button is released (
mouseup
event), after a complete click. - pressAndRelease – The switch state changes on
mousedown
, and automatically reverts to the original state onmouseup
.
Note: This property is effective only when
switchMode
is set to 'click'
.
Default value
"release"Example
Set the clickMode property.
<smart-switch-button click-mode='press'></smart-switch-button>
Set the clickMode property by using the HTML Element's instance.
const switchbutton = document.querySelector('smart-switch-button');
switchbutton.clickMode = 'pressAndRelease';
Get the clickMode property.
const switchbutton = document.querySelector('smart-switch-button');
let clickMode = switchbutton.clickMode;
checkedboolean
Sets the check state to indicate whether the item is checked, unchecked, or indeterminate; or retrieves the current check state of the item.
Default value
falseExample
Set the checked property.
<smart-switch-button checked></smart-switch-button>
Set the checked property by using the HTML Element's instance.
const switchbutton = document.querySelector('smart-switch-button');
switchbutton.checked = false;
Get the checked property.
const switchbutton = document.querySelector('smart-switch-button');
let checked = switchbutton.checked;
disabledboolean
Controls whether the ratio button is displayed and can be interacted with by the user. Set to true to show and enable the button, or false to hide or disable it.
Default value
falseExample
Set the disabled property.
<smart-switch-button disabled></smart-switch-button>
Set the disabled property by using the HTML Element's instance.
const switchbutton = document.querySelector('smart-switch-button');
switchbutton.disabled = false;
Get the disabled property.
const switchbutton = document.querySelector('smart-switch-button');
let disabled = switchbutton.disabled;
falseContentstring
Defines the text label or string that will be displayed when the checked property is set to false, representing the unchecked state of the component or element.
Default value
""""Example
Set the falseContent property.
<smart-switch-button false-content='OFF'></smart-switch-button>
Set the falseContent property by using the HTML Element's instance.
const switchbutton = document.querySelector('smart-switch-button');
switchbutton.falseContent = 'False';
Get the falseContent property.
const switchbutton = document.querySelector('smart-switch-button');
let falseContent = switchbutton.falseContent;
falseTemplateany
Defines a custom template that is displayed when the component is in the false state. This template allows you to specify the content or layout shown when the evaluated condition is false.
Example
Set the falseTemplate property.
<smart-switch-button false-template='templateId1'></smart-switch-button>
Set the falseTemplate property by using the HTML Element's instance.
const switchbutton = document.querySelector('smart-switch-button');
switchbutton.falseTemplate = templateId2;
Get the falseTemplate property.
const switchbutton = document.querySelector('smart-switch-button');
let falseTemplate = switchbutton.falseTemplate;
indeterminateboolean
Controls whether the switch is in an indeterminate state or retrieves its current indeterminate status. When set to true, the switch appears visually distinct to indicate that its state is neither clearly on nor off. This is typically used to represent a partial or mixed selection.
Default value
falseExample
Set the indeterminate property.
<smart-switch-button indeterminate></smart-switch-button>
Set the indeterminate property by using the HTML Element's instance.
const switchbutton = document.querySelector('smart-switch-button');
switchbutton.indeterminate = false;
Get the indeterminate property.
const switchbutton = document.querySelector('smart-switch-button');
let indeterminate = switchbutton.indeterminate;
invertedboolean
Specifies the direction in which the switch toggles between states. If set to true, the positions of the switch states are inverted, meaning the ON and OFF positions are swapped.
Default value
falseExample
Set the inverted property.
<smart-switch-button inverted></smart-switch-button>
Set the inverted property by using the HTML Element's instance.
const switchbutton = document.querySelector('smart-switch-button');
switchbutton.inverted = false;
Get the inverted property.
const switchbutton = document.querySelector('smart-switch-button');
let inverted = switchbutton.inverted;
unlockKeystring
Retrieves or assigns the unlockKey value, which serves as a credential to enable access to the product’s locked features or functionality.
Default value
""Example
Set the unlockKey property.
<smart-switch-button unlock-key=''></smart-switch-button>
Set the unlockKey property by using the HTML Element's instance.
const switchbutton = document.querySelector('smart-switch-button');
switchbutton.unlockKey = '1111-2222-3333-4444-5555';
Get the unlockKey property.
const switchbutton = document.querySelector('smart-switch-button');
let unlockKey = switchbutton.unlockKey;
localestring
Specifies or retrieves the current language code (e.g., 'en', 'fr', 'es'). This property determines which language is used for message localization when working with the messages property. Setting this value ensures the corresponding localized messages are displayed or accessed appropriately.
Default value
"en"Example
Set the locale property.
<smart-switch-button locale='de'></smart-switch-button>
Set the locale property by using the HTML Element's instance.
const switchbutton = document.querySelector('smart-switch-button');
switchbutton.locale = 'fr';
Get the locale property.
const switchbutton = document.querySelector('smart-switch-button');
let locale = switchbutton.locale;
localizeFormatFunctionfunction | null
Callback function associated with the localization module. This callback is invoked whenever localization-related events occur, such as changes in language, region settings, or translation updates. It enables the module to respond dynamically to localization changes in the application.
Example
Set the localizeFormatFunction property.
<smart-switch-button localize-format-function='function(){return '...'}'></smart-switch-button>
Set the localizeFormatFunction property by using the HTML Element's instance.
const switchbutton = document.querySelector('smart-switch-button');
switchbutton.localizeFormatFunction = function(){return '...'};
Get the localizeFormatFunction property.
const switchbutton = document.querySelector('smart-switch-button');
let localizeFormatFunction = switchbutton.localizeFormatFunction;
messagesobject
Defines an object that maps password strength states (e.g., weak, medium, strong) to their corresponding string values or messages. This allows for customized labels or feedback to be displayed to users based on the evaluated password strength.
Default value
"en": {
"propertyUnknownType": "'{{name}}' property is with undefined 'type' member!",
"propertyInvalidValue": "Invalid '{{name}}' property value! Actual value: {{actualValue}}, Expected value: {{value}}!",
"propertyInvalidValueType": "Invalid '{{name}}' property value type! Actual type: {{actualType}}, Expected type: {{type}}!",
"elementNotInDOM": "Element does not exist in DOM! Please, add the element to the DOM, before invoking a method.",
"moduleUndefined": "Module is undefined.",
"missingReference": "{{elementType}}: Missing reference to {{files}}.",
"htmlTemplateNotSuported": "{{elementType}}: Browser doesn't support HTMLTemplate elements.",
"invalidTemplate": "{{elementType}}: '{{property}}' property accepts a string that must match the id of an HTMLTemplate element from the DOM."
}
Example
Set the messages property.
<smart-switch-button messages='{"de":{"propertyUnknownType":"Die Eigenschaft '{{name}}' hat ein nicht definiertes 'type'-Member!","propertyInvalidValue":"Ungultiger Eigenschaftswert '{{name}}'! Aktueller Wert: {{actualValue}}, Erwarteter Wert: {{value}}!","propertyInvalidValueType":"Ungultiger Eigenschaftswert '{{name}}'! Aktueller Wert: {{actualType}}, Erwarteter Wert: {{type}}!","elementNotInDOM":"Element existiert nicht in DOM! Bitte fugen Sie das Element zum DOM hinzu, bevor Sie eine Methode aufrufen.","moduleUndefined":"Modul ist nicht definiert.","missingReference":"{{elementType}}: Fehlender Verweis auf {{files}}.","htmlTemplateNotSuported":"{{elementType}}: Browser unterstutzt keine HTMLTemplate-Elemente.","invalidTemplate":"{{elementType}}: '{{property}}' Die Eigenschaft akzeptiert eine Zeichenfolge, die mit der ID eines HTMLTemplate-Elements aus dem DOM ubereinstimmen muss."}}'></smart-switch-button>
Set the messages property by using the HTML Element's instance.
const switchbutton = document.querySelector('smart-switch-button');
switchbutton.messages = {"en":{"propertyUnknownType":"'{{name}}' property is with undefined 'type' member!","propertyInvalidValue":"Invalid '{{name}}' property value! Actual value: {{actualValue}}, Expected value: {{value}}!","propertyInvalidValueType":"Invalid '{{name}}' property value type! Actual type: {{actualType}}, Expected type: {{type}}!","elementNotInDOM":"Element does not exist in DOM! Please, add the element to the DOM, before invoking a method.","moduleUndefined":"Module is undefined.","missingReference":"{{elementType}}: Missing reference to {{files}}.","htmlTemplateNotSuported":"{{elementType}}: Browser doesn't support HTMLTemplate elements.","invalidTemplate":"{{elementType}}: '{{property}}' property accepts a string that must match the id of an HTMLTemplate element from the DOM."}};
Get the messages property.
const switchbutton = document.querySelector('smart-switch-button');
let messages = switchbutton.messages;
namestring
Retrieves the current name of the widget or assigns a new name to the widget. This property can be used to identify or reference the widget programmatically.
Default value
""""Example
Set the name property.
<smart-switch-button name='Name'></smart-switch-button>
Set the name property by using the HTML Element's instance.
const switchbutton = document.querySelector('smart-switch-button');
switchbutton.name = 'New Name';
Get the name property.
const switchbutton = document.querySelector('smart-switch-button');
let name = switchbutton.name;
orientation"horizontal" | "vertical"
Specifies the layout direction of the switch component, determining whether it is displayed horizontally or vertically. Use this property to control how the switch and its label are arranged within the user interface.
Default value
"horizontal"Example
Set the orientation property.
<smart-switch-button orientation='vertical'></smart-switch-button>
Set the orientation property by using the HTML Element's instance.
const switchbutton = document.querySelector('smart-switch-button');
switchbutton.orientation = 'horizontal';
Get the orientation property.
const switchbutton = document.querySelector('smart-switch-button');
let orientation = switchbutton.orientation;
readonlyboolean
When the custom element is set to readonly, users will not be able to modify its content or trigger any interactive behaviors such as editing, selecting, or submitting data through the element. However, the element remains visible and its value can still be programmatically accessed or updated by scripts.
Default value
falseExample
Set the readonly property.
<smart-switch-button readonly></smart-switch-button>
Set the readonly property by using the HTML Element's instance.
const switchbutton = document.querySelector('smart-switch-button');
switchbutton.readonly = false;
Get the readonly property.
const switchbutton = document.querySelector('smart-switch-button');
let readonly = switchbutton.readonly;
trueContentstring
Specifies the text label or value that will be displayed when the checked property is set to true. This text represents the state of the component when it is selected or activated.
Default value
""""Example
Set the trueContent property.
<smart-switch-button true-content='ON'></smart-switch-button>
Set the trueContent property by using the HTML Element's instance.
const switchbutton = document.querySelector('smart-switch-button');
switchbutton.trueContent = 'True';
Get the trueContent property.
const switchbutton = document.querySelector('smart-switch-button');
let trueContent = switchbutton.trueContent;
trueTemplatestring
Defines a custom template to display when the state is true, allowing you to specify how content should appear in this condition.
Default value
"null"Example
Set the trueTemplate property.
<smart-switch-button true-template='templateId1'></smart-switch-button>
Set the trueTemplate property by using the HTML Element's instance.
const switchbutton = document.querySelector('smart-switch-button');
switchbutton.trueTemplate = 'templateId2';
Get the trueTemplate property.
const switchbutton = document.querySelector('smart-switch-button');
let trueTemplate = switchbutton.trueTemplate;
switchMode"default" | "click" | "drag" | "none"
Configures how users can interact with the switch element to change its state. The switchMode property accepts the following options:
- default – The switch state can be toggled either by dragging the thumb (the movable part of the switch) or by clicking anywhere within the track (the switch’s background area).
- click – The switch state changes only when a user clicks inside the track. Dragging the thumb does not affect the state.
- drag – The switch state changes solely by dragging the thumb. Clicking on the track has no effect.
- none – The switch cannot be toggled by any user interaction. Its state can only be changed programmatically through the API.
Default value
"default"Example
Set the switchMode property.
<smart-switch-button switch-mode='click'></smart-switch-button>
Set the switchMode property by using the HTML Element's instance.
const switchbutton = document.querySelector('smart-switch-button');
switchbutton.switchMode = 'drag';
Get the switchMode property.
const switchbutton = document.querySelector('smart-switch-button');
let switchMode = switchbutton.switchMode;
themestring
Specifies the theme for the element, which controls its overall visual appearance—including colors, fonts, and style. Selecting a theme customizes how the element is presented to users, ensuring consistency with the application's design.
Default value
""Example
Set the theme property.
<smart-switch-button theme='blue'></smart-switch-button>
Set the theme property by using the HTML Element's instance.
const switchbutton = document.querySelector('smart-switch-button');
switchbutton.theme = 'red';
Get the theme property.
const switchbutton = document.querySelector('smart-switch-button');
let theme = switchbutton.theme;
unfocusableboolean
When set to true, this property prevents the element from receiving keyboard focus, making it impossible for users to select the element using the Tab key or other keyboard navigation methods.
Default value
falseExample
Set the unfocusable property.
<smart-switch-button unfocusable></smart-switch-button>
Set the unfocusable property by using the HTML Element's instance.
const switchbutton = document.querySelector('smart-switch-button');
switchbutton.unfocusable = false;
Get the unfocusable property.
const switchbutton = document.querySelector('smart-switch-button');
let unfocusable = switchbutton.unfocusable;
valuestring
Sets a new value for the widget or retrieves its current value. Use this to programmatically update what the widget displays or to access the user's input.
Default value
""""Example
Set the value property.
<smart-switch-button value='Value'></smart-switch-button>
Set the value property by using the HTML Element's instance.
const switchbutton = document.querySelector('smart-switch-button');
switchbutton.value = 'New Value';
Get the value property.
const switchbutton = document.querySelector('smart-switch-button');
let value = switchbutton.value;
Events
changeCustomEvent
This event is triggered whenever the widget's state changes between checked and unchecked, such as when a user selects or deselects it. The event provides updated information about the new checked state of the widget.
- Bubbles Yes
- Cancelable No
- Interface CustomEvent
- Event handler property onChange
Arguments
evCustomEvent
ev.detailObject
ev.detail.value - A boolean value indicating the new state of the button ( checked or not ).
ev.detail.oldValue - A boolean value indicating the previous state of the button ( checked or not ).
ev.detail.changeType - A string flag indicating whether the change event was triggered via API or an event.
Methods
isDefaultPrevented
Returns true if the event was prevented by any of its subscribers.
Returns
boolean true if the default action was prevented. Otherwise, returns false.
preventDefault
The preventDefault() method prevents the default action for a specified event. In this way, the source component suppresses the built-in behavior that follows the event.
stopPropagation
The stopPropagation() method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases.
Example
Set up the event handler of change event.
const switchbutton = document.querySelector('smart-switch-button'); switchbutton.addEventListener('change', function (event) { const detail = event.detail, value = detail.value, oldValue = detail.oldValue, changeType = detail.changeType; // event handling code goes here. })
checkValueCustomEvent
This event is triggered whenever the widget transitions to a checked state, such as when a user selects, activates, or toggles the widget to indicate it is checked. It allows developers to execute custom logic in response to changes in the widget's checked status.
- Bubbles Yes
- Cancelable No
- Interface CustomEvent
- Event handler property onCheckValue
Arguments
evCustomEvent
ev.detailObject
ev.detail.changeType - A string flag indicating whether the change event was triggered via API or an event.
Methods
isDefaultPrevented
Returns true if the event was prevented by any of its subscribers.
Returns
boolean true if the default action was prevented. Otherwise, returns false.
preventDefault
The preventDefault() method prevents the default action for a specified event. In this way, the source component suppresses the built-in behavior that follows the event.
stopPropagation
The stopPropagation() method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases.
Example
Set up the event handler of checkValue event.
const switchbutton = document.querySelector('smart-switch-button'); switchbutton.addEventListener('checkValue', function (event) { const detail = event.detail, changeType = detail.changeType; // event handling code goes here. })
uncheckValueCustomEvent
This event is triggered whenever the user unchecks the widget, indicating a change from a checked (selected) state to an unchecked (deselected) state. This allows you to execute custom logic in response to the widget being deselected.
- Bubbles Yes
- Cancelable No
- Interface CustomEvent
- Event handler property onUncheckValue
Arguments
evCustomEvent
ev.detailObject
ev.detail.changeType - A string flag indicating whether the change event was triggered via API or an event.
Methods
isDefaultPrevented
Returns true if the event was prevented by any of its subscribers.
Returns
boolean true if the default action was prevented. Otherwise, returns false.
preventDefault
The preventDefault() method prevents the default action for a specified event. In this way, the source component suppresses the built-in behavior that follows the event.
stopPropagation
The stopPropagation() method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases.
Example
Set up the event handler of uncheckValue event.
const switchbutton = document.querySelector('smart-switch-button'); switchbutton.addEventListener('uncheckValue', function (event) { const detail = event.detail, changeType = detail.changeType; // event handling code goes here. })
CSS Variables
--smart-switch-button-default-widthvar()
Default value
"calc(var(--smart-editor-height) + 10px)"Default width of the SwitchButton.
--smart-switch-button-default-heightvar()
Default value
"var(--smart-editor-height)"smartSwitchButton default height
--smart-switch-button-thumb-sizevar()
Default value
"calc(var(--smart-switch-button-default-height) - 8px)"smartSwitchButton thumb size