Skip to content

← All components

Actions and forms

RadioGroup

Labelled single-selection group with validation and orientation.

Live example

Choose a plan
You can change this later.

Usage

Each example includes the complete adapter-specific parameter reference. Copy it as a starting point, then remove options your use case does not need.

React

tsx
import { RadioGroup } from "@cofob/design-system-react";

/**
 * Complete RadioGroup parameter reference.
 * @param value/defaultValue
 *   type: string or string[]; controlled or initial value
 *   default: —
 *   example: "overview"
 * @param name
 *   type: string
 *   required
 *   example: "Ada Lovelace"
 * @param label
 *   type: string | renderable content
 *   required
 *   example: "Accessible label"
 * @param options
 *   type: readonly { value; label; description?; disabled? }[]
 *   default: —
 *   example: {{ cols: 100, fit: "width" }}
 * @param description
 *   type: string | renderable content
 *   default: —
 *   example: "Supporting context for this control."
 * @param error
 *   type: string | renderable content
 *   default: —
 *   example: "Enter a valid value."
 * @param orientation
 *   type: "horizontal" | "vertical"
 *   default: "vertical"
 *   example: "horizontal"
 * @param disabled
 *   type: boolean
 *   default: false
 *   example: {disabled}
 * @param onValueChange
 *   type: (value: string) => void
 *   default: —
 *   example: {handleValueChange}
 * @param children
 *   type: ReactNode | Svelte Snippet | child HTML
 *   default: —
 *   example: children / snippet / child HTML
 * @param fieldset attributes
 *   type: native element attributes
 *   default: —
 *   example: class / style / aria-* / data-*
 */
export function RadioGroupExample() {
  return (
    <RadioGroup name="plan" label="Plan" options={plans} defaultValue="pro" />
  );
}

Svelte

svelte
<script lang="ts">
  import { RadioGroup } from "@cofob/design-system-svelte";

  // Complete RadioGroup parameter reference.
  // value/defaultValue
  //   type: string or string[]; controlled or initial value
  //   default: —
  //   example: "overview"
  // name
  //   type: string
  //   required
  //   example: "Ada Lovelace"
  // label
  //   type: string | renderable content
  //   required
  //   example: "Accessible label"
  // options
  //   type: readonly { value; label; description?; disabled? }[]
  //   default: —
  //   example: {{ cols: 100, fit: "width" }}
  // description
  //   type: string | renderable content
  //   default: —
  //   example: "Supporting context for this control."
  // error
  //   type: string | renderable content
  //   default: —
  //   example: "Enter a valid value."
  // orientation
  //   type: "horizontal" | "vertical"
  //   default: "vertical"
  //   example: "horizontal"
  // disabled
  //   type: boolean
  //   default: false
  //   example: {disabled}
  // onValueChange
  //   type: (value: string) => void
  //   default: —
  //   example: {handleValueChange}
  // children
  //   type: ReactNode | Svelte Snippet | child HTML
  //   default: —
  //   example: children / snippet / child HTML
  // fieldset attributes
  //   type: native element attributes
  //   default: —
  //   example: class / style / aria-* / data-*
</script>

<RadioGroup name="plan" label="Plan" options={plans} bind:value />

HTML

html
<!--
  Complete RadioGroup parameter reference.
  value/defaultValue
    type: string or string[]; controlled or initial value
    default: —
    example: "overview"
  name
    type: string
    required
    example: "Ada Lovelace"
  label
    type: string | renderable content
    required
    example: "Accessible label"
  options
    type: readonly { value; label; description?; disabled? }[]
    default: —
    example: {{ cols: 100, fit: "width" }}
  description
    type: string | renderable content
    default: —
    example: "Supporting context for this control."
  error
    type: string | renderable content
    default: —
    example: "Enter a valid value."
  orientation
    type: "horizontal" | "vertical"
    default: "vertical"
    example: "horizontal"
  disabled
    type: boolean
    default: false
    example: {disabled}
  onValueChange
    type: (value: string) => void
    default: —
    example: {handleValueChange}
  children
    type: ReactNode | Svelte Snippet | child HTML
    default: —
    example: children / snippet / child HTML
  fieldset attributes
    type: native element attributes
    default: —
    example: class / style / aria-* / data-*
-->
<fieldset class="cf-radio-group"><legend>Plan</legend>…</fieldset>

<script type="module">
  import { initDesignSystem } from "@cofob/design-system-css";

  const designSystem = initDesignSystem(document);
  window.addEventListener("pagehide", () => designSystem.destroy(), { once: true });
</script>

Parameters

Adapter differences are explicit. Native element attributes are forwarded in React and Svelte and can be written directly in HTML.

ParameterTypeDefaultAdaptersExampleDescription
value/defaultValuestring or string[]; controlled or initial valueReact · Svelte · HTML"overview"Use the first form for controlled state and the second for initial state.
namerequiredstringrequiredReact · Svelte · HTML"Ada Lovelace"Identifies a native form field or named entity, depending on the component.
labelrequiredstring | renderable contentrequiredReact · Svelte · HTML"Accessible label"Visible or accessible name, depending on the component.
optionsreadonly { value; label; description?; disabled? }[]React · Svelte · HTML{{ cols: 100, fit: "width" }}Component-specific choices or configuration options.
descriptionstring | renderable contentReact · Svelte · HTML"Supporting context for this control."Supporting explanatory content.
errorstring | renderable contentReact · Svelte · HTML"Enter a valid value."Validation message and invalid visual/ARIA state.
orientation"horizontal" | "vertical""vertical"React · Svelte · HTML"horizontal"Sets layout and the matching keyboard navigation axis or ARIA orientation.
disabledbooleanfalseReact · Svelte · HTML{disabled}Prevents user interaction while preserving visible context.
onValueChange(value: string) => voidReact · Svelte · HTML{handleValueChange}Reports a user-driven tab or accordion value change.
childrenReactNode | Svelte Snippet | child HTMLReact · Svelte · HTMLchildren / snippet / child HTMLIdiomatic adapter composition content.
fieldset attributesnative element attributesReact · Svelte · HTMLclass / style / aria-* / data-*Forwards native class/style, accessibility, event, and data attributes to the root element.