Label Positioning
Control where labels appear relative to the switch
Live Demo
Code
Position Guidelines
Position Options
top- Above the switch (needs padding-top)bottom- Below the switch (needs padding-bottom)left- To the left (vertical only, needs padding-left)right- To the right (vertical only, needs padding-right)
⚠️ Important: Spacing
By default, labels are absolutely positioned and don't reserve space in the layout.
Add appropriate padding to the container in all directions to prevent overlap with other content.
Alternatively, use labelRenderMode="block" for automatic spacing.
Recommended Padding
- Top: 3rem padding-top
- Bottom: 2.5rem padding-bottom
- Left: 5rem padding-left
- Right: 6-8rem padding-right
Label Render Mode
Choose between absolute and block positioning for labels
Live Demo
Absolute Mode (Default)
Block Mode (New)
Block Mode - Vertical
Code
Render Mode Comparison
Render Modes
absolute(default)- Labels use absolute positioning
- Don't affect layout flow
- Require manual padding
- More control over exact positioning
block- Labels use static positioning
- Take up space in document flow
- No padding needed
- Simpler to use, less flexible
When to Use Block Mode
- Dynamic content where padding is hard to predict
- Simpler layouts without overlapping elements
- When you want automatic spacing
- Responsive designs that adapt to content
When to Use Absolute Mode
- Precise control over label positioning
- Complex layouts with overlapping elements
- Fixed-size components
- Backwards compatibility (default behavior)
Label Content Features (v1.4.0+)
Advanced label text handling with labelMember, labelCallback, and clickable labels
Live Demo
1. labelMember Property
2. labelCallback Function
3. Clickable Labels (Vertical Mode)
Labels are clickable in vertical mode when no thumbTemplate is used.
4. Label Priority System
Code
Feature Details
New in v1.4.0
Enhanced label system with automatic text extraction and interactive features.
1. labelMember Property
- Extracts label text from object property
- Example:
labelMember="name"readsitem.name - Perfect for arrays of objects
- Null-safe: skips if property doesn't exist
2. labelCallback Function
- Custom function:
(item: any, index: number) => string - Access to both item data and index
- Ideal for computed labels or formatting
- Can combine multiple object properties
3. Clickable Labels
- Available in vertical orientation with left/right positions
- Only active when no
thumbTemplateis defined - Click any label to jump directly to that option
- Visual hover effects indicate interactivity
Label Priority System
- labelMember - Object property extraction
- labelCallback - Custom function
- labelTemplate - Full custom rendering
- Default - "Option 1", "Option 2", etc.
Best Practices
- Use
labelMemberfor simple object properties - Use
labelCallbackfor computed or formatted text - Use
labelTemplatefor rich content (HTML, styling) - Combine with
labelRenderMode="block"for easier layouts
Custom Label Templates
Rich label content with custom templates
Live Demo
Code
Template Features
labelTemplate Snippet
The labelTemplate snippet allows complete customization
of how labels are rendered for each option.
Template Parameters
currentIndex- Index of this itemitem- The item data objectisSelected- Boolean for selection state
Use Cases
- Multi-line labels with descriptions
- Icons with text
- Conditional content based on selection
- Custom styling and colors
Label Visibility
Control when to show or hide labels
Live Demo
Code
Visibility Guidelines
When to Hide Labels
- When space is limited
- When using self-explanatory icons
- In compact UI designs
- When labels are shown elsewhere
Accessibility Note
When hiding labels, ensure the options are still understandable through context, tooltips, or nearby text.
Label Best Practices
📝 Content Guidelines
- ✅ Keep labels concise and clear
- ✅ Use consistent terminology
- ✅ Consider internationalization
- ✅ Test with different text lengths
- ✅ Ensure sufficient contrast
🎯 Positioning Tips
- ✅ Add padding for top/left positions
- ✅ Consider viewport constraints
- ✅ Test on different screen sizes
- ✅ Match position to layout flow
- ✅ Be consistent across your app