Theme studio

Design a theme, preview it live, then export it. Saved in this browser.

Quick picks #10b981
Generated scale
50100200300400500600700800900
Some text is below AA

RatingInput

  • Stable
  • WCAG 2.2 evidence
  • RTL

Collects a 1 to 5 star rating. Use Rating to display one. Built on React Aria RadioGroup: one radio per star, named "1 star" to "5 stars". Tab enters the group on the chosen star, arrow keys move and select (mirrored in right-to-left locales), the choice is submitted with name (WCAG 2.1.1, 4.1.2). The stars are 32 px targets (2.5.8). Chosen stars are filled and empty stars keep an outline; the radio names, the checked state and the descriptor say the value in text (WCAG 1.1.1, 1.4.1, 1.4.11). Hovering previews a rating; the keyboard focus ring surrounds the row of stars as in Figma (2.4.7). Consumer duties: question wording (label), descriptor wording, translated starLabel.

import { RatingInput } from "@nexera-ui/react";
Loading example…
4
examples
21
props
6
live controls
1
platform
9
WCAG criteria
1
block uses it

Try every prop. Copy the code.

Change the props and the code updates. Check light and dark, LTR and RTL, and phone width.

Loading…
errorMessage
label
isDisabled
isReadOnly
isRequired
isInvalid
Generated code
import { RatingInput } from "@nexera-ui/react";

<RatingInput />

Examples 3

The same examples as Storybook, rendered live. Open Code to copy one.

Disabled

Figma Disabled: the stars and the descriptor are dimmed to 45 %.

Loading example…

Long label

Long questions and descriptors wrap; the stars wrap in very narrow containers.

Loading example…

Right to left

Right-to-left: the first star is on the right and arrow keys follow the reading direction. Translate the names.

Loading example…

Props 21

Press "Try it" on a card to load that prop into the playground.

21 props shown

valueNexera
number

The rating, 0 (not rated) to 5. Controlled; pair it with onChange.

Default –
defaultValueNexera
number

The initial rating when uncontrolled.

Default 0
onChangeNexera
(value: number) => void

Called with the new rating (1 to 5) when the user picks a star.

Default –
descriptorNexera
ReactNode | ((value: number) => ReactNode)

Text under the stars, for example "Not rated", "Good". Pass a function to describe the current rating; it receives 0 while nothing is chosen. Shown when provided and linked to the group with aria-describedby. Translate it.

Default –
errorMessageNexera
ReactNode

Error text under the stars, shown while the group is invalid (for example isRequired on submit).

Default –
starLabelNexera
(stars: number) => string

Accessible name of each star option. Translate it, with your locale's plural rules.

Default (stars: number): string => stars === 1 ? "1 star" : `${String(stars)} stars`
classNameNexera
string

Extra classes for the root, merged last so they win over the defaults.

Default –
styleNexera
CSSProperties

Inline style for the root.

Default –
labelNexera
ReactNode

Visible question above the stars, for example "Rate your onboarding". Wraps; names the radio group.

Default –
aria-labelNexera
string

Accessible name of the group when the question is not shown. Translate it.

Default –
aria-labelledbyNexera
string

Id(s) of the visible element(s) that name the group.

Default –
validationBehaviorReact Aria
"native" | "aria"

Whether to use native HTML form validation to prevent form submission when the value is missing or invalid, or mark the field as required or invalid via ARIA.

Default 'native'
nameReact Aria
string

The name of the input element, used when submitting an HTML form. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefname).

Default –
isDisabledReact Aria
boolean

Whether the input is disabled.

Default –
isReadOnlyReact Aria
boolean

Whether the input can be selected but not changed by the user.

Default –
isRequiredReact Aria
boolean

Whether user input is required on the input before form submission.

Default –
isInvalidReact Aria
boolean

Whether the input value is invalid.

Default –
validateReact Aria
(value: string) => true | ValidationError | null

A function that returns an error message if a given value is invalid. Validation errors are displayed to the user when the form is submitted if validationBehavior="native". For realtime validation, use the isInvalid prop instead.

Default –
formReact Aria
string

The <form> element to associate the input with. The value of this attribute must be the id of a <form> in the same document. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input#form).

Default –
idReact Aria
string

The element's unique identifier. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id).

Default –
aria-describedbyReact Aria
string

Identifies the element (or elements) that describes the object.

Default –

* Required. React Aria props shown are the ones most apps use; the component accepts the rest of its React Aria props too.

Accessible by default.

Built on React Aria, and covered by the WCAG 2.2 evidence generated on every build.

WCAG 2.2 evidence

6 direct · 3 supporting
  • 1.1.1Non-text ContentLevel A · tested directly
  • 1.3.1Info and RelationshipsLevel A · tested directly
  • 1.4.1Use of ColorLevel A · tested directly
  • 1.4.11Non-text ContrastLevel AA · supporting test
  • 2.1.1KeyboardLevel A · tested directly
  • 2.4.7Focus VisibleLevel AA · supporting test
  • 2.5.8Target Size (Minimum)Level AA · supporting test
  • 3.3.1Error IdentificationLevel A · tested directly
  • 4.1.2Name, Role, ValueLevel A · tested directly

Fits any width.

Nexera components respond to the space they are given. Drag the corner of the frame, or pick a width.

0 px · drag the corner

Styling hooks

Pass className to add Tailwind classes (merged last). State is exposed as data attributes, so you can style it with variants like data-pressed:.

  • data-disabled
  • data-focus-visible
  • data-preview
  • data-readonly
Usage
<RatingInput className="data-disabled:opacity-90 shadow-sm" />

Used in blocks

Related components