Skip to content

SCheckbox <s-checkbox> ​

A single checkbox for a yes/no choice, bound to its checked state with v-model. SCheckbox is the typed Vue 3 wrapper for Shopify's Polaris <s-checkbox> web component.

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

Best practices ​

  • Keep each checkbox independent. Merchants should be able to tick any combination of options without one checkbox affecting another.
  • Give every checkbox a descriptive label. This matters most when a checkbox switches a setting on or off, so merchants know exactly what they're enabling.
  • Order options logically. Sort them alphabetically, numerically or by time so merchants can find the one they want quickly.
  • Reserve indeterminate for partial "select all". Use it on a "select all" checkbox when only some of the items in its group are checked.
  • Add details when context helps. Use it for extra explanation of what an option does, only when the label alone isn't enough.
vue
<SCheckbox
  label="Send order confirmation emails"
  details="Customers get an email as soon as their order is placed."
/>

See Shopify's best practices for <s-checkbox> for the full guidance.

Example ​

Checked: false

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

const value = ref(false)
</script>

<template>
  <SCheckbox label="Send me marketing emails" v-model="value" />
  <p>Checked: {{ value }}</p>
</template>

v-model ​

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

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

is equivalent to:

template
<SCheckbox :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.
defaultIndeterminatebooleanThe initial indeterminate state for uncontrolled components. Use this when you want the checkbox to start in an indeterminate state but don't need to control it afterward. This value applies until indeterminate is explicitly set or the user changes the checkbox state by clicking.
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.
indeterminatebooleanWhether the checkbox displays in an indeterminate state (neither checked nor unchecked), typically used to indicate partial selection in hierarchical lists. This visual state takes priority over the checked prop in appearance only. The form submission value is still determined by the checked prop. If indeterminate has not been explicitly set and hasn't been modified by user interaction, it returns the value of defaultIndeterminate.
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.
valuestringThe value used in form data when the control is checked.

Events ​

EventType
blurFocusEvent
changeEvent
inputEvent

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

Slots ​

SlotDescription
details
error

Released under the MIT License. Vue logo by Evan You, CC BY-NC-SA 4.0.