Skip to content

ComponentsForms & data

SourceSource

Radio

One choice out of a short, visible list, with the ring and dot the client's settings panels use.

A radio group is for a choice that is short enough to show in full. A select menu hides its options until asked. A radio group shows all of them at once. The client’s settings panels use it when there are two or three options and the difference between them matters.

It is built on Radix Radio Group in React and Reka UI Radio Group in Vue. The primitive owns the value, the keyboard and the form input.

The state is in the ring and the dot, not in motion: the selected row reads as selected in a screenshot, and in greyscale.

"use client"

import * as React from "react"

import { Radio, RadioGroup } from "@/registry/bases/newt/ui/radio"

export default function RadioDemo() {
  const [mode, setMode] = React.useState("voice-activity")

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <RadioGroup label="Input mode" value={mode} onValueChange={setMode}>
        <Radio value="voice-activity">Voice Activity</Radio>
        <Radio value="push-to-talk">Push to Talk</Radio>
      </RadioGroup>

      <RadioGroup label="Who can reply" defaultValue="everyone">
        <Radio
          value="everyone"
          description="Anyone in the channel can reply to this message."
        >
          Everyone
        </Radio>
        <Radio
          value="nobody"
          description="Replies are turned off for this message."
          disabled
        >
          Nobody
        </Radio>
      </RadioGroup>
    </div>
  )
}
<script setup lang="ts">
import { ref } from "vue"
import { Radio, RadioGroup } from "~~/registry/bases/newt/ui/radio"

const mode = ref("voice-activity")
</script>

<template>
  <div class="flex w-full max-w-sm flex-col gap-6">
    <RadioGroup v-model="mode" label="Input mode">
      <Radio value="voice-activity">Voice Activity</Radio>
      <Radio value="push-to-talk">Push to Talk</Radio>
    </RadioGroup>

    <RadioGroup label="Who can reply" default-value="everyone">
      <Radio
        value="everyone"
        description="Anyone in the channel can reply to this message."
      >
        Everyone
      </Radio>
      <Radio
        value="nobody"
        description="Replies are turned off for this message."
        disabled
      >
        Nobody
      </Radio>
    </RadioGroup>
  </div>
</template>

Installation

npx newtui@latest add radionpx shadcn@latest add @newtui/radionpx shadcn-vue@latest add @newtui/radiopnpm dlx newtui@latest add radiopnpm dlx shadcn@latest add @newtui/radiopnpm dlx shadcn-vue@latest add @newtui/radioyarn dlx newtui@latest add radioyarn dlx shadcn@latest add @newtui/radioyarn dlx shadcn-vue@latest add @newtui/radiobunx newtui@latest add radiobunx shadcn@latest add @newtui/radiobunx shadcn-vue@latest add @newtui/radiodeno run -A npm:newtui@latest add radiodeno run -A npm:shadcn@latest add @newtui/radiodeno run -A npm:shadcn-vue@latest add @newtui/radiovlx newtui@latest add radiovlx shadcn@latest add @newtui/radiovlx shadcn-vue@latest add @newtui/radiovp dlx newtui@latest add radiovp dlx shadcn@latest add @newtui/radiovp dlx shadcn-vue@latest add @newtui/radionubx newtui@latest add radionubx shadcn@latest add @newtui/radionubx shadcn-vue@latest add @newtui/radionlx newtui@latest add radionlx shadcn@latest add @newtui/radionlx shadcn-vue@latest add @newtui/radioupx newtui@latest add radioupx shadcn@latest add @newtui/radioupx shadcn-vue@latest add @newtui/radio

The shadcn CLI needs the @newtui registry in your components.json. Set it up.

Install the dependencies

npm install radix-uipnpm add radix-uiyarn add radix-uibun add radix-uideno add npm:radix-uivlt install radix-uivp add radix-uinub add radix-uini radix-uiupm add radix-ui
npm install reka-uipnpm add reka-uiyarn add reka-uibun add reka-uideno add npm:reka-uivlt install reka-uivp add reka-uinub add reka-uini reka-uiupm add reka-ui

Copy the source into your project

"use client"

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

import { cn } from "@/lib/utils"

/*
 * A radio group: one choice out of a short, visible list. Where a select menu
 * hides its options until asked, this shows them all, which is what the
 * client's settings panels use when there are two or three of them and the
 * difference between them matters.
 *
 * Radix owns the behaviour: the value, the single tab stop, the arrow keys
 * and the hidden input a form reads. Only the look is newt/ui's.
 */
const RadioGroup = React.forwardRef<
  React.ComponentRef<typeof RadioGroupPrimitive.Root>,
  React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Root> & {
    /** Accessible name for the group. */
    label?: string
  }
>(({ className, label, ...props }, ref) => (
  <RadioGroupPrimitive.Root
    ref={ref}
    aria-label={label}
    className={cn("flex flex-col gap-1", className)}
    {...props}
  />
))
RadioGroup.displayName = "RadioGroup"

const Radio = React.forwardRef<
  React.ComponentRef<typeof RadioGroupPrimitive.Item>,
  React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Item> & {
    /** A second line, when the choice needs a sentence to explain it. */
    description?: React.ReactNode
  }
>(({ className, description, children, ...props }, ref) => (
  <RadioGroupPrimitive.Item
    ref={ref}
    className={cn(
      "group flex cursor-pointer items-center gap-3 border-0 bg-transparent px-1 py-2 text-start font-[family-name:var(--newt-font-sans)] text-[15px] leading-5 text-newt-text-secondary",
      "hover:text-newt-text-primary focus-visible:rounded-[var(--newt-radius-sm)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-newt-text-link",
      "data-[state=checked]:text-newt-text-primary",
      "disabled:cursor-not-allowed disabled:opacity-50",
      className
    )}
    {...props}
  >
    {/*
     * The indicator stays mounted so it can be the ring as well as the dot:
     * it carries `data-state`, and the dot grows from nothing.
     */}
    <RadioGroupPrimitive.Indicator
      forceMount
      aria-hidden="true"
      className={cn(
        "relative h-5 w-5 shrink-0 rounded-full border-2 border-newt-text-muted transition-colors duration-fast ease-newt",
        "after:absolute after:top-1/2 after:start-1/2 after:h-2 after:w-2 after:rounded-full after:bg-newt-on-accent after:content-['']",
        // Centring, and the dot's grow: both carry the writing direction.
        "after:[transform:translate(calc(var(--newt-dir)*-50%),-50%)_scale(0)]",
        "data-[state=checked]:border-newt-brand data-[state=checked]:bg-newt-brand",
        "data-[state=checked]:after:[transform:translate(calc(var(--newt-dir)*-50%),-50%)_scale(1)]",
        "group-hover:border-newt-text-secondary",
        // A disabled row does not answer the pointer, checked or not.
        "data-[disabled]:data-[state=unchecked]:group-hover:border-newt-text-muted data-[disabled]:data-[state=checked]:group-hover:border-newt-brand"
      )}
    />
    {description === undefined ? (
      children
    ) : (
      <span className="flex min-w-0 flex-col gap-0.5">
        <span>{children}</span>
        <span className="text-[13px] leading-[17px] text-newt-text-muted">
          {description}
        </span>
      </span>
    )}
  </RadioGroupPrimitive.Item>
))
Radio.displayName = "Radio"

export { Radio, RadioGroup }
<script setup lang="ts">
import {
  RadioGroupIndicator,
  RadioGroupItem,
  useForwardPropsEmits,
  type RadioGroupItemEmits,
  type RadioGroupItemProps,
} from "reka-ui"
import { computed, type HTMLAttributes } from "vue"

import { cn } from "@/lib/utils"

const props = defineProps<
  RadioGroupItemProps & {
    class?: HTMLAttributes["class"]
    /** A second line, when the choice needs a sentence to explain it. */
    description?: string
  }
>()
const emits = defineEmits<RadioGroupItemEmits>()

const delegated = computed(() => {
  const { class: _class, description: _description, ...rest } = props
  return rest
})
const forwarded = useForwardPropsEmits(delegated, emits)
</script>

<template>
  <RadioGroupItem
    v-bind="forwarded"
    :class="
      cn(
        'group flex cursor-pointer items-center gap-3 border-0 bg-transparent px-1 py-2 text-start font-[family-name:var(--newt-font-sans)] text-[15px] leading-5 text-newt-text-secondary',
        'hover:text-newt-text-primary focus-visible:rounded-[var(--newt-radius-sm)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-newt-text-link',
        'data-[state=checked]:text-newt-text-primary',
        'disabled:cursor-not-allowed disabled:opacity-50',
        props.class
      )
    "
  >
    <!--
      The indicator stays mounted so it can be the ring as well as the dot:
      it carries `data-state`, and the dot grows from nothing. A disabled row
      does not answer the pointer, checked or not.
    -->
    <RadioGroupIndicator
      force-mount
      aria-hidden="true"
      :class="
        cn(
          'relative h-5 w-5 shrink-0 rounded-full border-2 border-newt-text-muted transition-colors duration-fast ease-newt',
          'after:absolute after:top-1/2 after:start-1/2 after:h-2 after:w-2 after:rounded-full after:bg-newt-on-accent after:content-[\'\']',
          'after:[transform:translate(calc(var(--newt-dir)*-50%),-50%)_scale(0)]',
          'data-[state=checked]:border-newt-brand data-[state=checked]:bg-newt-brand',
          'data-[state=checked]:after:[transform:translate(calc(var(--newt-dir)*-50%),-50%)_scale(1)]',
          'group-hover:border-newt-text-secondary',
          'data-[disabled]:data-[state=unchecked]:group-hover:border-newt-text-muted data-[disabled]:data-[state=checked]:group-hover:border-newt-brand'
        )
      "
    />
    <span v-if="props.description" class="flex min-w-0 flex-col gap-0.5">
      <span><slot /></span>
      <span class="text-[13px] leading-[17px] text-newt-text-muted">
        {{ props.description }}
      </span>
    </span>
    <slot v-else />
  </RadioGroupItem>
</template>
<script setup lang="ts">
import {
  RadioGroupRoot,
  useForwardPropsEmits,
  type RadioGroupRootEmits,
  type RadioGroupRootProps,
} from "reka-ui"
import { computed, type HTMLAttributes } from "vue"

import { cn } from "@/lib/utils"

/*
 * A radio group: one choice out of a short, visible list. Where a select menu
 * hides its options until asked, this shows them all, which is what the
 * client's settings panels use when there are two or three of them and the
 * difference between them matters.
 *
 * Reka owns the behaviour: the value, the single tab stop, the arrow keys
 * and the hidden input a form reads. Only the look is newt/ui's.
 */
const props = defineProps<
  RadioGroupRootProps & {
    class?: HTMLAttributes["class"]
    /** Accessible name for the group. */
    label?: string
  }
>()
const emits = defineEmits<RadioGroupRootEmits>()

const delegated = computed(() => {
  const { class: _class, label: _label, ...rest } = props
  return rest
})
const forwarded = useForwardPropsEmits(delegated, emits)
</script>

<template>
  <RadioGroupRoot
    v-bind="forwarded"
    :aria-label="props.label"
    :class="cn('flex flex-col gap-1', props.class)"
  >
    <slot />
  </RadioGroupRoot>
</template>
export { default as Radio } from "./Radio.vue"
export { default as RadioGroup } from "./RadioGroup.vue"

Update the import paths

The files import @/lib/utils and sibling components through the aliases in your components.json. Point them at wherever those live in your project.

No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Radio to your React project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.

No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Radio to your Vue project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.

Usage

import { Radio } from "@/components/ui/radio"

export function Example() {
  return <Radio />
}
<script setup lang="ts">
import { Radio, RadioGroup } from "@/components/ui/radio"
</script>

<template>
  <Radio />
</template>

The group owns the value; each Radio only names the value it stands for. Leave value off the group and it manages its own selection from defaultValue.

<RadioGroup label="Input mode" value={mode} onValueChange={setMode}>
  <Radio value="voice-activity">Voice Activity</Radio>
  <Radio value="push-to-talk">Push to Talk</Radio>
</RadioGroup>
<RadioGroup v-model="mode" label="Input mode">
  <Radio value="voice-activity">Voice Activity</Radio>
  <Radio value="push-to-talk">Push to Talk</Radio>
</RadioGroup>

Second lines

A choice that needs a sentence to explain it takes a description, which sits under the label in muted text. Use it when the label alone would make somebody guess; leave it off when it would only restate the label.

Examples

Controlled

Bind the group’s value when the choice drives something else on the page, such as the summary under this group.

"use client"

import * as React from "react"

import { Radio, RadioGroup } from "@/registry/bases/newt/ui/radio"

export default function RadioControlledDemo() {
  const [display, setDisplay] = React.useState("cozy")

  return (
    <div className="flex w-full max-w-sm flex-col gap-3">
      <RadioGroup
        label="Message display"
        value={display}
        onValueChange={setDisplay}
      >
        <Radio value="cozy">Cozy</Radio>
        <Radio value="compact">Compact</Radio>
      </RadioGroup>
      <p
        className="rounded-md bg-newt-bg-elevated px-3 py-2 text-sm text-newt-text-secondary"
        aria-live="polite"
      >
        {display === "compact"
          ? "Avatars are hidden and more messages fit on the screen."
          : "Avatars are shown and messages have room to breathe."}
      </p>
    </div>
  )
}
<script setup lang="ts">
import { ref } from "vue"
import { Radio, RadioGroup } from "~~/registry/bases/newt/ui/radio"

const display = ref("cozy")
</script>

<template>
  <div class="flex w-full max-w-sm flex-col gap-3">
    <RadioGroup v-model="display" label="Message display">
      <Radio value="cozy">Cozy</Radio>
      <Radio value="compact">Compact</Radio>
    </RadioGroup>
    <p
      class="rounded-md bg-newt-bg-elevated px-3 py-2 text-sm text-newt-text-secondary"
      aria-live="polite"
    >
      {{
        display === "compact"
          ? "Avatars are hidden and more messages fit on the screen."
          : "Avatars are shown and messages have room to breathe."
      }}
    </p>
  </div>
</template>

Inline

Two or three short labels can sit in a row: pass layout classes to the group. The arrow keys still walk the options in order.

import { Radio, RadioGroup } from "@/registry/bases/newt/ui/radio"

export default function RadioInlineDemo() {
  return (
    <RadioGroup
      className="flex-row flex-wrap gap-x-5"
      label="Theme"
      defaultValue="dark"
    >
      <Radio value="dark">Dark</Radio>
      <Radio value="light">Light</Radio>
      <Radio value="system">Match system</Radio>
    </RadioGroup>
  )
}
<script setup lang="ts">
import { Radio, RadioGroup } from "~~/registry/bases/newt/ui/radio"
</script>

<template>
  <RadioGroup
    class="flex-row flex-wrap gap-x-5"
    label="Theme"
    default-value="dark"
  >
    <Radio value="dark">Dark</Radio>
    <Radio value="light">Light</Radio>
    <Radio value="system">Match system</Radio>
  </RadioGroup>
</template>

Disabled option

A disabled radio stays visible, so the reader learns the choice exists, but the pointer and the arrow keys both pass over it. Use the description to say why it is unavailable.

import { Radio, RadioGroup } from "@/registry/bases/newt/ui/radio"

/* The arrow keys step over the disabled row rather than stopping on it. */
export default function RadioDisabledDemo() {
  return (
    <RadioGroup
      className="w-full max-w-sm"
      label="Stream quality"
      defaultValue="720"
    >
      <Radio value="720" description="Smooth on most connections.">
        720p
      </Radio>
      <Radio
        value="1080"
        description="Needs a boosted server to turn on."
        disabled
      >
        1080p
      </Radio>
      <Radio value="source" description="Whatever your screen sends.">
        Source
      </Radio>
    </RadioGroup>
  )
}
<script setup lang="ts">
import { Radio, RadioGroup } from "~~/registry/bases/newt/ui/radio"

/* The arrow keys step over the disabled row rather than stopping on it. */
</script>

<template>
  <RadioGroup
    class="w-full max-w-sm"
    label="Stream quality"
    default-value="720"
  >
    <Radio value="720" description="Smooth on most connections.">720p</Radio>
    <Radio
      value="1080"
      description="Needs a boosted server to turn on."
      disabled
    >
      1080p
    </Radio>
    <Radio value="source" description="Whatever your screen sends.">
      Source
    </Radio>
  </RadioGroup>
</template>

API reference

RadioGroup

PropType
value / v-model?string

The selected value, when you control it. In React, leave it undefined and pass `defaultValue` to let the group own it.

Typestring
defaultValue?string

The value selected on first render, for an uncontrolled group.

Typestring
onValueChange?(value: string) => void

React only. Called with the value that was chosen; Vue emits `update:modelValue`.

Type(value: string) => void
label?string

Accessible name for the group. A radio group without one is announced as an unlabelled set.

Typestring
name?string

The field name. Inside a `<form>`, the group submits the selected value under this name.

Typestring
required?boolean

The form does not submit until a row is selected.

Typeboolean
Defaultfalse
disabled?boolean

Disables every row.

Typeboolean
Defaultfalse
orientation?"horizontal" | "vertical"

Limits the arrow keys to one axis. Without it, all four arrow keys move the selection.

Type"horizontal" | "vertical"
loop?boolean

The arrow keys wrap from the last row to the first.

Typeboolean
Defaulttrue

Radio

PropType
value?string

Which value this row stands for. Required, and unique within the group.

Typestring
description?ReactNode / string

A second line under the label, for a choice that needs explaining.

TypeReactNode / string
disabled?boolean

Skipped by the arrow keys and not selectable.

Typeboolean
Defaultfalse
children / default slot?React.ReactNode / Vue slot

The label.

TypeReact.ReactNode / Vue slot

Both parts accept the other props of the primitive part they wrap. They also accept a className / class, which is merged with the defaults.

Accessibility

The group has role="radiogroup" and an accessible name. Each row is a button with role="radio" and aria-checked. The label and the description are inside the button, so they are its accessible name.

The group is one tab stop. Tab moves focus to the selected row, or to the first row when nothing is selected. The arrow keys move the selection and wrap at the ends. They skip disabled rows.

Home and End move focus to the first and last enabled row, and Space selects the focused row.

Give the group a label. Without one, a screen reader does not say what the choice is for. A focused row shows a 2px --newt-text-link outline.

Tokens

Radio reads its colours, radii and motion from the --newt-* tokens installed with the library. Override a token and every component that reads it follows, including this one — see the token layer.

  • --newt-text-secondary
  • --newt-font-sans
  • --newt-text-primary
  • --newt-text-link
  • --newt-radius-sm
  • --newt-text-muted
  • --newt-radius-full
  • --newt-duration-fast
  • --newt-ease
  • --newt-on-accent
  • --newt-dir
  • --newt-brand