FlatRadio
A segmented control for choosing among two to five inline options.
Usage
Basic
Loading demo...
Disabled
Set disabled on the whole group or on single items.
Loading demo...
Sizes
size takes sm, md (default), lg, or xl.
Loading demo...
Icons
icon takes an icon class, such as a UnoCSS icon.
Loading demo...
Bordered
Loading demo...
Multiple
With multiple, the value is an array and items toggle like checkboxes, without the thumb.
Loading demo...
Keyboard Navigation
Once the container has focus, it responds to the keys below.
Loading demo...
| Key | Behavior |
|---|---|
→ / ↓ | Next enabled item (wraps) |
← / ↑ | Previous enabled item (wraps) |
Home | First enabled item |
End | Last enabled item |
Enter / Space | Toggles the current item in multiple mode |
Best Practices
- Use for two to five short options that benefit from side-by-side comparison (labels don't wrap); use
TxSelectfor more. - Use
xlwhen the control is the primary choice on screen; keep the defaultmdinline and in toolbars. - Don't bold custom slot content only when selected: every item already carries the selected weight, and extra bold reflows the row.
- Use
multipleonly for independent values; otherwise use switches or checkboxes. - Keep
valuestable across renders: the parent registers items by value for thumb placement and keyboard order.
API Reference
TxFlatRadio
Props
| Prop | Type | Default | Description |
|---|---|---|---|
modelValue / v-model | string | number | (string | number)[] | required | A single value, or an array in multiple mode. |
multiple | boolean | false | Multi-select: items toggle like checkboxes and the thumb is hidden. |
disabled | boolean | false | Disables the whole group, removing it from the tab order and blocking changes. |
size | 'sm' | 'md' | 'lg' | 'xl' | 'md' | Size. |
bordered | boolean | false | Adds an outer border. |
Events
| Event | Params | Description |
|---|---|---|
update:modelValue | (value: string | number | (string | number)[]) => void | Fires with the new value after a selection change. |
change | (value: string | number | (string | number)[]) => void | Fires together with update:modelValue. |
Slots
| Slot | Description |
|---|---|
default | TxFlatRadioItem children. |
TxFlatRadioItem
Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | number | required | The item's value, registered with the parent. |
label | string | - | Text shown when there is no default slot. |
icon | string | - | Icon class used when there is no icon slot. |
disabled | boolean | false | Disables the item and skips it in keyboard navigation. |
Slots
| Slot | Description |
|---|---|
default | Custom content, replacing label. |
icon | Custom icon, replacing icon. |
Overview
- Single mode renders
role="radiogroup"withrole="radio"items;multiplerendersrole="group"withrole="checkbox"items. - Only the container is tabbable; items keep
tabindex="-1". Name the group with nearby field text or an external label. - In single mode the arrow keys select directly; in
multiplemode they only move focus, and Enter / Space toggles. - The thumb never scales. It lands in place on mount, resize, and item registration, glides to a new selection, and never leaves the track.
- A press scales the label and icon, never the item box.
- Under reduced motion, the thumb lands in place and the press scale is dropped; the fade stays.
Technologies
- The thumb runs on the glide material of the shared
useJellyIndicator(as inTxTabs,TxTabBar, andTxSidebarNav), writingtransform,width, andopacityeach frame without re-rendering. - Source:
packages/tuffex/packages/components/src/flat-radio/.
查看源码
packages/tuffex/packages/components/src/flat-radio/index.ts
Customization
| CSS variable | Used for |
|---|---|
--tx-flat-radio-track-bg | Track fill; defaults to --tx-fill-color. |
--tx-flat-radio-indicator-bg | Thumb and multi-select item fill; defaults to --tx-surface-raised. |
--tx-flat-radio-indicator-shadow | Thumb shadow. |