Skip to content
Stylhero 0.8.0
Components

Core

Layout and type

Inputs

Overlays

Navigation

Data display

Charts

Transitions and utilities

Page pieces (landing pages, portfolios, docs)

Icons

Components / Inputs

Rating

Star rating. The interactive version is a radio group, so arrow keys work. ref points at the star that takes focus (the checked one, else the first); it is unset when readOnly.

import { Rating } from "@stylhero/ui";

Example

Code
import { Rating, Stack } from "@stylhero/ui";

function RatingExample() {
  return (
    <Stack gap={3}>
      <Rating label="Rate this build" defaultValue={3} />
      <Rating label="Average" value={4} readOnly size="sm" />
    </Stack>
  );
}

Props

PropTypeDefaultDescription
defaultValue number 0
label string "Rating" Accessible name, e.g. "Rate your visit".
max number 5
name string -
onValueChange (value: number) => void -
readOnly boolean - Display only.
size "sm" | "md" "md"
value number -

Also takes the HTML attributes of its root element (id, style, data-*, aria-*, event handlers…). Takes a ref.

Keyboard

KeyDoes
Arrow keysChange the rating (native radios)

Accessibility

  • Native radios in a role="radiogroup", each labelled "3 stars" and so on. readOnly renders an image labelled "3 out of 5" instead.

Generated from src/components/Rating.tsx. Something wrong or missing? Open an issue.