Introducing PrimeReact v11-alpha 🎉Discover Now

RadioButton

RadioButton is an extension to standard radio button element with theming.

Select a deployment environment:
preview

Installation#

npx shadcn@latest add @primereact/ui/radiobutton

Usage#

import { RadioButton, RadioButtonGroup } from '@/components/ui/radiobutton';
<RadioButtonGroup>
    <RadioButton />
</RadioButtonGroup>

Examples#

Basic#

basic-demo

Group#

Use the RadioButton.Group component with value and onValueChange props to control the selected state of radio buttons.

group-demo

Dynamic#

RadioButtons can be generated using a list of values.

dynamic-demo

Card#

RadioButtons can be displayed in a card style.

Select a payment method:
card-demo

Sizes#

Use the size property to change the size of a radio button.

sizes-demo

Filled#

Specify the filled property to display the component with a higher visual emphasis than the default outlined style.

filled-demo

Disabled#

When the disabled property is present, the element cannot be edited and focused.

disabled-demo

Invalid#

Invalid state is displayed using the invalid property to indicate a failed validation. You can use this style when integrating with form validation libraries.

invalid-demo

Accessibility#

Screen Reader#

RadioButton component uses a hidden native radio button element internally that is only visible to screen readers. Value to describe the component can either be provided via label tag combined with id prop or using aria-labelledby, aria-label props.

<label for="rb1">One</label>
<RadioButton inputId="rb1" />
 
<span id="rb2">Two</span>
<RadioButton aria-labelledby="rb2" />
 
<RadioButton aria-label="Three" />