Components/FlatRadio

FlatRadio

A segmented control for choosing among two to five inline options.

VerifiedSince 0.3.4

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...
KeyBehavior
→ / ↓Next enabled item (wraps)
← / ↑Previous enabled item (wraps)
HomeFirst enabled item
EndLast enabled item
Enter / SpaceToggles 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 TxSelect for more.
  • Use xl when the control is the primary choice on screen; keep the default md inline 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 multiple only for independent values; otherwise use switches or checkboxes.
  • Keep value stable across renders: the parent registers items by value for thumb placement and keyboard order.

API Reference

TxFlatRadio

Props

PropTypeDefaultDescription
modelValue / v-modelstring | number | (string | number)[]requiredA single value, or an array in multiple mode.
multiplebooleanfalseMulti-select: items toggle like checkboxes and the thumb is hidden.
disabledbooleanfalseDisables the whole group, removing it from the tab order and blocking changes.
size'sm' | 'md' | 'lg' | 'xl''md'Size.
borderedbooleanfalseAdds an outer border.

Events

EventParamsDescription
update:modelValue(value: string | number | (string | number)[]) => voidFires with the new value after a selection change.
change(value: string | number | (string | number)[]) => voidFires together with update:modelValue.

Slots

SlotDescription
defaultTxFlatRadioItem children.

TxFlatRadioItem

Props

PropTypeDefaultDescription
valuestring | numberrequiredThe item's value, registered with the parent.
labelstring-Text shown when there is no default slot.
iconstring-Icon class used when there is no icon slot.
disabledbooleanfalseDisables the item and skips it in keyboard navigation.

Slots

SlotDescription
defaultCustom content, replacing label.
iconCustom icon, replacing icon.

Overview

  • Single mode renders role="radiogroup" with role="radio" items; multiple renders role="group" with role="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 multiple mode 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 in TxTabs, TxTabBar, and TxSidebarNav), writing transform, width, and opacity each frame without re-rendering.
  • Source: packages/tuffex/packages/components/src/flat-radio/.
查看源码
packages/tuffex/packages/components/src/flat-radio/index.ts

Customization

CSS variableUsed for
--tx-flat-radio-track-bgTrack fill; defaults to --tx-fill-color.
--tx-flat-radio-indicator-bgThumb and multi-select item fill; defaults to --tx-surface-raised.
--tx-flat-radio-indicator-shadowThumb shadow.