Skip to content
Stylhero 0.8.0
Components

Core

Layout and type

Inputs

Overlays

Navigation

Data display

Charts

Transitions and utilities

Page pieces (landing pages, portfolios, docs)

Icons

Components / Core

RadioGroup

A set of radios: pick exactly one. Arrow keys move between them (native). ref points at the radio that takes focus (the checked one, else the first enabled one), so form libraries can focus the group, e.g. react-hook-form's field.ref.

import { RadioGroup } from "@stylhero/ui";

Example

Code
import { useState } from "react";
import { RadioGroup } from "@stylhero/ui";

function RadioGroupExample() {
  const [size, setSize] = useState("m");
  return (
    <RadioGroup legend="Size" row value={size} onValueChange={setSize}
      options={[{ value: "s", label: "Small" }, { value: "m", label: "Medium" }, { value: "l", label: "Large" }, { value: "xl", label: "XL", disabled: true }]} />
  );
}

Props

PropTypeDefaultDescription
legend required ReactNode - The group's question, e.g. "Notify me by".
options required Array<ChoiceOption | string> -
defaultValue string -
error ReactNode -
hint ReactNode -
name string -
onValueChange (value: string) => void -
row boolean - Lay the options out side by side.
value string -

Also takes every <fieldset> attribute (id, style, data-*, aria-*, event handlers…), passed to that element. Takes a ref.

Types

type ChoiceOption = { value: string; label: ReactNode; hint?: ReactNode; disabled?: boolean };

Keyboard

KeyDoes
TabMoves into the group, to the checked option
Arrow keysMove to and select the next option

Accessibility

  • Native radios in a <fieldset>. ref points at the checked option, else the first enabled one.

Generated from src/components/FieldSet.tsx. Something wrong or missing? Open an issue.