Skip to main content

Switch

Use cases:

  • Toggling visibility of a UI section
  • Disabling & enabling features

Example

Declaration

<rapid-switch></rapid-switch>

Usage

@customElement({
name: 'my-element',
template: html`
<rapid-switch
@change=${(x, ctx) => x.switchChanged(ctx.event)}>
Theme
<span slot="checked-message">Dark</span>
<span slot="unchecked-message">Light</span>
</rapid-switch>
`,
})
export class MyElement extends GenesisElement {
switchChanged(e: Event) {
console.log('switch changed', (e.target as HTMLInputElement).checked)
}
}

API

Property and attribute binding examples for Genesis Component syntax (closing tag omitted).

NameTypeDescriptionExample
checkedbooleanSets or retrieves the current state of the component. Default: false
<rapid-switch ?checked=${sync(x => x.isSelected, 'boolean')}>
readonlybooleanConfigures the component so the user cannot alter the state via the web browser.
<rapid-switch readonly>
disabledbooleanSame functionality as readonly, and additionally greys out the component.
<rapid-switch disabled>
formstringAssociates this component to a form. Form id needs to be passed. If no Id informed, then it will be associated with the ancestor form.
<rapid-switch form="myForm">

Slots

SlotUse
switchThe control element.

Parts

PartDescription
labelThe label text.
checked-indicatorThe checked indicator.
checked-messageThe text label when the switch is selected.
switchThe input control.
unchecked-messageThe text label when the switch is not selected.

Events fired

NameDescription
changeFires the event when the radio component changes its state

Events fired

EventTypeUseExample
changeeventEmits a custom change event when the component state changes. Access the value on the event via .target.checked.
<rapid-switch @change="${(x) => x.myChangeHandler(event)}">

Events listened to

This component doesn't listen to any events.

Further details

This component is an implementation of an HTML switch element.