Skip to main content

rc-segmented-button

Segmented button group backed by native radio inputs.

Package
@rcarls/rc-segmented-button
Element
<rc-segmented-button>
Native dependency
Direct-child fieldset with radio inputs
State model
Controlled or uncontrolled selected value
Main events
rc-segmented-button-change

Installation

npm install @rcarls/rc-segmented-button
import '@rcarls/rc-segmented-button/define';

Markup

<rc-segmented-button>
<fieldset>
<legend>Text size</legend>
<label><input type="radio" name="size" value="small" /> Small</label>
<label><input type="radio" name="size" value="medium" checked /> Medium</label>
<label><input type="radio" name="size" value="large" /> Large</label>
</fieldset>
</rc-segmented-button>

The fieldset, legend, labels, and radios stay in light DOM for forms and no-JavaScript fallback. Arrow keys, Home, and End follow the APG radio group model.

Without a theme, the fieldset, legend, and radio controls retain their browser appearance. Material and Substrate visually flatten the fieldset and legend, then style the labels as the segment surfaces; the semantic fieldset and legend remain available to assistive technology.

Live demo

API

Properties

PropertyMarkupTypeDefaultDescription
valuevaluestringNot specifiedCurrent selected radio value. Host writes are silent.
defaultValuedefault-valuestringNot specifiedInitial selected value for uncontrolled usage.
disableddisabledbooleanfalseMirror disabled state to the native fieldset.
orientationorientation'horizontal' | 'vertical''horizontal'Keyboard orientation.

Methods

No public methods are documented in the custom elements manifest.

Events

EventDetail typeDescription
rc-segmented-button-changeNo detail type documentedFired after user interaction changes the selected value.

Slots

NameDescription
(default)A direct `<fieldset>` containing native radio inputs and labels.

CSS Custom Properties

PropertyDefaultDescription
--rc-segmented-button-segment-gapNot specifiedGap between segment icon and label content (defers to native label layout when unset).
--rc-segmented-button-segment-min-block-sizeNot specifiedMinimum segment block size (defers to native label layout when unset).
--rc-segmented-button-segment-padding-blockrevertSegment block-axis padding (defers to native label padding when unset).
--rc-segmented-button-segment-padding-inlinerevertSegment inline-axis padding (defers to native label padding when unset).
--rc-segmented-button-borderrevertSegment border (defers to native label border when unset).
--rc-segmented-button-colorrevertSegment text color (defers to native label color when unset).
--rc-segmented-button-bgrevertSegment background (defers to native label background when unset).
--rc-segmented-button-radiusrevertRounded corner radius on the first and last segments (defers to native label styling when unset).
--rc-segmented-button-dividerrevertBorder between adjacent segments (defers to native label styling when unset).
--rc-segmented-button-selected-colorrevertSegment text color when its radio is checked (defers to native label color when unset).
--rc-segmented-button-selected-bgrevertSegment background when its radio is checked (defers to native label background when unset).
--rc-segmented-button-focus-ringrevertSegment outline when its radio is focus-visible (defers to native focus styling when unset).
--rc-segmented-button-focus-ring-offsetrevertSegment outline offset when its radio is focus-visible (defers to native focus styling when unset).
--rc-segmented-button-disabled-opacityrevertSegment opacity when its radio is disabled, or when the host is `disabled` (defers to native disabled styling when unset).

CSS Parts

No CSS parts are documented in the custom elements manifest.