Rate
Star rating: read-only display, interactive scoring, half stars, custom character and count.
Basic usage
Basic usage
Current value: 3
4.5 stars
The first row is interactive scoring; in the second row allowHalf enables half stars (clicking the left half counts 0.5) and readonly renders a display-only rating that outputs the score text with showScore; the third row shows max for the star count, disabled to block interaction, and character to replace the star with any symbol.
import { useState } from 'react'
import { LhRate } from '@lh-ui/react'
export default function Demo() {
const [value, setValue] = useState(3)
return <LhRate value={value} onChange={setValue} />
}
LhRate Props
| Prop | Description | Type | Options | Default |
|---|---|---|---|---|
| value | Controlled rating value | number | — | — |
| defaultValue | Uncontrolled default rating | number | — | 0 |
| max | Max stars | number | — | 5 |
| allowHalf | Allow half stars | boolean | — | false |
| readonly | Read-only (outputs star text for screen readers) | boolean | — | false |
| disabled | Whether to disable | boolean | — | false |
| character | Custom character | string | — | ★ |
| showScore | Show score text | boolean | — | false |
| scoreTemplate | Score template ({n} placeholder) | string | — | locale rate.stars |
| sx | Shorthand layout props | SxProps | — | — |
LhRate events
| Event | Description | Callback signature | Vue equivalent |
|---|---|---|---|
| onChange | Rating change (triggered by both click and keyboard) | (value: number) => void | @update:modelValue / @change |
Accessibility
The interactive mode is a role="radiogroup" of real focusable buttons (roving tabindex): arrow keys step the rating (0.5 in half-star mode), Home resets to 0, End fills to max. The read-only mode outputs role="img" + aria-label (e.g. "4.5 stars") for screen readers.
Styles
import '@lh-ui/react/style/rate'