Basic Usage
Simple multi-option switch with labels
Live Demo
Code
Explanation
Two-way Binding
Use bind:selectedIndex to track which option is currently selected.
Items Array
Pass an array of strings or objects to define the available options.
Different Option Counts
MultiSwitch adapts to any number of options
Live Demo
Code
Guidelines
Flexible Options
MultiSwitch works with 3 or more options. The component automatically adjusts spacing and positioning.
Content Types
- Text labels
- Emoji characters
- Short abbreviations
- Custom objects
Size Variations
Control the size for different use cases
Live Demo
Code
Size Guidelines
Choosing Size
- Small (30-40px): Compact layouts, sidebars
- Default (50px): Most common use cases
- Large (60-80px): Touch interfaces, emphasis
Label Considerations
Larger switches provide more space for labels and better touch targets.
Vertical Orientation
Vertical layout for space-constrained designs
Live Demo
Code
When to Use
Vertical Benefits
- Saves horizontal space
- Works well in sidebars
- Good for mobile layouts
- Creates visual hierarchy
Label Positioning
Consider using "right" or "left" label positions with vertical switches for better readability.
Label Positioning
Control where labels appear relative to the switch
Live Demo
Code
Position Options
Available Positions
top- Above the switchbottom- Below the switch (default)left- To the left (vertical only)right- To the right (vertical only)
Design Tips
Choose label position based on your layout constraints and visual hierarchy.
Event Handling
Respond to selection changes
Live Demo
Code
Event Details
onItemChange Callback
The onItemChange prop accepts a function that receives
the newly selected index.
Common Use Cases
- Form validation
- Loading related data
- Updating other UI components
- Analytics tracking
Working with Custom Objects
Using both children and labelTemplate with complex data
Live Demo
Code
Template Usage
Custom Object Support
When using complex objects, provide both children and labelTemplate snippets to display different parts of your data.
Template Roles
- children: Compact display in switch area (first letter)
- labelTemplate: Full details in labels (name + description)
Best Practices
Keep switch content minimal and use labels for detailed information to maintain readability and usability.