Skip to Content
DocsEnterpriseBlogShowcase

Rating

Used to show reviews and ratings in a visual format.

Ark UISourceStorybookRecipe

Setup

If you don't already have the snippet, run the following command to add the rating snippet

chakra snippet add rating

The snippet includes a closed component composition for the RatingGroup component.

Usage

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

Examples

Sizes

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

Controlled

Use the value and onValueChange prop to control the rating value.

ReadOnly

Use the readOnly prop to make the rating component read-only.

Hook Form

Here's an example of how to use rating with react-hook-form.

Custom Icon

Use the icon prop to pass a custom icon to the rating component. This will override the default star icon.

Half Star

Use the allowHalf prop to allow half-star ratings.

Emoji

Compose the rating component with emojis.

😡😠😐😊😍

Testimonial

Use the rating component to show testimonials.

Sage is a great software engineer. He is very professional and knowledgeable.

MJ

Matthew Jones

CTO, Company

Props

Root

PropDefaultType
count '5'
number

The total number of ratings.

colorPalette 'gray'
'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'

The color palette of the component

size 'md'
'xs' | 'sm' | 'md' | 'lg'

The size of the component

allowHalf
boolean

Whether to allow half stars.

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.
autoFocus
boolean

Whether to autofocus the rating.

defaultValue
number

The initial value of the rating group when it is first rendered. Use when you do not need to control the state of the rating group.

disabled
boolean

Whether the rating is disabled.

form
string

The associate form of the underlying input element.

id
string

The unique identifier of the machine.

ids
Partial<{ root: string label: string hiddenInput: string control: string item(id: string): string }>

The ids of the elements in the rating. Useful for composition.

name
string

The name attribute of the rating element (used in forms).

onHoverChange
(details: HoverChangeDetails) => void

Function to be called when the rating value is hovered.

onValueChange
(details: ValueChangeDetails) => void

Function to be called when the rating value changes.

readOnly
boolean

Whether the rating is readonly.

required
boolean

Whether the rating is required.

translations
IntlTranslations

Specifies the localized strings that identifies the accessibility elements and their states

value
number

The current rating value.

as
React.ElementType

The underlying element to render.

unstyled
boolean

Whether to remove the component's style.

Item

PropDefaultType
index *
number

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.