Rating

An accessible rating component with half-value support, keyboard navigation, and form integration.

Installation

CLI

Loading...

Dependencies

This component requires the following npm packages:

Loading...

Registry Dependencies

This component also requires: https://ui.shadcn.com/r/styles/base-vega/utils.json

Usage

Rating is an accessible star rating component that allows users to provide ratings with support for half values, keyboard navigation, and form integration.

It supports both controlled and uncontrolled modes, RTL layouts, multiple size variants, and custom icons. The component is fully accessible with proper ARIA attributes and keyboard navigation.

Basic Rating
Half Steps (LTR)
Half Steps (RTL)

Examples

Controlled State

Use value andonValueChange to control the rating value programmatically.

Current rating: 3

Half Steps

Set step={0.5} to enable half-star ratings. Click on the left or right half of a star to select half values.

Themes & Custom Icons

Customize the rating with different colors and icons by passing custom children to RatingItem.

Default
Gold
Heart
Energy

Sizes

Use the size prop to change the size of rating items.

Small
Default
Large

API Reference

Rating Props

PropTypeDefaultDescription
valuenumber-Controlled rating value.
defaultValuenumber0Default rating value (uncontrolled).
onValueChange(value: number) => void-Callback fired when the rating value changes.
onHover(value: number | null) => void-Callback fired when hovering over a rating item.
maxnumber5Maximum rating value.
step0.5 | 11Step increment for ratings. Use 0.5 for half-star ratings.
activationMode"automatic" | "manual""automatic"How items are activated. "automatic" selects on focus, "manual" requires Enter/Space.
dir"ltr" | "rtl"-Text direction for RTL support.
orientation"horizontal" | "vertical""horizontal"Layout orientation of rating items.
size"sm" | "default" | "lg""default"Size variant for rating items.
clearablebooleanfalseAllow clearing the rating by clicking the current value.
disabledbooleanfalseDisable all rating items.
readOnlybooleanfalseMake the rating read-only.
requiredbooleanfalseMark the rating as required for form validation.
namestring-Name attribute for form submission.
asChildbooleanfalseRender as child element using Radix Slot.

RatingItem Props

PropTypeDefaultDescription
indexnumber-Item index (0-based). Auto-assigned if not provided.
childrenReactNode | ((dataState: DataState) => ReactNode)-Custom content. Receives dataState for conditional rendering. Defaults to Star icon.
asChildbooleanfalseRender as child element using Radix Slot.

Accessibility

The Rating component follows WAI-ARIA guidelines for radio groups and includes full keyboard navigation support.

Keyboard Interactions

KeyDescription
ArrowLeft / ArrowRightNavigate between rating items
HomeMove to first rating item
EndMove to last rating item
Enter / SpaceActivate focused item (manual mode)

Source Code

Loading...