Visual Studio Code Radio Group

October 13, 2023 · View on GitHub

The vscode-radio-group is a web component implementation of a radio group.

Radio group hero

Usage

❌ Don't✅ Do
Radio buttons that indicate multiple options can be selectedRadio buttons with one clear possible selection
Don't use radio buttons when more than one selection is possible. Try using checkboxes instead.Use radio groups for options that feature a single selection at a time.
❌ Don't✅ Do
Radio buttons arranged in a horizontal orientationRadio buttons arranged in a vertical orientation
Avoid using horizontal radio group layouts.Arrange radio groups vertically to make it easy to scan and compare options.
❌ Don't✅ Do
Radio options with multi-line textRadio buttons with concise labels
Don't use long blocks of text.Use concise language to describe each option.

Implementation

While any DOM content is permissible as a child of the vscode-radio-group, only vscode-radio components and slotted content with a role of radio will receive keyboard support.

Interactive component examples

Attributes

AttributeTypeDescription
disabledbooleanDisables the radio group and child radios.
namestringThe name of the radio group. This will also set the name value for all child radio elements.
orientationstringThe orientation of the group. Options: horizontal, vertical.
readonlybooleanWhen true, the child radios will be immutable by user interaction.

Basic Radio Group

Warning
There is a known upstream bug with vscode-radio component selection on first interaction. A workaround fix is to make sure that all radio components have a unique value attribute applied as demonstrated below.

<vscode-radio-group>
  <label slot="label">Radio Group Label</label>
  <vscode-radio value="value-1">Radio Label</vscode-radio>
  <vscode-radio value="value-2">Radio Label</vscode-radio>
  <vscode-radio value="value-3">Radio Label</vscode-radio>
</vscode-radio-group>

Disabled Attribute

<vscode-radio-group disabled>
  <label slot="label">Radio Group Label</label>
  <vscode-radio value="value-1">Radio Label</vscode-radio>
  <vscode-radio value="value-2">Radio Label</vscode-radio>
  <vscode-radio value="value-3">Radio Label</vscode-radio>
</vscode-radio-group>

Name Attribute

<vscode-radio-group name="example-radio-group">
  <label slot="label">Radio Group Label</label>
  <vscode-radio value="value-1">Radio Label</vscode-radio>
  <vscode-radio value="value-2">Radio Label</vscode-radio>
  <vscode-radio value="value-3">Radio Label</vscode-radio>
</vscode-radio-group>

Orientation Attribute

If the orientation attribute is not set, the default orientation is horizontal.

<vscode-radio-group orientation="vertical">
  <label slot="label">Radio Group Label</label>
  <vscode-radio value="value-1">Radio Label</vscode-radio>
  <vscode-radio value="value-2">Radio Label</vscode-radio>
  <vscode-radio value="value-3">Radio Label</vscode-radio>
</vscode-radio-group>

<vscode-radio-group orientation="horizontal">
  <label slot="label">Radio Group Label</label>
  <vscode-radio value="value-1">Radio Label</vscode-radio>
  <vscode-radio value="value-2">Radio Label</vscode-radio>
  <vscode-radio value="value-3">Radio Label</vscode-radio>
</vscode-radio-group>

Read Only Attribute

<vscode-radio-group readonly>
  <label slot="label">Radio Group Label</label>
  <vscode-radio value="value-1">Radio Label</vscode-radio>
  <vscode-radio value="value-2">Radio Label</vscode-radio>
  <vscode-radio value="value-3">Radio Label</vscode-radio>
</vscode-radio-group>