Switcher
The switcher input type is used for boolean toggle switches. It provides a modern, accessible way to enable/disable features, accept terms, or make yes/no decisions with a simple on/off state.
vue
<template>
<VsInputSwitcher v-model="switcherValue" />
</template>
<script setup>
import { ref } from 'vue'
import { VsInputSwitcher } from '@opengis/form'
const switcherValue = ref(false);
</script>
Basic Switcher
vue
<VsInputSwitcher v-model="switcherValue" />
js
{
name: 'newsletter',
type: 'switcher',
label: 'Subscribe to newsletter'
}
Required Switcher
vue
<VsInputSwitcher v-model="switcherValue" />
js
{
name: 'terms',
type: 'switcher',
label: 'I agree to the terms and conditions',
rules: ['required']
}
Properties
Required Properties
- name (string): Unique identifier for the field
- type (string): Must be 'switcher'
- label (string): Display label for the field
Optional Properties
- disabled (boolean): Whether the field is disabled
- rules (array): Validation rules
- conditions (object): Conditional display logic
Schema Interface
typescript
interface SwitcherSchemaItem {
name: string;
type: 'switcher';
label: string;
disabled?: boolean;
rules?: (string | object)[];
conditions?: Conditions | Conditions[];
}
Best Practices
- Use clear, action-oriented labels that describe what the switch does
- Use positive language (e.g., "Enable notifications" vs "Disable notifications")
- Provide immediate feedback when the switch state changes
- Use consistent styling across your application
- Consider accessibility with proper ARIA labels
- Use for binary choices only (on/off, yes/no, enable/disable)
- Avoid using for multiple options - use radio buttons or select instead
- Provide clear visual feedback for the current state
- Use appropriate sizing for touch interfaces
- Test with keyboard navigation for accessibility compliance