Radio Group

A Radio Group component is a UI element that allows users to select one option from a set of mutually exclusive choices. It typically consists of multiple radio buttons, where only one button can be selected at a time. Radio groups are commonly used in forms to gather user preferences, ensuring a clear and organized way to present options for selection. They enhance user experience by providing a straightforward interface for making single-choice decisions.

Demo

Rendered live, with the same build of the library you install.

Horizontal:

Vertical:

Usage

RadioGroup.tsx
import { useState } from 'react';
import { NRadioGroup } from '@nayan-ui/react';
const items = [
{ label: 'Startup', value: 'startup' },
{ label: 'Business', value: 'business' },
{ label: 'Enterprise', value: 'enterprise' }
];
const RadioGroup = () => {
const [value, setValue] = useState('startup');
return (
<div>
<h1 className="text-foreground mb-3 text-base">Horizontal:</h1>
<NRadioGroup label="Plan" items={items} value={value} onChange={setValue} />
<div className="mt-5" />
<h1 className="text-foreground mb-3 text-base">Vertical:</h1>
<NRadioGroup orientation="vertical" label="Plan" items={items} value={value} onChange={setValue} />
</div>
);
};
export default RadioGroup;

Attributes

12 props
NameTypeDefaultDetails
orientation'horizontal' | 'vertical'OptionalOrientation of radio group.
itemsRadioItem[]RequiredArray of radio items.
classNamestring' 'You can customise by passing tailwind classes.
idstringOptionalID for the radio group.
labelstringOptionalLabel for the radio group.
itemClassNamestring' 'You can customise by passing tailwind classes.
radioClassNamestring' 'You can customise by passing tailwind classes.
labelClassNamestring' 'You can customise by passing tailwind classes.
disabledbooleanfalseWhether the radio group is disabled.
valuestringRequiredSelected radio value.
onChange(selected: string) => voidRequiredCallback when selection changes.
showLabelbooleanOptionalWhether to show labels.

Tags

Other components solving nearby problems.