For AI agents: the complete documentation index is available at https://ifhover.github.io/leaf-ui/v/0.6.0/en/llms.txt, the full documentation bundle is available at https://ifhover.github.io/leaf-ui/v/0.6.0/en/llms-full.txt, and this page is available as Markdown at https://ifhover.github.io/leaf-ui/v/0.6.0/en/components/radio.md.
  • English
  • Radio

    Choose one option from a group.

    Examples

    RadioGroup builds options and supplies a group name. Provide label, aria-label or aria-labelledby. Give the group a name for form submission. Read event.target.value in onChange. Individual Radio controls with the same name form a native group.

    Choose appearance
    basic.tsx
    import { RadioGroup } from '@ifhover/leaf-ui';
    
    export function RadioBasic() {
      return (
        <RadioGroup
          label="Choose appearance"
          name="appearance"
          defaultValue="light"
          options={[
            { label: 'Light', value: 'light' },
            { label: 'Dark', value: 'dark' },
            { label: 'System', value: 'system' },
            { label: 'Custom (unavailable)', value: 'custom', disabled: true },
          ]}
        />
      );
    }
    
    Notification frequency
    Selected:daily
    controlled.tsx
    import { RadioGroup, Space, Text } from '@ifhover/leaf-ui';
    
    import { useState } from 'react';
    
    export function RadioControlled() {
      const [value, setValue] = useState('daily');
      return (
        <Space direction="vertical" align="stretch">
          <RadioGroup
            label="Notification frequency"
            direction="vertical"
            value={value}
            onChange={(event) => setValue(event.target.value)}
            options={[
              { label: 'Daily', value: 'daily' },
              { label: 'Weekly', value: 'weekly' },
              { label: 'Important messages only', value: 'important' },
            ]}
          />
          <Text tone="muted">Selected:{value}</Text>
        </Space>
      );
    }
    

    Card choices

    Use icons and descriptions to help people choose a plan.

    Backup method
    surfaces.tsx
    import { RadioGroup } from '@ifhover/leaf-ui';
    
    import { Cloud, HardDrive } from 'lucide-react';
    
    export function RadioCards() {
      
      return (
        <RadioGroup
          variant="card"
          label={'Backup method'}
          defaultValue="cloud"
          options={[
            {
              value: 'cloud',
              label: 'Cloud backup',
              description: 'Sync across your devices',
              icon: <Cloud />,
            },
            {
              value: 'local',
              label: 'Local backup',
              description: 'Keep data on this device',
              icon: <HardDrive />,
            },
          ]}
        />
      );
    }
    

    Grouped choices

    Group choices into one list while retaining native arrow-key navigation.

    Access policy
    surfaces.tsx
    import { RadioGroup, Tag } from '@ifhover/leaf-ui';
    
    import { ShieldCheck } from 'lucide-react';
    
    export function RadioList() {
      
      return (
        <RadioGroup
          variant="list"
          label={'Access policy'}
          defaultValue="readonly"
          options={[
            {
              value: 'readonly',
              label: 'Read-only access',
              description: 'Allow reading and require approval for changes',
              icon: <ShieldCheck />,
              extra: (
                <Tag color="success" size="sm">
                  {'Recommended'}
                </Tag>
              ),
            },
            {
              value: 'review',
              label: 'Approve every request',
              description: 'Ask the owner to approve every action',
            },
          ]}
        />
      );
    }
    

    RadioGroup API

    PropertyTypeDefaultDescription
    optionsreadonly RadioOption[]RequiredRequired. Options
    valuestring—Controlled value / initial uncontrolled value
    defaultValuestring—Controlled value / initial uncontrolled value
    namestringGeneratedShared field name; specify it for form submission
    labelReactNode—Group name
    size'sm' | 'md' | 'lg''md'Control size
    variant'plain' | 'card' | 'list''plain'Plain choices, a card grid or a list with shared borders and dividers.
    direction'horizontal' | 'vertical''horizontal'Layout direction
    requiredbooleanfalseRequire a non-empty value; compound controls validate once.
    onChangeChangeEventHandler<HTMLInputElement>—Read event.target.value
    disabledbooleanfalseDisable interaction.
    refRef<HTMLFieldSetElement>—DOM reference

    Radio API

    PropertyTypeDefaultDescription
    size'sm' | 'md' | 'lg''md'Control size
    variant'plain' | 'card''plain'Plain choice or a card with a full clickable surface.
    descriptionReactNode—Additional description.
    iconReactNode—Icon content.
    extraReactNode—Supplementary status or tags; avoid interactive controls.
    checkedboolean—Controlled checked state / initial checked state
    defaultCheckedboolean—Controlled checked state / initial checked state
    valuestringRequiredControlled value.
    namestring—Field name in native FormData.
    onChangeChangeEventHandler<HTMLInputElement>—Called when the value changes.
    disabledbooleanfalseDisable interaction.
    requiredbooleanfalseRequire a non-empty value; compound controls validate once.
    childrenReactNode—Content, or child nodes for hierarchical records.
    refRef<HTMLInputElement>—DOM reference

    RadioOption

    PropertyTypeDefaultDescription
    labelstringRequiredOption label
    valuestringRequiredValue; unique within the group
    disabledbooleanfalseDisable the option

    Types

    Import RadioProps to describe component props. Option types in the API table link to their detailed fields above.

    import type { RadioProps, RadioGroupProps, RadioOption } from '@ifhover/leaf-ui';

    Forms and localization

    Use name to include values in FormData. Uncontrolled fields follow form reset; reset controlled values in application state. Place controls in FormField for labels, help and errors. ConfigProvider supplies regional themes and translated built-in UI. Application labels and options are your responsibility.

    Surfaces and rich content

    Radio and RadioGroup support icons, descriptions and status tags. RadioGroup variant="card" arranges cards; variant="list" creates grouped rows. description and extra are accessible descriptions; avoid buttons or links in extra. Groups retain native arrow keys, disabled-option skipping and form submission.

    RadioOption

    PropertyTypeDefaultDescription
    labelReactNode—Required. Visible label or content.
    descriptionReactNode—Additional description.
    iconReactNode—Icon content.
    extraReactNode—Supplementary status or tags; avoid interactive controls.
    valuestring—Required. Controlled value.
    disabledboolean—Disable interaction.