RadioGroup
RadioGroup composes Base UI’s radio group, root, and indicator with Density control attributes on each radio root.
CompactComfortable
import { useState } from "react";
import { RadioGroup } from "density-base-ui";
export default function RadioExample() {
const [density, setDensity] = useState("compact");
const updateDensity = (value: unknown) => {
if (typeof value === "string") {
setDensity(value);
}
};
return (
<RadioGroup
value={density}
onValueChange={updateDensity}
items={[
{ value: "compact", label: "Compact" },
{ value: "comfortable", label: "Comfortable" },
]}
/>
);
}Label and hint
LightDark
Applied to this workspace.import { RadioGroup } from "density-base-ui";
export default function RadioFieldExample() {
return (
<RadioGroup
label="Theme"
hint="Applied to this workspace."
items={[
{ value: "light", label: "Light" },
{ value: "dark", label: "Dark" },
]}
value="dark"
/>
);
}Error
LightDark
Choose a theme.import { RadioGroup } from "density-base-ui";
export default function RadioErrorExample() {
return (
<RadioGroup
errorMessage="Choose a theme."
hint="Applied to this workspace."
items={[
{ value: "light", label: "Light" },
{ value: "dark", label: "Dark" },
]}
label="Theme"
/>
);
}Field orientation
Enabled
Enabled
import { RadioGroup, Separator, View } from "density-base-ui";
const items = [{ value: "on", label: "Enabled" }];
export default function RadioFieldOrientationExample() {
return (
<View>
<RadioGroup
fieldOrientation="vertical"
label="Vertical"
items={items}
value="on"
/>
<Separator />
<RadioGroup
fieldOrientation="horizontal"
label="Horizontal"
items={items}
value="on"
/>
</View>
);
}Emphasis
Enabled
Enabled
Enabled
Enabled
import { RadioGroup, View } from "density-base-ui";
const items = [{ value: "on", label: "Enabled" }];
export default function RadioEmphasisExample() {
return (
<View>
<RadioGroup
aria-label="Primary radio"
emphasis="primary"
items={items}
value="on"
/>
<RadioGroup
aria-label="Secondary radio"
emphasis="secondary"
items={items}
value="on"
/>
<RadioGroup
aria-label="Outline radio"
emphasis="outline"
items={items}
value="on"
/>
<RadioGroup
aria-label="Ghost radio"
emphasis="ghost-primary"
items={items}
value="on"
/>
</View>
);
}Size
Enabled
Enabled
Enabled
Enabled
Enabled
Enabled
Enabled
Enabled
import { RadioGroup, View } from "density-base-ui";
const items = [{ value: "on", label: "Enabled" }];
export default function RadioSizeExample() {
return (
<View>
<RadioGroup aria-label="2xs radio" items={items} size="2xs" value="on" />
<RadioGroup aria-label="xs radio" items={items} size="xs" value="on" />
<RadioGroup aria-label="sm radio" items={items} size="sm" value="on" />
<RadioGroup aria-label="md radio" items={items} size="md" value="on" />
<RadioGroup aria-label="lg radio" items={items} size="lg" value="on" />
<RadioGroup aria-label="xl radio" items={items} size="xl" value="on" />
<RadioGroup aria-label="2xl radio" items={items} size="2xl" value="on" />
<RadioGroup aria-label="3xl radio" items={items} size="3xl" value="on" />
</View>
);
}| Prop | Values | Required | Default | Behavior | Description |
|---|---|---|---|---|---|
emphasis | primary, secondary, outline, ghost-primary, ghost-secondary, ghost-tertiary | Not required | — | — | — |
errorMessage | React.ReactNode | Not required | — | — | — |
fieldOrientation | vertical, horizontal | Not required | — | — | — |
hint | React.ReactNode | Not required | — | — | — |
items | RadioItem[] | Required | — | — | — |
label | React.ReactNode | Not required | — | — | — |
size | 2xs, xs, sm, md, lg, xl, 2xl, 3xl | Not required | — | — | — |
This component also accepts props from native APIs. They are passed through and intentionally kept out of this focused Density API table.