Skip to content

SSwitch <s-switch>

ts
import { SSwitch } from 'polaris-vue-elements'

Example

On: false

vue
<script setup>
import { ref } from 'vue'
import { SSwitch } from 'polaris-vue-elements'

const value = ref(false)
</script>

<template>
  <SSwitch label="Enable notifications" v-model="value" />
  <p>On: {{ value }}</p>
</template>

v-model

v-model on <SSwitch> binds to the checked property and listens for the change DOM event.

template
<SSwitch v-model="value" />

is equivalent to:

template
<SSwitch :checked="value" @change="value = $event.target.checked" />

Props

PropTypeDescription
accessibilityLabelstringA label used for users using assistive technologies like screen readers. When set, any children or label supplied will not be announced. This can also be used to display a control without a visual label, while still providing context to users using screen readers.
checkedbooleanWhether the control is active.
defaultCheckedbooleanWhether the control is active by default.
detailsanyAdditional text to provide context or guidance for the field. This text is displayed along with the field and its label to offer more information or instructions to the user. This will also be exposed to screen reader users.
disabledbooleanDisables the control, disallowing any interaction.
erroranyIndicate an error to the user. The field will be given a specific stylistic treatment to communicate problems that have to be resolved immediately.
labelanyVisual content to use as the control label.
labelAccessibilityVisibility"visible" | "exclusive"Changes the visibility of the component's label. - visible: the label is visible to all users. - exclusive: the label is visually hidden but remains in the accessibility tree.
namestringAn identifier for the control that is unique within the nearest containing Form component.
requiredbooleanWhether the field needs a value. This requirement adds semantic value to the field, but it will not cause an error to appear automatically. If you want to present an error when this field is empty, you can do so with the error property.
valuestring

Events

EventType
blurCustomEvent
changeCustomEvent
inputCustomEvent

Listen for these with @blur-style listeners on <SSwitch>.