Radio Group
A cross-platform React radio group component that manages single selection across multiple radio buttons. Provides context to child Radio components for coordinated selection.
Installation
npm install @xsolla/xui-radio-group @xsolla/xui-radio
Demo
Basic Radio Group
import * as React from "react";
import { RadioGroup } from "@xsolla/xui-radio-group";
import { Radio } from "@xsolla/xui-radio";
export default function BasicRadioGroup() {
const [value, setValue] = React.useState("option1");
return (
<RadioGroup value={value} onChange={setValue}>
<Radio value="option1" label="Option 1" />
<Radio value="option2" label="Option 2" />
<Radio value="option3" label="Option 3" />
</RadioGroup>
);
}
Horizontal Layout
import * as React from "react";
import { RadioGroup } from "@xsolla/xui-radio-group";
import { Radio } from "@xsolla/xui-radio";
export default function HorizontalRadioGroup() {
const [size, setSize] = React.useState("md");
return (
<RadioGroup value={size} onChange={setSize} flexDirection="row" gap={24}>
<Radio value="sm" label="Small" />
<Radio value="md" label="Medium" />
<Radio value="lg" label="Large" />
</RadioGroup>
);
}
Radio Group with Descriptions
import * as React from "react";
import { RadioGroup } from "@xsolla/xui-radio-group";
import { Radio } from "@xsolla/xui-radio";
export default function RadioGroupWithDescriptions() {
const [plan, setPlan] = React.useState("starter");
return (
<RadioGroup value={plan} onChange={setPlan} gap={16}>
<Radio
value="starter"
label="Starter"
description="$9/month - Best for personal projects"
/>
<Radio
value="professional"
label="Professional"
description="$29/month - Best for small teams"
/>
<Radio
value="enterprise"
label="Enterprise"
description="Custom pricing - For large organizations"
/>
</RadioGroup>
);
}
Card View
RadioCard renders each option as a selectable card with a title, a
description and a radio indicator. The whole card is the click target, and
the selected card is filled with the brand-tinted control surface.
import * as React from "react";
import { RadioGroup, RadioCard } from "@xsolla/xui-radio-group";
export default function DistributionModelPicker() {
const [model, setModel] = React.useState("p2p");
return (
<RadioGroup view="card" value={model} onChange={setModel}>
<RadioCard
value="f2p"
title="Free-to-play (F2P)"
description="Players have free access to the game after downloading the launcher."
/>
<RadioCard
value="p2p"
title="Pay-to-play (P2P)"
description="Players must purchase the game to access it."
/>
<RadioCard
value="s2p"
title="Subscribe-to-play (S2P)"
description="Players must buy a subscription to access the game."
/>
</RadioGroup>
);
}
Two-Column Card Layout
columns lays the cards out side by side. Children are distributed
round-robin, so the reading order stays left-to-right then top-to-bottom.
Every card in a row is stretched to the height of the tallest one, so
descriptions that wrap to a different number of lines still line up. Use
columns — not flexDirection="row" — for a multi-column card layout.
import * as React from "react";
import { RadioGroup, RadioCard } from "@xsolla/xui-radio-group";
export default function SalesChannelPicker() {
const [channel, setChannel] = React.useState("launcher");
return (
<RadioGroup view="card" columns={2} value={channel} onChange={setChannel}>
<RadioCard
value="launcher"
title="Sell in launcher"
description="Players buy the game inside the launcher."
/>
<RadioCard
value="web"
title="Sell on the web"
description="Players buy the game on your web store."
/>
</RadioGroup>
);
}
Top-Aligned Card Content
In a stretched row, a card can end up taller than its own content. By default
its title and description are centred against the radio indicator. Pass
contentAlign="top" to pin the text to the top of the card instead — the
indicator stays vertically centred either way, which is the split a single
align-items on the card cannot express.
import * as React from "react";
import { RadioGroup, RadioCard } from "@xsolla/xui-radio-group";
export default function TopAlignedCards() {
const [channel, setChannel] = React.useState("launcher");
return (
<RadioGroup view="card" columns={2} value={channel} onChange={setChannel}>
<RadioCard
contentAlign="top"
value="launcher"
title="Sell in launcher"
description="After clicking the Buy button a payment widget opens, selling the game key under the SKU specified above."
/>
<RadioCard
contentAlign="top"
value="browser"
title="Sell in browser"
description="After clicking the Buy button the link opens in a browser."
/>
</RadioGroup>
);
}
Disabled Radio Group
import * as React from "react";
import { RadioGroup } from "@xsolla/xui-radio-group";
import { Radio } from "@xsolla/xui-radio";
export default function DisabledRadioGroup() {
return (
<RadioGroup value="option1" disabled>
<Radio value="option1" label="Option 1" />
<Radio value="option2" label="Option 2" />
<Radio value="option3" label="Option 3" />
</RadioGroup>
);
}
Anatomy
Import the components and compose them:
import { RadioGroup } from "@xsolla/xui-radio-group";
import { Radio } from "@xsolla/xui-radio";
<RadioGroup
value={selectedValue} // Currently selected value
onChange={handleChange} // Selection change handler
size="md" // Size for all child radios
disabled={false} // Disable all radios
flexDirection="column" // Layout direction
gap={12} // Gap between items
>
<Radio value="a" label="Option A" />
<Radio value="b" label="Option B" />
<Radio value="c" label="Option C" />
</RadioGroup>;
Examples
Form Integration
import * as React from "react";
import { RadioGroup } from "@xsolla/xui-radio-group";
import { Radio } from "@xsolla/xui-radio";
import { Button } from "@xsolla/xui-button";
export default function FormRadioGroup() {
const [shipping, setShipping] = React.useState("");
const [error, setError] = React.useState("");
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
if (!shipping) {
setError("Please select a shipping method");
return;
}
console.log("Selected shipping:", shipping);
};
return (
<form onSubmit={handleSubmit}>
<h3 id="shipping-label">Select Shipping Method</h3>
<RadioGroup
value={shipping}
onChange={(v) => {
setShipping(v);
setError("");
}}
aria-labelledby="shipping-label"
aria-describedby={error ? "shipping-error" : undefined}
>
<Radio
value="standard"
label="Standard Shipping"
description="5-7 business days - Free"
/>
<Radio
value="express"
label="Express Shipping"
description="2-3 business days - $9.99"
/>
<Radio
value="overnight"
label="Overnight Shipping"
description="Next business day - $24.99"
/>
</RadioGroup>
{error && (
<p id="shipping-error" role="alert" style={{ color: "red" }}>
{error}
</p>
)}
<Button type="submit" style={{ marginTop: 16 }}>
Continue
</Button>
</form>
);
}
Different Sizes
import * as React from "react";
import { RadioGroup } from "@xsolla/xui-radio-group";
import { Radio } from "@xsolla/xui-radio";
export default function RadioGroupSizes() {
const [value, setValue] = React.useState("a");
return (
<div style={{ display: "flex", gap: 48 }}>
<div>
<h4>Small</h4>
<RadioGroup value={value} onChange={setValue} size="sm">
<Radio value="a" label="Option A" />
<Radio value="b" label="Option B" />
</RadioGroup>
</div>
<div>
<h4>Large</h4>
<RadioGroup value={value} onChange={setValue} size="lg">
<Radio value="a" label="Option A" />
<Radio value="b" label="Option B" />
</RadioGroup>
</div>
</div>
);
}
API Reference
RadioGroup
Container component that provides selection context to Radio children.
RadioGroup Props:
| Prop |
Type |
Default |
Description |
testID |
string |
— |
Test ID for testing frameworks. On web this renders as data-testid; on React Native it renders as testID. |
| children |
ReactNode |
- |
Required. Radio components to group. |
| value |
string |
- |
Currently selected value. |
| onChange |
(value: string) => void |
- |
Callback when selection changes. |
| size |
"sm" \| "md" \| "lg" \| "xl" |
"md" |
Size applied to all child Radio components. |
| disabled |
boolean |
false |
Whether all radios are disabled. |
| flexDirection |
"row" \| "column" |
"column" |
Layout direction of the group. |
| gap |
number |
12 / 4 |
Gap between items in pixels. Defaults to 4 when view="card". |
| view |
"default" \| "card" |
"default" |
Visual treatment of the options. "card" is for RadioCard children. |
| columns |
number |
1 |
Number of equal-width columns. Values above 1 take precedence over flexDirection, and stretch every option in a row to the height of the tallest one. |
RadioCard
A selectable card option. Renders a title, an optional description and a radio
indicator, with the whole card as the click target. Must be used inside a
RadioGroup, which owns the selected value.
RadioCard Props:
| Prop |
Type |
Default |
Description |
testID |
string |
— |
Test ID for testing frameworks. |
| value |
string |
- |
Required. Value this card selects in the parent group. |
| title |
string |
- |
Required. Primary line of the card. |
| description |
string |
- |
Supporting line rendered under the title. |
| size |
"sm" \| "md" \| "lg" \| "xl" |
group |
Size of the card and its indicator. Falls back to the group's size. |
| checked |
boolean |
group |
Selected state. Normally derived from the parent group's value. |
| disabled |
boolean |
false |
Disables this card only. The group's disabled disables every card. |
| padding |
number \| string |
by size |
Overrides the size-derived internal padding (8/12/16/16 vertical, 12/16/16/20 horizontal). |
| contentAlign |
"center" \| "top" |
"center" |
Where the title/description block sits when the card is taller than its own content. The radio indicator stays vertically centred either way. |
| onPress |
() => void |
- |
Called after the card is selected, in addition to the group's onChange. |
| themeMode |
ThemeMode |
context |
Per-component theme mode override. |
RadioGroup Context
RadioGroup provides context to child Radio components:
interface RadioGroupContextProps {
value?: string; // Currently selected value
onChange?: (value: string) => void; // Selection handler
size?: "sm" | "md" | "lg" | "xl"; // Size for radios
disabled?: boolean; // Disabled state
view?: "default" | "card"; // Visual treatment
}
Child Radio components automatically:
- Sync their checked state with the group value
- Call the group's onChange when selected
- Inherit size and disabled props from the group
Accessibility
- RadioGroup renders
role="radiogroup" and provides proper grouping semantics
- Only one radio can be selected at a time
RadioCard carries the role="radio" semantics and the tab stop itself, so
its indicator is presentational and never becomes a second tab stop
RadioCard responds to both Space and Enter
- Arrow keys navigate between options when focused
- Tab key moves focus to/from the group
- Disabled state properly communicated to all children