Skip to content
Logic2BUI

Search docs

Search components and documentation

New
Menu

Rating

A star rating input following the radio-group pattern — arrow keys move the value, hovering previews it, and a read-only mode renders static scores.

3 out of 5

Installation

npx logic2b@next add rating

Usage

import { Rating } from "@/components/ui/rating"

const [value, setValue] = React.useState(0)

<Rating value={value} onValueChange={setValue} aria-label="Rate this" />

Clicking the current value again clears the rating to 0.

Examples

Read-only

For displaying scores: the group becomes role="img" labelled “label: n out of max”, and any icon works.

4.0 · 128 reviews

Accessibility

  • Follows the radio-group pattern: each step is a role="radio" button with aria-checked and an n out of max label.
  • Arrow keys move the value (selection follows focus); Home / End jump to 1 / max.
  • Read-only ratings are announced as a single image with the score in the label, not as a disabled control.

Live playground

Edit the component props and inspect the exact JSX before copying it. The preview loads only when this section enters the viewport.

Generated JSX
<Rating
  defaultValue={3}
  max={5}
  aria-label="Product rating"
 />

API reference

Generated from the public TypeScript exports in src/ui/rating.tsx.

View JSON

Rating

Component

Rating — a star (or custom icon) rating following the radio-group pattern: each star is a radio, arrows move the value, hover previews it. `readOnly` renders a static, labelled image instead.

Props: Omit<React.ComponentProps<"div">, "defaultValue" | "onChange"> & { value?: number defaultValue?: number onValueChange?: (value: number) => void max?: number readOnly?: boolean disabled?: boolean icon?: React.ReactNode }
PropTypeRequiredDefaultDescription
valuenumberNo——
defaultValuenumberNo——
onValueChange(value: number) => voidNo——
maxnumberNo5—
readOnlybooleanNofalse—
disabledbooleanNofalse—
iconReact.ReactNodeNo——
aria-labelstringNo"Rating"—

Accessibility contract

Machine-readable behavior and consumer responsibilities for rating.

View JSON
Support
Authored behavior
Pattern
radio group
Keyboard interactions for rating
KeysBehavior
ArrowUp ArrowDown ArrowLeft ArrowRightMove within the composite control.
Home EndMove to the minimum or maximum rating.
SpaceSelect the focused rating.

Built-in semantics

  • Interactive stars expose radiogroup/radio and aria-checked; read-only mode is a labelled image.

Consumer responsibilities

  • Provide a contextual label and visible text for the meaning of the scale.