Forms

Rating.

A keyboard-friendly rating with whole or half steps.

LIVE PREVIEWTry it. It works.

Install the source

Terminal
npx shadcn@latest add https://ui.bld8.dev/r/rating.json

Registry setup · Examples · API and behavior · Open the playground

COMPLETE EXAMPLES

Use it in context.

Each example includes its imports, data and state. The preview runs that same source. Include the stylesheet once in your application.

Fractional ratings with native radio values

Choose half-star scores with the pointer or keyboard, preserve read-only values and reset through an external native form.

Keyboard

  • Arrow keys change by half a star; Home and End reach the bounds.
  • RTL reverses horizontal arrow direction. Clear rating restores an unrated value.

States covered

  • half stars
  • RTL
  • native form ownership
  • required
  • prevented reset
  • read only and disabled

Install this complete example and its component dependencies.

Terminal
npx shadcn@latest add https://ui.bld8.dev/r/example-rating-fractional-form.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 {useId,useState} from 'react';
import {Button,Checkbox,Rating,UIProvider} from '@bld8/ui';
export default function RatingForm(){const id=useId(),[rtl,setRtl]=useState(false),[prevent,setPrevent]=useState(false),[result,setResult]=useState('No rating submitted.');return <UIProvider direction={rtl?'rtl':'ltr'}><div style={{display:'grid',gap:24}}><Button variant="secondary" onClick={()=>setRtl(value=>!value)}>{rtl?'Use LTR rating':'Use RTL rating'}</Button>
<Rating label="Review score" name="score" form={id} defaultValue={3.5} step={.5} required hint="Use arrow keys for half-star steps."/>
<Rating label="Published score" name="published" form={id} value={4.5} step={.5} readOnly/>
<Rating label="Disabled score" name="disabled" form={id} defaultValue={2} disabled/>
<Rating label="Ten point summary" max={10} step={.5} value={8.5} readOnly/>
<Checkbox label="Prevent rating reset" checked={prevent} onCheckedChange={setPrevent}/>
<form id={id} aria-label="Review form" onReset={event=>{if(prevent)event.preventDefault();}} onSubmit={event=>{event.preventDefault();const data=new FormData(event.currentTarget);setResult('Score: '+data.get('score')+' | Published: '+data.get('published')+' | Disabled: '+data.has('disabled'));}}><div style={{display:'flex',gap:12,flexWrap:'wrap'}}><Button type="submit">Read ratings</Button><Button type="reset" variant="secondary">Reset ratings</Button></div></form><p role="status">{result}</p></div></UIProvider>;}

Quick reference

React / TypeScript
<Rating label="Your rating" name="rating" step={0.5} />

In the workspace or ZIP starter, import components from @bld8/ui and include @bld8/ui/styles.css once. Registry installations use your local bld8/ source path. Wrap overlays in UIProvider.

API & behaviour

Fractional native choices, clear, required state and reset preserve canonical numeric values. Read-only values remain submitted; disabled fields do not. Direction follows the local UI provider.

Rating

Rating public properties
PropTypeDefault
labelRequiredstring—
classNamestring | undefined—
clearableboolean | undefinedtrue
defaultValuenumber | null | undefinednull
disabledboolean | undefinedfalse
errorstring | undefined—
formstring | undefined—
hintstring | undefined—
inputRefRef<HTMLInputElement> | undefined—
maxnumber | undefined5
namestring | undefined—
onBlurFocusEventHandler<HTMLInputElement> | undefined—
onValueChange((value: number | null) => void) | undefined—
readOnlyboolean | undefinedfalse
requiredboolean | undefinedfalse
step1 | 0.5 | undefined1
valuenumber | null | undefined—

RatingProps

RatingProps public properties
PropTypeDefault
labelRequiredstring—
classNamestring | undefined—
clearableboolean | undefined—
defaultValuenumber | null | undefined—
disabledboolean | undefined—
errorstring | undefined—
formstring | undefined—
hintstring | undefined—
inputRefRef<HTMLInputElement> | undefined—
maxnumber | undefined—
namestring | undefined—
onBlurFocusEventHandler<HTMLInputElement> | undefined—
onValueChange((value: number | null) => void) | undefined—
readOnlyboolean | undefined—
requiredboolean | undefined—
step1 | 0.5 | undefined—
valuenumber | null | undefined—

Tables come from the public TypeScript declarations. Related types and function parameters are shown alongside their component. A dash means no default is declared at the public function boundary.

Related controls

Notes to self

Test this component with real content, keyboard input and both themes. The example is a starting point; labels, error handling and behaviour still need to fit the application.