Developer Programs

Learn

Docs

Radio Button

Components > Editing Data > Radio Button
Use this component to...
Prompt the user to select exactly one item from a small list of options

Overview

Use the radio button component to prompt the user to select exactly one item from a small list of options.

All options are visible at the same time and display in a vertical stack.

Three radio buttons with one item selected

An interesting bit of trivia… old timers may remember that car radios used to have physical buttons for changing the radio station. When you pushed in one button, it tuned to a specific station and pushed out all the other buttons. This mutual exclusion behavior was needed in modern UI too, so the industry settled on the term “radio buttons” for this component as a nod to these physical-world analogs from the past.

The push buttons in this old car radio are the inspiration for the modern term “radio buttons” (photo credit: Cottonbro Studio)
Old car radio buttons

Development

Web component development

Component reference

p-radioButton
p-radioButton
Module: RadioButtonModule - Package: primeng
⚠️ This component requires the use of Angular and will not work in non-Angular applications.

Allows the user to select one item from a short list, with all items visible in a vertical list

View the p-radioButton reference doc

If you're adding PrimeNG to your solution for the first time, reference their setup documentation. It's important to note that the inclusion of the nova-light theme css is not necessary to work with Responsive UI. Styling for the PrimeNG components is provided by Responsive UI's theming.

Implementation

Start by importing the RadioButtonModule module into your application.

Import the module
import { RadioButtonModule } from 'primeng/radiobutton';

Display one p-radioButton instance for each list item.

Radio button HTML
<p-radioButton id="accountType" *ngFor="let accountType of accountTypesList" name="accountTypeGroup" [value]="accountType"
 label="{{accountType}}" [formControl]="accountType">
</p-radioButton>

In the TypeScript, create an array with the radio button options. Due to a bug with the PrimeNG p-radioButton when used in a reactive form, you’ll need to subscribe to valueChanges so the user interface will correctly display the selected item. This is a known issue with PrimeNG and will be fixed in a future release.

Import the module
public accountTypesList: string[] = ['Customer Account', 'Employee Account', 'Shareholder Account'];

constructor() {
    // Capture primeng radio buttons
    const accountType: any = this.editForm.get('accountType');

    // Manually subscribe to value changes on radio button changes and propagate back out 
    // due to bug in PrimeNG component: https://github.com/primefaces/primeng/issues/9162
    accountType.valueChanges.subscribe((value: any) => accountType.setValue(value, { emitEvent: false }));
}
The PrimeNG p-radioButton does not currently support selected or disabled states. All disabled radio buttons display as unselected.

Angular component development

Component reference

p-radioButton
p-radioButton
Module: RadioButtonModule - Package: primeng

Allows the user to select one item from a short list, with all items visible in a vertical list

View the p-radioButton reference doc

If you're adding PrimeNG to your solution for the first time, reference their setup documentation. It's important to note that the inclusion of the nova-light theme css is not necessary to work with Responsive UI. Styling for the PrimeNG components is provided by Responsive UI's theming.

Implementation

Start by importing the RadioButtonModule module into your application.

Import the module
import { RadioButtonModule } from 'primeng/radiobutton';

Display one p-radioButton instance for each list item.

Radio button HTML
<p-radioButton id="accountType" *ngFor="let accountType of accountTypesList" name="accountTypeGroup" [value]="accountType"
 label="{{accountType}}" [formControl]="accountType">
</p-radioButton>

In the TypeScript, create an array with the radio button options. Due to a bug with the PrimeNG p-radioButton when used in a reactive form, you’ll need to subscribe to valueChanges so the user interface will correctly display the selected item. This is a known issue with PrimeNG and will be fixed in a future release.

Import the module
public accountTypesList: string[] = ['Customer Account', 'Employee Account', 'Shareholder Account'];

constructor() {
    // Capture primeng radio buttons
    const accountType: any = this.editForm.get('accountType');

    // Manually subscribe to value changes on radio button changes and propagate back out 
    // due to bug in PrimeNG component: https://github.com/primefaces/primeng/issues/9162
    accountType.valueChanges.subscribe((value: any) => accountType.setValue(value, { emitEvent: false }));
}
The PrimeNG p-radioButton does not currently support selected or disabled states. All disabled radio buttons display as unselected.

Design

Figma design

Figma design info
You can find this component in the Components - Forms page in the Figma UI Kit.
Dev ComponentDesign Component Name
Radio buttonRUI / Forms / Radio Button

Adobe XD design

Adobe XD design info
You can find this component in these artboards in the Adobe XD design samples:
  • Sample App - Editing Form Data
Dev ComponentDesign Component Name
Radio button - checkedJHA / Forms / Radio Button / Checked
Radio button - uncheckedJHA / Forms / Radio Button / Unchecked

Support options
Have questions on this topic?
Join the Responsive UI team in Microsoft Teams to connect with the community.
See something in this page that needs to change?
Send us feedback on this page.
Last updated Fri Jul 28 2023