ToggleButton
ToggleButton allows the user to change a setting between two states.
Selector
smart-toggle-button
Properties
Events
Properties
animation"none" | "simple" | "advanced"
Specifies or retrieves the current animation mode for the element. When set to 'none', all animations are disabled, and the element will appear or update instantly without any animated transitions. If a different value is assigned, the element will use the corresponding animation effect during state changes.
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-toggle-button animation='none'></smart-toggle-button>
Set the animation property by using the HTML Element's instance.
const togglebutton = document.querySelector('smart-toggle-button');
togglebutton.animation = 'simple';
Get the animation property.
const togglebutton = document.querySelector('smart-toggle-button');
let animation = togglebutton.animation;
checkedboolean
Defines or updates the current state of the element, controlling its behavior, appearance, or functionality based on the specified value. This property determines how the element responds to user interactions and can trigger associated changes in the interface or underlying logic.
Default value
falseExample
Set the checked property.
<smart-toggle-button checked></smart-toggle-button>
Set the checked property by using the HTML Element's instance.
const togglebutton = document.querySelector('smart-toggle-button');
togglebutton.checked = false;
Get the checked property.
const togglebutton = document.querySelector('smart-toggle-button');
let checked = togglebutton.checked;
clickMode"hover" | "press" | "release" | "pressAndRelease"
Specifies how the button responds to user click interactions, determining the trigger conditions for its click event (e.g., on mouse down, on mouse up, or after a complete click).
Default value
"release"Example
Set the clickMode property.
<smart-toggle-button click-mode='hover'></smart-toggle-button>
Set the clickMode property by using the HTML Element's instance.
const togglebutton = document.querySelector('smart-toggle-button');
togglebutton.clickMode = 'release';
Get the clickMode property.
const togglebutton = document.querySelector('smart-toggle-button');
let clickMode = togglebutton.clickMode;
disabledboolean
Determines whether the ratio button is displayed and interactive. Set to true to show and enable the button, or false to hide and disable it.
Default value
falseExample
Set the disabled property.
<smart-toggle-button disabled></smart-toggle-button>
Set the disabled property by using the HTML Element's instance.
const togglebutton = document.querySelector('smart-toggle-button');
togglebutton.disabled = false;
Get the disabled property.
const togglebutton = document.querySelector('smart-toggle-button');
let disabled = togglebutton.disabled;
innerHTMLstring
Assigns the specified HTML markup to the element’s content, replacing all existing child elements and text within the element. This allows dynamic insertion of HTML structure and content inside the targeted element.
Default value
""""Example
Set the innerHTML property.
<smart-toggle-button inner-h-t-m-l='Toggle Button Label'></smart-toggle-button>
Set the innerHTML property by using the HTML Element's instance.
const togglebutton = document.querySelector('smart-toggle-button');
togglebutton.innerHTML = 'New Toggle Button Label';
Get the innerHTML property.
const togglebutton = document.querySelector('smart-toggle-button');
let innerHTML = togglebutton.innerHTML;
unlockKeystring
Sets or retrieves the value of the unlockKey, a unique code or token required to authorize and unlock access to the product’s features or functionality.
Default value
""Example
Set the unlockKey property.
<smart-toggle-button unlock-key=''></smart-toggle-button>
Set the unlockKey property by using the HTML Element's instance.
const togglebutton = document.querySelector('smart-toggle-button');
togglebutton.unlockKey = '1111-2222-3333-4444-5555';
Get the unlockKey property.
const togglebutton = document.querySelector('smart-toggle-button');
let unlockKey = togglebutton.unlockKey;
localestring
Specifies or retrieves the current language setting. This property works together with the messages property to determine which localized messages are displayed. When you set this property, the component selects the appropriate set of messages corresponding to the chosen language.
Default value
"en"Example
Set the locale property.
<smart-toggle-button locale='de'></smart-toggle-button>
Set the locale property by using the HTML Element's instance.
const togglebutton = document.querySelector('smart-toggle-button');
togglebutton.locale = 'fr';
Get the locale property.
const togglebutton = document.querySelector('smart-toggle-button');
let locale = togglebutton.locale;
localizeFormatFunctionfunction | null
Callback function associated with the localization module, typically used to handle events or operations such as language changes, text translations, or localization updates within the application.
Example
Set the localizeFormatFunction property.
<smart-toggle-button localize-format-function='function(){return '...'}'></smart-toggle-button>
Set the localizeFormatFunction property by using the HTML Element's instance.
const togglebutton = document.querySelector('smart-toggle-button');
togglebutton.localizeFormatFunction = function(){return '...'};
Get the localizeFormatFunction property.
const togglebutton = document.querySelector('smart-toggle-button');
let localizeFormatFunction = togglebutton.localizeFormatFunction;
messagesobject
Sets or retrieves an object containing the text strings displayed in the widget, allowing for easy localization and customization of interface messages. This property works together with the locale property to provide translations and adapt the widget's language to different regions. Use this object to define or override the default text for various UI elements, tooltips, messages, and labels within the widget.
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-toggle-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-toggle-button>
Set the messages property by using the HTML Element's instance.
const togglebutton = document.querySelector('smart-toggle-button');
togglebutton.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 togglebutton = document.querySelector('smart-toggle-button');
let messages = togglebutton.messages;
namestring
Gets or assigns the name of the widget. This property allows you to retrieve the current name of the widget or specify a new name for identification and reference purposes within the application.
Default value
""""Example
Set the name property.
<smart-toggle-button name='Name'></smart-toggle-button>
Set the name property by using the HTML Element's instance.
const togglebutton = document.querySelector('smart-toggle-button');
togglebutton.name = 'New Name';
Get the name property.
const togglebutton = document.querySelector('smart-toggle-button');
let name = togglebutton.name;
readonlyboolean
If the custom element has the 'readonly' attribute set, its content cannot be modified by the user. However, users may still be able to interact with the element in other ways, such as selecting or copying its content. No input changes or value modifications are permitted while the element is in the readonly state.
Default value
falseExample
Set the readonly property.
<smart-toggle-button readonly></smart-toggle-button>
Set the readonly property by using the HTML Element's instance.
const togglebutton = document.querySelector('smart-toggle-button');
togglebutton.readonly = false;
Get the readonly property.
const togglebutton = document.querySelector('smart-toggle-button');
let readonly = togglebutton.readonly;
themestring
Specifies the theme to be applied. The selected theme controls the visual appearance and styling of the element, including colors, fonts, spacing, and other design-related properties.
Default value
""Example
Set the theme property.
<smart-toggle-button theme='blue'></smart-toggle-button>
Set the theme property by using the HTML Element's instance.
const togglebutton = document.querySelector('smart-toggle-button');
togglebutton.theme = 'red';
Get the theme property.
const togglebutton = document.querySelector('smart-toggle-button');
let theme = togglebutton.theme;
unfocusableboolean
When set to true, the element will be removed from the tab order and cannot receive focus via keyboard or mouse interactions.
Default value
falseExample
Set the unfocusable property.
<smart-toggle-button unfocusable></smart-toggle-button>
Set the unfocusable property by using the HTML Element's instance.
const togglebutton = document.querySelector('smart-toggle-button');
togglebutton.unfocusable = false;
Get the unfocusable property.
const togglebutton = document.querySelector('smart-toggle-button');
let unfocusable = togglebutton.unfocusable;
valuestring
Gets the current value of the widget or sets a new value for the widget. Use this property to retrieve what the widget currently holds or to update it programmatically.
Default value
""""Example
Set the value property.
<smart-toggle-button value='Value'></smart-toggle-button>
Set the value property by using the HTML Element's instance.
const togglebutton = document.querySelector('smart-toggle-button');
togglebutton.value = 'New Value';
Get the value property.
const togglebutton = document.querySelector('smart-toggle-button');
let value = togglebutton.value;
Events
changeCustomEvent
This event is triggered whenever the state of the widget changes—specifically, when the user checks or unchecks the widget. It allows you to respond to any change in the widget’s selection status.
- 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 togglebutton = document.querySelector('smart-toggle-button'); togglebutton.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 into a checked state, such as when a user selects or activates it. It allows developers to respond to changes in the widget's selection 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 togglebutton = document.querySelector('smart-toggle-button'); togglebutton.addEventListener('checkValue', function (event) { const detail = event.detail, changeType = detail.changeType; // event handling code goes here. })
uncheckValueCustomEvent
This event is triggered when the user deselects or unchecks the widget, typically by clicking or tapping on it. It indicates that the widget has transitioned from a checked or selected state to an unchecked or unselected state. Developers can use this event to execute custom logic or update the application’s interface in response to the change.
- 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 togglebutton = document.querySelector('smart-toggle-button'); togglebutton.addEventListener('uncheckValue', function (event) { const detail = event.detail, changeType = detail.changeType; // event handling code goes here. })