SenUI Logo

One choice from many, no second thoughts.

SenRadio is a thin, accessible wrapper over a native radio input. It keeps keyboard semantics, focus rings, and form integration for free, and adds nothing else.

Pick a tea

Selected: matcha

Stepping stones — only one foot down at a time.

React Hook Form

Use a Controller and call field.onChange with the new value. Same shape as a native radio group, none of the wiring.

Choose a plan
Current: free

Disabled

Show a locked option without removing it from the group.

No label

Skip the label prop when a custom layout supplies its own.

Accessibility

Wrap groups in fieldset with a legend. Native arrow-key navigation comes for free.

Tip

More than five options? A select probably reads faster.

One choice in a group

Use radios when the user must pick exactly one. For independent toggles reach for SenCheckbox.

Same name, different values

Group radios with a shared name attribute. The browser handles exclusivity natively.

Form-friendly ref

forwardRef makes integration with React Hook Form, Formik, or vanilla refs frictionless.

Quick usage

A controlled radio group — the most common shape for forms.

'use client'

import { useState } from 'react'
import SenRadio from 'sen-ui/SenRadio'

export function PlanPicker() {
  const [plan, setPlan] = useState('free')

  return (
    <fieldset className="space-y-2">
      <legend>Pick a plan</legend>
      {['free', 'pro', 'team'].map((p) => (
        <SenRadio
          key={p}
          id={`plan-${p}`}
          name="plan"
          value={p}
          label={p}
          checked={plan === p}
          onChange={() => setPlan(p)}
        />
      ))}
    </fieldset>
  )
}

Full standalone implementation

'use client'

import React, { forwardRef } from 'react'
import type { ChangeEventHandler, InputHTMLAttributes } from 'react'

export interface SenRadioProps
  extends Omit<InputHTMLAttributes<HTMLInputElement>, 'size' | 'onChange'> {
  id: string
  name: string
  value: string
  label?: string
  checked?: boolean
  disabled?: boolean
  onChange?: ChangeEventHandler<HTMLInputElement>
  className?: string
}

const SenRadio = forwardRef<HTMLInputElement, SenRadioProps>(
  (
    { id, name, value, label, checked = false, disabled = false, onChange, className, ...props },
    ref
  ) => {
    return (
      <div
        className={[
          'flex items-center',
          disabled && 'opacity-50',
          className,
        ]
          .filter(Boolean)
          .join(' ')}
      >
        <input
          ref={ref}
          type="radio"
          id={id}
          name={name}
          value={value}
          checked={checked}
          disabled={disabled}
          onChange={onChange}
          className="h-4 w-4 border-gray-300 transition-colors duration-150 focus:ring-2 focus:ring-blue-500 focus:ring-offset-2"
          {...props}
        />
        {label && (
          <label htmlFor={id} className="ml-2 cursor-pointer select-none">
            {label}
          </label>
        )}
      </div>
    )
  }
)

SenRadio.displayName = 'SenRadio'

export default SenRadio