ToggleButton API

ToggleButton Javascript API

Class

ToggleButton

ToggleButton allows the user to change a setting between two states.

Selector

smart-toggle-button

Properties

Events

Properties

animation"none" | "simple" | "advanced"

Sets or gets the animation mode. Animation is disabled when the property is set to 'none'

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

Sets the state of the element.

Default value

false

Example

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"

Sets the click mode of the button.

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

Enables or disables the ratio button.

Default value

false

Example

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

Sets the inner HTML of the 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;

localestring

Sets or gets the language. Used in conjunction with the property messages.

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, related to localization module.

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 gets an object specifying strings used in the widget that can be localized. Used in conjunction with the property locale.

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

Sets or gets the widget's name.

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 is readonly, it cannot be interacted with.

Default value

false

Example

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

Determines the theme. Theme defines the look of the element

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

If is set to true, the element cannot be focused.

Default value

false

Example

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

Sets or gets the widget's value.

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 when the state of the element is changed.

  • Bubbles Yes
  • Cancelable No
  • Interface CustomEvent
  • Event handler property onChange

Arguments

evCustomEvent

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) {
	// event handling code goes here.
}