Get Started
Components
Dev Tools
More Guides
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
Horizontal:
Vertical:
# Attributes
Name | Type | Default | Details |
---|---|---|---|
className | string | ' ' | You can customise by passing tailwind classes. |
itemClassName | string | ' ' | You can customise by passing tailwind classes. |
radioClassName | string | ' ' | You can customise by passing tailwind classes. |
labelClassName | string | ' ' | You can customise by passing tailwind classes. |
orientation | vertical | horizontal | horizontal | You can pass radio group orientation. |
disabled | boolean | false | You can pass disabled to set default checkbox state. |
items | RadioItem[] | Required | You can pass list of radio items. |
selected | string | Required | You can pass default selected item. |
onChange | (selected: string) => void | Required | You can get callback when radio group changed. |
# Usage
import { useState } from 'react';
import { NRadioGroup } from 'nayan';
const items = [
{ value: 'startup', label: 'Startup' },
{ value: 'business', label: 'Business' },
{ value: 'enterprise', label: 'Enterprise' }
];
const RadioGroupExample = () => {
const [selected, setSelected] = useState(items[0].value);
return (
<div>
<h1 className="text-text mb-3 text-base">Horizontal:</h1>
<NRadioGroup items={items} selected={selected} setSelected={setSelected} />
<div className="mt-5" />
<h1 className="text-text mb-3 text-base">Vertical:</h1>
<NRadioGroup orientation="vertical" items={items} selected={selected} setSelected={setSelected} />
</div>
);
};
export default RadioGroup;
# Tags