Radio group example

Required choice and form data.

An uncontrolled native group with a focused error and a disabled option.

Complete React client module · MIT · Next.js and Vite

Interactive example

Required choice and form data

An uncontrolled native group with a focused error and a disabled option.

Keyboard

  • Tab reaches the first available radio.
  • Arrow keys change the selection and skip disabled options.

States covered

  • Empty required group
  • Invalid
  • Disabled option
  • Submitted

Install this complete example and its component dependencies.

Terminal
npx shadcn@latest add https://ui.bld8.dev/r/example-radio-validation.json
Complete source
React / TypeScript
/*!
MIT License

Copyright (c) 2026 Jaison

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
'use client';
import '@bld8/ui/styles.css';
import {useRef,useState} from 'react';
import {Button,RadioGroup} from '@bld8/ui';
export default function ExportExample(){
  const first=useRef<HTMLInputElement>(null);
  const [error,setError]=useState(''),[status,setStatus]=useState('');
  return <form noValidate onSubmit={event=>{
    event.preventDefault();const selected=new FormData(event.currentTarget).get('exportFormat');
    if(!selected){setError('Choose an export format.');first.current?.focus();return;}
    setStatus('Export format: '+selected);
  }}>
    <RadioGroup label="Export format" name="exportFormat" required inputRef={first} error={error}
      hint="The choice is submitted using its stable value." onValueChange={()=>{setError('');setStatus('');}}
      options={[{value:'json',label:'Structured JSON'},{value:'csv',label:'Spreadsheet CSV'},{value:'xml',label:'Legacy XML',disabled:true}]}/>
    <Button type="submit">Read export preference</Button><p role="status">{status}</p>
  </form>;
}