RadioGroup
Radio button group with arrow-key navigation, horizontal/vertical layout, and per-option descriptions. Only the selected radio is in the tab order.
import { RadioGroup } from "phoundry-ui";Basic vertical
Loading interactive example…
View source
<script lang="ts"> import { RadioGroup } from "phoundry-ui"; import type { RadioOption } from "phoundry-ui";
let basicValue = $state("option1");
const basicOptions: RadioOption[] = [ { value: "option1", label: "Option 1" }, { value: "option2", label: "Option 2" }, { value: "option3", label: "Option 3" }, ];</script>
<div class="flex items-start gap-6"> <RadioGroup options={basicOptions} value={basicValue} onchange={(v: string) => (basicValue = v)} /> <span class="text-xs text-txt-tertiary" >Selected: <strong class="text-txt-primary">{basicValue}</strong></span ></div>Horizontal
Loading interactive example…
View source
<script lang="ts"> import { RadioGroup } from "phoundry-ui"; import type { RadioOption } from "phoundry-ui";
let horizValue = $state("sm");
const horizOptions: RadioOption[] = [ { value: "sm", label: "Small" }, { value: "md", label: "Medium" }, { value: "lg", label: "Large" }, ];</script>
<div class="flex items-center gap-6"> <RadioGroup options={horizOptions} value={horizValue} onchange={(v: string) => (horizValue = v)} orientation="horizontal" /> <span class="text-xs text-txt-tertiary" >Selected: <strong class="text-txt-primary">{horizValue}</strong></span ></div>With descriptions
Loading interactive example…
View source
<script lang="ts"> import { RadioGroup } from "phoundry-ui"; import type { RadioOption } from "phoundry-ui";
let descValue = $state("pro");
const descOptions: RadioOption[] = [ { value: "free", label: "Free", description: "Basic features for personal use", icon: "phoundry-ui:money-disabled", }, { value: "pro", label: "Pro", description: "Advanced features and priority support", icon: "phoundry-ui:money-disabled", }, { value: "enterprise", label: "Enterprise", description: "Custom solutions for large teams", icon: "phoundry-ui:money-disabled", }, ];</script>
<RadioGroup options={descOptions} value={descValue} onchange={(v: string) => (descValue = v)}/>Disabled option
Loading interactive example…
View source
<script lang="ts"> import { RadioGroup } from "phoundry-ui"; import type { RadioOption } from "phoundry-ui";
let disabledValue = $state("a");
const disabledOptions: RadioOption[] = [ { value: "a", label: "Available" }, { value: "b", label: "Also available" }, { value: "c", label: "Unavailable", disabled: true }, ];</script>
<RadioGroup options={disabledOptions} value={disabledValue} onchange={(v: string) => (disabledValue = v)}/>Sizes (sm / md)
Loading interactive example…
View source
<script lang="ts"> import { RadioGroup } from "phoundry-ui"; import type { RadioOption } from "phoundry-ui";
let sizeDemo = $state("sm");
const sizeOptions: RadioOption[] = [ { value: "sm", label: "Small" }, { value: "md", label: "Medium" }, ];</script>
<div class="flex flex-wrap items-start gap-8"> <div> <p class="mb-2 text-[10px] text-txt-tertiary"> size="sm" (default) </p> <RadioGroup options={sizeOptions} value={sizeDemo} onchange={(v: string) => (sizeDemo = v)} size="sm" /> </div> <div> <p class="mb-2 text-[10px] text-txt-tertiary">size="md"</p> <RadioGroup options={sizeOptions} value={sizeDemo} onchange={(v: string) => (sizeDemo = v)} size="md" /> </div></div>Group disabled
Loading interactive example…
View source
<script lang="ts"> import { RadioGroup } from "phoundry-ui"; import type { RadioOption } from "phoundry-ui";
let groupDisabledVal = $state("x");
const groupDisabledOptions: RadioOption[] = [ { value: "x", label: "One" }, { value: "y", label: "Two" }, ];</script>
<p class="mb-2 text-xs text-txt-secondary"> Disables the entire radiogroup- Individual option <code>disabled</code> flags add finer control.</p><RadioGroup options={groupDisabledOptions} value={groupDisabledVal} onchange={(v: string) => (groupDisabledVal = v)} disabled/>API
From phoundry-ui@0.4.21
| Name | Type | Default | Description |
|---|---|---|---|
optionsrequired | RadioOption[] | — | Array of { value, label, icon?, description?, disabled? } |
valuerequired | string | — | Currently selected value |
onchangerequired | (value: string) => void | — | Called when selection changes |
name | string | `radio-${Math.random().toString(36).slice(2, 8)}` | Group name (auto-generated if omitted) |
orientation | "horizontal" | "vertical" | 'vertical' | Layout direction |
size | "sm" | "md" | 'sm' | Size of radio circles and text |
disabled | boolean | false | Disables all options |
class | ClassValue | — | Additional CSS classes on the group container |
style | string | — | Inline styles on the component styling target described below. |
Usage tips
- Arrow keys move selection between enabled options - no need to Tab through each radio.
- Set
disabledon individual options to grey them out while keeping the rest interactive. - Use
orientation="horizontal"for compact option sets like size pickers. - The
descriptionfield on options is great for plan selectors or settings with context. - Set
namewhen embedding multiple groups in one form so browsers associate radios correctly (otherwise a random fallback name is generated).
Styling
.ph-radio-group is the stable root identification hook. Styling is component-local vanilla CSS; data-size always identifies the selected size. class and style apply to the group container. data-orientation exposes vertical or horizontal; each button exposes its selection through aria-checked and its disabled state through the native attribute. Sizes retain the existing circle, dot, and text dimensions. Arrow navigation skips disabled options and is inactive when the whole group is disabled. Internal part selectors and --_ph-* properties are implementation details. Filled indicators use the active Theme’s --text-on-accent foreground.