Introducing PrimeReact v11-alpha 🎉Discover Now
styledForm

Rating

Rating component is a star based selection input.

A
Amy ElsnerSupport · 2m
Glad I could help! How would you rate this conversation?
preview

Usage#

import { Rating } from '@primereact/ui/rating';
<Rating.Root>
    <Rating.Option />
</Rating.Root>

Examples#

Basic#

Captures user feedback as a star rating on a numeric scale.

basic-demo

Half Stars#

Use allowHalf property to allow half stars.

allow-half-demo

Controlled#

Use onValueChange to listen to value changes.

controlled-demo

Number of Stars#

Number of stars to display is defined with stars property.

stars-demo

Vertical#

Use orientation="vertical" to display the rating vertically.

vertical-demo

Template#

Custom icons are used to override the default icons with onIcon and offIcon properties.

AAAAAAAAAA
template-demo

Emoji#

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

😡😕😐🙂😍
emoji-demo

ReadOnly#

When readOnly is present, value cannot be edited.

readonly-demo

Disabled#

When disabled is present, value cannot be edited.

disabled-demo

Accessibility#

Screen Reader#

Rating component internally uses radio buttons that are only visible to screen readers. The value to read for item is retrieved from the locale API via star and stars of the aria property.

Keyboard Support#

Keyboard interaction is derived from the native browser handling of radio buttons in a group.

KeyFunction
tabMoves focus to the star representing the value, if there is none then first star receives the focus.
left arrow up arrowMoves focus to the previous star, if there is none then last radio button receives the focus.
right arrow down arrowMoves focus to the next star, if there is none then first star receives the focus.
spaceIf the focused star does not represent the value, changes the value to the star value.