# Radio group

shadcn radio group with a pixel ring and dot.

Source: https://www.ui95.dev/ui/radio-group

## Examples

```tsx
import { Label } from "@/components/ui/label"
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"

import type { ShowcaseDemo } from "../types"

const DRIVES = ["A:", "C:", "D:"] as const

function renderGroup(idPrefix: string, options: { isInvalid?: boolean; isDisabled?: boolean; isHorizontal?: boolean }) {
  return (
    <RadioGroup
      defaultValue="C:"
      aria-label="Drive"
      disabled={options.isDisabled}
      className={options.isHorizontal ? "flex flex-wrap gap-5" : undefined}
    >
      {DRIVES.map((drive) => (
        <div key={drive} className="flex items-center gap-3">
          <RadioGroupItem
            id={`${idPrefix}-${drive}`}
            value={drive}
            aria-invalid={options.isInvalid}
            disabled={drive === "A:" && !options.isDisabled ? true : undefined}
          />
          <Label htmlFor={`${idPrefix}-${drive}`}>{drive}</Label>
        </div>
      ))}
    </RadioGroup>
  )
}

export const demo: ShowcaseDemo = {
  span: "single",
  variants: [
    { label: "vertical, A: disabled", render: () => renderGroup("radio-vertical", {}) },
    { label: "horizontal", render: () => renderGroup("radio-horizontal", { isHorizontal: true }) },
    { label: "invalid", render: () => renderGroup("radio-invalid", { isInvalid: true, isHorizontal: true }) },
    { label: "group disabled", render: () => renderGroup("radio-disabled", { isDisabled: true, isHorizontal: true }) },
  ],
}
```

## Installation

```bash
npx shadcn@latest add https://www.ui95.dev/r/radio-group.json
```

Run it in a Radix shadcn project that already has the UI95 theme.

Dependencies:

```bash
npm install cn radix-ui
```

Add these items first:

- [pixel-glyphs](https://www.ui95.dev/ui/pixel-glyphs)

`components/ui/radio-group.tsx`

```tsx
"use client"

import { cn } from "cn"
import { RadioGroup as RadioGroupPrimitive } from "radix-ui"
import * as React from "react"

import { RadioDotGlyph, RadioRingGlyph } from "@/components/ui/pixel-glyphs"

function RadioGroup({
  className,
  ...props
}: React.ComponentProps<typeof RadioGroupPrimitive.Root>) {
  return (
    <RadioGroupPrimitive.Root
      data-slot="radio-group"
      className={cn("grid w-full gap-3", className)}
      {...props}
    />
  )
}

function RadioGroupItem({
  className,
  ...props
}: React.ComponentProps<typeof RadioGroupPrimitive.Item>) {
  return (
    <RadioGroupPrimitive.Item
      data-slot="radio-group-item"
      className={cn(
        "group/radio-group-item peer relative grid size-5 shrink-0 place-items-center text-foreground after:absolute after:-inset-x-3 after:-inset-y-2 disabled:cursor-not-allowed disabled:text-muted-foreground aria-invalid:text-destructive",
        className
      )}
      {...props}
    >
      <RadioRingGlyph className="col-start-1 row-start-1" />
      <RadioGroupPrimitive.Indicator
        data-slot="radio-group-indicator"
        className="col-start-1 row-start-1 grid place-items-center text-card-foreground group-disabled/radio-group-item:text-muted-foreground"
      >
        <RadioDotGlyph />
      </RadioGroupPrimitive.Indicator>
    </RadioGroupPrimitive.Item>
  )
}

export { RadioGroup, RadioGroupItem }
```

## API reference

### RadioGroup

No props of its own. It forwards the props of the element or primitive it wraps.

### RadioGroupItem

No props of its own. It forwards the props of the element or primitive it wraps.

## Sounds

- `radio.select`
