RadioGroup
Single choice from a short list, with roving focus and labelled items.
Example
import { RadioGroup, RadioGroupItem } from "@porcelana/ui";
export default function Example() {
return (
<RadioGroup aria-label="Wake-up time" defaultValue="06:00">
<RadioGroupItem value="05:30" label="05:30" />
<RadioGroupItem value="06:00" label="06:00" />
<RadioGroupItem value="07:15" label="07:15" />
</RadioGroup>
);
}Import
import { RadioGroup, RadioGroupItem } from "@porcelana/ui";
import "@porcelana/ui/styles.css"; // once, at your app rootProps
Generated from the TypeScript types. Standard HTML attributes are passed through and not listed.
RadioGroup
| Prop | Type | Default | Description |
|---|---|---|---|
aria-label | string | – | Defines a string value that labels the current element. @see aria-labelledby. |
asChild | boolean | – | Render the single child element instead, merging props and behaviour onto it. |
defaultValue | string | – | Initial value when uncontrolled. |
dir | Direction | – | Reading direction for keyboard navigation ("ltr" or "rtl"). |
disabled | boolean | – | Prevents interaction and dims the control. |
form | string | – | Id of the form this control belongs to. |
id | string | – | Element id. Generated automatically when omitted. |
loop | boolean | – | Whether keyboard navigation wraps from the last item to the first. |
name | string | – | Field name submitted with a form. |
onValueChange | ((value: string) => void) | – | Called with the new value. |
orientation | Orientation | – | Layout and arrow-key direction. |
required | boolean | – | Marks the control as required in forms. |
value | string | null | – | Controlled value. Use with onValueChange. |
RadioGroupItem
| Prop | Type | Default | Description |
|---|---|---|---|
labelrequired | ReactNode | – | Visible label; the whole row is the touch target. |
aria-label | string | – | Defines a string value that labels the current element. @see aria-labelledby. |
asChild | boolean | – | Render the single child element instead, merging props and behaviour onto it. |
checked | boolean | – | Controlled checked state. Use with onCheckedChange. |
disabled | boolean | – | Prevents interaction and dims the control. |
id | string | – | Element id. Generated automatically when omitted. |
required | boolean | – | Marks the control as required in forms. |
type | "button" | "submit" | "reset" | – | Button type (defaults to "button"). |
value | string | null | – | Controlled value. Use with onValueChange. |
Accessibility
- Tab enters the group once; arrow keys move between options and Space selects.
- Give the group an aria-label or wrap it in a labelled fieldset.
Mobile
- Each option row is at least 44px tall.
- Set orientation="horizontal" for a wrapping row.