Skip to main content
Version: 3.0.0-beta

Radio Group

Radio Group allows users to select one option from a set. It's useful for exclusive selection scenarios where only one choice is permissible. Each radio group item is represented by a RadioGroupItem component, and typically wrapped by a Label component.

Usage

To use the RadioGroup and RadioGroupItem, import them from your components and structure your options using the RadioGroup as the container and RadioGroupItem for each option.

Basic Radio Group

A basic example of a radio group, allowing for simple selection.

import React from "react";
import { Label, RadioGroup, RadioGroupItem } from "@firecms/ui";

export default function RadioGroupBasicDemo() {
return (
<RadioGroup onValueChange={(value) => console.log(value)}>
<Label
className="flex items-center gap-2"
htmlFor="color-black">
<RadioGroupItem id="color-black" value="black"/>
Black
</Label>
<Label
className="flex items-center gap-2"
htmlFor="color-white">
<RadioGroupItem id="color-white" value="white"/>
White
</Label>
<Label
className="flex items-center gap-2"
htmlFor="color-blue">
<RadioGroupItem id="color-blue" value="blue"/>
Blue
</Label>
</RadioGroup>
);
}

Customizing Radio Group Item Appearance

This example demonstrates how to customize the appearance of individual radio group items.

import React from "react";
import { Label, RadioGroup, RadioGroupItem } from "@firecms/ui";

export default function RadioGroupCustomDemo() {
return (
<RadioGroup onValueChange={(value) => console.log(value)}>
<Label
className="border cursor-pointer rounded-md p-2 flex items-center gap-2 [&:has(:checked)]:bg-gray-100 dark:[&:has(:checked)]:bg-gray-800"
htmlFor="size-small">
<RadioGroupItem id="size-small" value="small"/>
Small
</Label>
<Label
className="border cursor-pointer rounded-md p-2 flex items-center gap-2 [&:has(:checked)]:bg-gray-100 dark:[&:has(:checked)]:bg-gray-800"
htmlFor="size-medium">
<RadioGroupItem id="size-medium" value="medium"/>
Medium
</Label>
<Label
className="border cursor-pointer rounded-md p-2 flex items-center gap-2 [&:has(:checked)]:bg-gray-100 dark:[&:has(:checked)]:bg-gray-800"
htmlFor="size-large">
<RadioGroupItem id="size-large" value="large"/>
Large
</Label>
</RadioGroup>
);
}

Disabled Radio Group

How to disable the entire radio group or individual items within it.

import React from 'react';
import { RadioGroup, RadioGroupItem } from "@firecms/ui";

export default function RadioGroupDisabledDemo() {
return (
<RadioGroup>
<RadioGroupItem value="1">Disabled Option 1</RadioGroupItem>
<RadioGroupItem value="2" disabled>Disabled Option 2</RadioGroupItem>
<RadioGroupItem value="3">Disabled Option 3</RadioGroupItem>
</RadioGroup>
);
}
Sign up to our newsletter to get the latest news and updates. No spam!