Skip to main content

Choice

Radio or checkbox group selection.

Usage

<w-choice value="option1" label="Select an option">
<w-slot opt data-value="option1"><button>Option 1</button></w-slot>
<w-slot opt data-value="option2"><button>Option 2</button></w-slot>
<w-slot opt data-value="option3"><button>Option 3</button></w-slot>
</w-choice>

Props

PropTypeDefaultDescription
valuestring""Selected value(s), comma-separated for multiple
multiplebooleanfalseAllow multiple selection
labelstring""Group label
orientation"horizontal" | "vertical""horizontal"Layout direction

Slots

SlotElementDescription
optionButtonSelectable option (use data-value)

Events

EventDetailDescription
change{ value }Selection changed

Keyboard

KeyAction
ArrowRight / ArrowDownNext option
ArrowLeft / ArrowUpPrevious option
SpaceSelect focused option

Examples

Multiple Selection (Checkboxes)

<w-choice multiple value="opt1,opt3" label="Select features">
<w-slot opt data-value="opt1"><button>Feature A</button></w-slot>
<w-slot opt data-value="opt2"><button>Feature B</button></w-slot>
<w-slot opt data-value="opt3"><button>Feature C</button></w-slot>
</w-choice>

Styling

The host gets display: flex with row/column direction set automatically by [orientation]. State is exposed as aria-checked on each option's child element.

/* Each option */
w-choice w-slot[opt] > * {
padding: 0.5rem 1rem;
cursor: pointer;
}

/* Selected option */
w-choice w-slot[opt] > *[aria-checked="true"] {
background: #eef2ff;
border-color: #6366f1;
}

/* Disabled */
w-choice[disabled] w-slot[opt] > * {
opacity: 0.5;
}

/* Vertical (default) vs horizontal */
w-choice[orientation="horizontal"] {
flex-wrap: wrap;
}
SelectorTargets
w-choice w-slot[opt] > *[aria-checked="true"]Currently selected
w-choice w-slot[opt] > *[aria-disabled="true"]Disabled options
w-choice[orientation="horizontal"]Horizontal layout
w-choice[mode="checkbox"]Checkbox mode group

Accessibility

  • Single selection: role="radiogroup" with role="radio" options
  • Multiple selection: Options have aria-checked
  • aria-label from label prop
  • Roving tabindex navigation