Vivid API

Switch

Use a Switch when you want a user to easily toggle between two mutually exclusive options, like 'on' and 'off' typically for settings or preferences within an application.

Usage

import { registerSwitch } from '@vonage/vivid-api';
registerSwitch('your-prefix');

Name and Value

Use the name and value attribute when including the Switch as part of a form.

API Reference

Properties

PropertyTypeDefaultDescription
checked
(modelValue)
booleanThe current checkedness of the element.
connotation'accent' | 'cta' | 'success' | 'alert' | 'announcement'Controls the color of the Switch
defaultCheckedbooleanThe default checkedness of the element. This value sets the `checked` property only when the `checked` property has not been explicitly set.
disabledbooleanSets the element's disabled state. A disabled element will not be included during form submission.
initialValuestringThe default value of the element. This value sets the `value` property only when the `value` property has not been explicitly set.
labelstringProvides the label for the Switch
namestringThe name of the element. This element's value will be surfaced during form submission under the provided name.
readOnlybooleanWhen true, the control will be immutable by user interaction. See https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/readonly | readonly HTML attribute for more information.
requiredbooleanRequire the field to be completed prior to form submission.
valuestringThe current value of the element.
PropertyTypeDefaultDescription
current-checkedbooleanThe current checkedness of the element.
connotation'accent' | 'cta' | 'success' | 'alert' | 'announcement'Controls the color of the Switch
checkedbooleanThe default checkedness of the element. This value sets the `checked` property only when the `checked` property has not been explicitly set.
disabledbooleanSets the element's disabled state. A disabled element will not be included during form submission.
valuestringThe default value of the element. This value sets the `value` property only when the `value` property has not been explicitly set.
labelstringProvides the label for the Switch
namestringThe name of the element. This element's value will be surfaced during form submission under the provided name.
readonlybooleanWhen true, the control will be immutable by user interaction. See https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/readonly | readonly HTML attribute for more information.
requiredbooleanRequire the field to be completed prior to form submission.
current-valuestringThe current value of the element.

Events

NameTypeDescription
changeCustomEvent<undefined>Emits a custom change event when the checked state changes
NameTypeDescription
changeCustomEvent<undefined>Emits a custom change event when the checked state changes

Methods

NameParamsReturnsDescription
checkValiditybooleanReturn the current validity of the element.
reportValiditybooleanReturn the current validity of the element. If false, fires an invalid event at the element.