Skip to content

Radio ​

A controlled radio. @Binding var checked expresses "whether this item is selected"; it is usually used inside a group, where only one item in the same group can be true.

Spec source: lh-ui-core/specs/radio.json · Golden cases: lh-ui-core/cases/radio.json (6 entries, translated into XCTest, runnable on the macOS host)

States ​

The selected state is an outlined primary-colored ring with a solid primary-colored dot; the unselected state is an empty outlined ring. The dot diameter is the size times radio.dotScale (50%).

9:41Radio states
UnselectedSelected
Disabled selectedDisabled unselected

HTML mock preview (iOS / SwiftUI appearance), not an on-device render

swift
@State private var picked = "blue"

LhRadio(checked: Binding(get: { picked == "blue" }, set: { _ in }), value: "blue", label: "青花瓷 (ceramic blue)") { _ in
  picked = "blue"
}

Sizes ​

Three sizes map to the radio.size tokens; the ring stroke comes from radio.ringWidth.

9:41Radio sizes
SmallMediumLarge

HTML mock preview (iOS / SwiftUI appearance), not an on-device render

Tap gate ​

Tapping an already-selected item keeps it selected and does not fire onChange (golden case tap-checked-keeps-checked); the disabled state does not fire either (disabled-blocks-change). A group container is left for a later release.

API ​

Props ​

PropDescriptionTypeDefault
checkedWhether this item is selected (controlled two-way binding)Bool—
valueThe value this item represents (paired with checked to build a radio group)String""
disabledWhether disabled (does not fire onChange)Boolfalse
lhSizeRadio size, mapped to the size tokensLhRadioSize.medium
labelText labelString""
onChangeSelection-change callback; the payload is the new value((Bool) -> Void)?nil

LhRadioSize ​

ValueRing sizeDot diameter
.smallradio.size.small (16pt)size × radio.dotScale (8pt)
.mediumradio.size.medium (20pt)size × radio.dotScale (10pt)
.largeradio.size.large (24pt)size × radio.dotScale (12pt)

Colors ​

StateRing borderDot
Unselectedcolor.border.base (radio.ringWidth)—
Selectedcolor.primary.defaultcolor.primary.default
Disabledcolor.disabled.bordercolor.disabled.text

Token Reference ​

TokenPurpose
radio.size.{small,medium,large}Three ring sizes
radio.dotScaleRatio of the dot to the ring size (50%)
radio.ringWidthRing border width
radio.gapGap between the ring and the text (follows spacing.sm)
color.primary.defaultSelected border and dot color
color.border.baseUnselected border color
color.disabled.{border,text}Disabled border and dot color
color.text.{primary,disabled}Label text colors

Golden Case Mapping ​

case idAssertionLocal test
tap-unchecked-emits-onchangeTapping an unselected item fires onChange(true)testUncheckedIsInteractive
tap-checked-keeps-checkedTapping a selected item keeps it selected with no callbacktestCheckedShowsDot
disabled-blocks-changeThe disabled state does not fire onChangetestDisabledBlocksChange
checked-uses-primary-tokensThe selected state consumes the primary tokentestCheckedUsesPrimaryTokens
unchecked-uses-border-tokenThe unselected state consumes the border tokentestUncheckedUsesBorderToken
small-size-uses-small-tokenThe small size consumes the small size tokentestSmallSizeUsesSmallToken

Plus dedicated tests: testStrokeUsesRadioTokens / testDarkColorsComeFromDarkTokens / testDisabledInDarkUsesDarkDisabledTokens / testDimensionsAreIdenticalInDarkMode / testRadioViewInitAcceptsConstant.

bash
swift test --filter LhRadioTests    # Runs on the macOS host, no simulator required

lh-ui native bloodline · iOS (Swift + SwiftUI)