Products · Components

Switch

An on and off switch for a setting that applies at once.

For a choice the person confirms with a button, use a Checkbox.

Children: Nothing

Example

The Switch component
view.dml
<Switch label="Notify me of payments" checked="{{ notify }}" onChange="setNotify" />
controller.ts
export default definePage({
  initialState: { notify: true },
  mutations: {
    setNotify: (_state, event: CheckedEvent) => ({ notify: event.detail.checked }),
  },
});

Props

PropTypeWhat it is
checkedbooleanDefault: false.
labelstring
disabledbooleanDims it, and the person can't use it.

Events

EventSendsNotes
onChange{ checked } in detail

Keep reading

On this page