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
| Prop | Type | Default | Description |
|---|---|---|---|
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
| Key | Does |
|---|---|
| Arrow keys | Change the rating (native radios) |
Accessibility
- Native radios in a
role="radiogroup", each labelled "3 stars" and so on.readOnlyrenders an image labelled "3 out of 5" instead.
Generated from src/components/Rating.tsx. Something wrong or missing? Open an issue.