DocsBlog

Get Started

Components

Data Grid

Signals

Styling

Theming

↑↓Navigate
↵Select
EscClose
  • 1.8.0

  • Day

    Night

    Preview

    Switch mode
  • cerberus

    acheron

    elysium

    oceanus

Get Started
Components
Data Grid
Signals
Styling
Theming

Concepts

OverviewCompositionCerberus ContextTesting

Layout

Aspect RatioBleedBoxCenterContainerContainer QueryDividerFlexFloatGridGroupLink OverlayScrollableStackWrap

Components

AccordionAdmonitionAvatarButtonCarouselCheckboxClipboardCollapsibleComboboxConfirm ModalCTA ModalDate PickerDialogFieldFieldsetFile UploaderIconButtonInputLoading StatesMarqueeMenuNotificationsNumber InputPaginationPin InputPopoverProgress IndicatorsPrompt ModalRadioRatingSelectSliderSplit ButtonSwitchTableTabsTagTextTextareaToggleTooltip

Utilities

Client OnlyDownload TriggerEnvironmentFeature FlagsFocus TrapForFormat ByteFormat NumberFormat Relative TimeFormat Relative TimeFrameHighlightJSON Tree ViewLocalePortalPresenceShowSwapsplitPropsTheme

Rating

The Rating component provides a way to select a value from a range of values, typically used for feedback on a scale.

  • npm
  • source
  • recipe
  • Ark
View as Markdown
Open this page in Markdown
Anthropic
Open in Claude
Ask questions about this page
OpenAI
Open in ChatGPT
Ask questions about this page

Import

import { Rating, RatingParts } from '@cerberus/react'

Usage

The Rating component is an abstracted client component that provides a way to select a value from a range of values. It is used to provide feedback on a scale. The default count is 5, and the default value is 0.

Loading example...

Readonly State

To render the Rating component in a read-only state, you can use the readOnly prop.

Loading example...

Orientation

The Rating component supports two layout orientations for label usage: horizontal, and vertical. The default orientation is vertical.

Loading example...

Sizes

The Rating component supports two sizes: sm, and md. The default size is sm.

Loading example...

Customizing

To customize the Rating component use style props or the Primitive components.

Loading example...

Primitives

You can utilize the primitive components or the css prop to customize the radio.

ComponentDescription
RatingRootThe context provider for the Rating parts
RatingLabelThe label of the rating
RatingControlThe visual control of the rating
RatingContextThe context provider for the rating
RatingItemThe container of the rating item
RatingItemContextThe context provider for a rating item
RatingHiddenInputThe native input for the rating

API

Root

Props

PropTypeRequiredDefaultDescription
allowHalfbooleanfalseundefinedWhether to allow half stars.
asChildbooleanfalseundefinedUse the provided child element as the default rendered element, combining their props and behavior.
autoFocusbooleanfalseundefinedWhether to autofocus the rating.
countnumberfalse5The total number of ratings.
defaultValuenumberfalseundefinedThe initial value of the rating when rendered.
Use when you don't need to control the value of the rating.
disabledbooleanfalseundefinedWhether the rating is disabled.
formstringfalseundefinedThe associate form of the underlying input element.
idstringfalseundefinedThe unique identifier of the machine.
idsPartial<{ root: string, label: string, hiddenInput: string, control: string, item: (id: string) => string }>falseundefinedThe ids of the elements in the rating. Useful for composition.
namestringfalseundefinedThe name attribute of the rating element (used in forms).
onHoverChange(details: HoverChangeDetails) => voidfalseundefinedFunction to be called when the rating value is hovered.
onValueChange(details: ValueChangeDetails) => voidfalseundefinedFunction to be called when the rating value changes.
readOnlybooleanfalseundefinedWhether the rating is readonly.
requiredbooleanfalseundefinedWhether the rating is required.
translationsIntlTranslationsfalseundefinedSpecifies the localized strings that identifies the accessibility elements and their states
valuenumberfalseundefinedThe controlled value of the rating

Control

Props

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

Data Attributes

AttributeDescription / Value
data-scoperating-group
data-partcontrol
data-readonlyPresent when read-only
data-disabledPresent when disabled

HiddenInput

Props

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

Item

Props

PropTypeRequiredDefaultDescription
indexnumbertrueundefinedundefined
asChildbooleanfalseundefinedUse the provided child element as the default rendered element, combining their props and behavior.

Data Attributes

AttributeDescription / Value
data-scoperating-group
data-partitem
data-disabledPresent when disabled
data-readonlyPresent when read-only
data-checkedPresent when checked
data-highlightedPresent when highlighted
data-half

Label

Props

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

Data Attributes

AttributeDescription / Value
data-scoperating-group
data-partlabel
data-disabledPresent when disabled
data-requiredPresent when required

RootProvider

Props

PropTypeRequiredDefaultDescription
valueUseRatingGroupReturntrueundefinedundefined
asChildbooleanfalseundefinedUse the provided child element as the default rendered element, combining their props and behavior.

Context

API:

PropertyTypeDescription
setValue(value: number) => voidSets the value of the rating group
clearValueVoidFunctionClears the value of the rating group
hoveringbooleanWhether the rating group is being hovered
valuenumberThe current value of the rating group
hoveredValuenumberThe value of the currently hovered rating
countnumberThe total number of ratings
itemsnumber[]The array of rating values. Returns an array of numbers from 1 to the max value.
getItemState(props: ItemProps) => ItemStateReturns the state of a rating item

Accessibility

Keyboard Support

KeyDescription
ArrowRightMoves focus to the next star, increasing the rating value based on the allowHalf property.
ArrowLeftMoves focus to the previous star, decreasing the rating value based on the allowHalf property.
EnterSelects the focused star in the rating group.

On this page

  • Import
  • Usage
  • Readonly State
  • Orientation
  • Sizes
  • Customizing
  • Primitives
  • API
    • Root
      • Props
    • Control
      • Props
      • Data Attributes
    • HiddenInput
      • Props
    • Item
      • Props
      • Data Attributes
    • Label
      • Props
      • Data Attributes
    • RootProvider
      • Props
    • Context
  • Accessibility
    • Keyboard Support
Edit this page on Github