Introducing PrimeReact v11-alpha 🎉Discover Now

Rating

Rating component is a star based selection input.

Installation#

npx shadcn@latest add @primereact/rating

Usage#

import { Rating, RatingOff, RatingOn, RatingOption } from '@/components/ui/rating';
<Rating defaultValue={3} />

The Rating component renders default star icons automatically. For custom content, compose with sub-components:

<Rating defaultValue={3}>
    <RatingOption index={0}>
        <RatingOn>filled icon</RatingOn>
        <RatingOff>empty icon</RatingOff>
    </RatingOption>
</Rating>

Examples#

Basic#

Choose a rating value by clicking on the stars.

basic-demo

Without Half#

Set allowHalf to false to disable half-star selection.

allow-half-demo

Controlled#

Use value and onValueChange for programmatic control.

controlled-demo

Number of Stars#

Rating supports any number of stars.

stars-demo

Vertical#

Set orientation to "vertical" for a vertical layout.

vertical-demo

Template#

Custom content can be placed inside RatingOn and RatingOff instead of the default star icons.

AAAAAAAAAA
template-demo

Emoji#

Use emojis with data-checked attribute to highlight only the selected option while keeping others in grayscale.

😡😡😕😕😐😐🙂🙂😍😍
emoji-demo

ReadOnly#

Use readOnly to display a rating without allowing changes.

readonly-demo

Disabled#

Use disabled to prevent interaction.

disabled-demo

API#

Sub-Components#

See Primitive API for RatingRoot, RatingOption, RatingOn, and RatingOff component documentation.

Hooks#

See Headless API for useRating and useRatingOption hook documentation.

Accessibility#

See Rating Primitive for WAI-ARIA compliance details and keyboard support.