Forms
Rating
A star rating. Editable ratings are a native radio group that forms submit; read-only ratings show averages, including part-filled stars.
import { Rating } from '@reactloom/ui';Examples
Rate a stay
Give each star a meaningful name with optionLabel.
import { Rating } from '@reactloom/ui';
import { useState } from 'react';
const words = ['', 'Poor', 'Fair', 'Good', 'Very good', 'Excellent'];
export default function Example() {
const [value, setValue] = useState<number | null>(null);
return (
<Rating
label="Rate your stay"
description={value ? words[value] : 'Choose 1 to 5 stars.'}
value={value}
onValueChange={setValue}
optionLabel={(n) => `${n} star${n === 1 ? '' : 's'}, ${words[n]}`}
name="stay-rating"
/>
);
}Average rating
readOnly renders an image with a text name.
4.3 (1,284 reviews)
import { HStack, Rating, Text } from '@reactloom/ui';
export default function Example() {
return (
<HStack gap="2" align="center">
<Rating readOnly value={4.3} size="sm" valueLabel={(v, max) => `Average rating ${v} out of ${max}`} />
<Text size="sm" tone="muted">
4.3 (1,284 reviews)
</Text>
</HStack>
);
}API reference
| Prop | Type | Default |
|---|---|---|
value / defaultValue | number | null | — |
onValueChange | (value) => void | — |
maxNumber of stars. | number | 5 |
readOnlyDisplay only; fractional values allowed. | boolean | false |
nameSubmitted with forms. | string | — |
optionLabelName of each star. | (n, max) => string | `n out of max` |
valueLabelRead-only name. | (value, max) => string | `Rated value out of max` |
iconCustom symmetric symbol. | ReactNode | — |
labelVisible label. | ReactNode | — |
description · errorHelp text and error, linked with aria-describedby. | ReactNode | — |
hideLabel · required · disabled · sizeAs on Input. | | — |
Customization
Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.
State attributes
Target these in your CSS to style states without depending on class names.
| Attribute | Values |
|---|---|
[data-disabled] | present when on |
[data-size] | sm · md · lg |
Theme tokens it reads
--pl-color-fg-muted --pl-color-warning-solid --pl-focus-ring-color --pl-focus-ring-width
Accessibility
- Each star is a native radio: arrows move and select (wrapping, mirrored right to left) in every browser.
- Read-only ratings are role="img" with the value in text.
- Stars use a 3:1 contrast outline in every theme and Highlight in forced colours.
| Key | Action |
|---|---|
| Tab | Move to the selected star (or the first) |
| ← → ↑ ↓ | Choose the previous or next value |
Usage guidelines
Do
- Show the number of reviews next to an average.
- Name the stars when the scale has words (Poor … Excellent).
Don’t
- Don’t use stars for settings or yes/no choices.