Skip to main content

Rate

Star rating: read-only display, interactive scoring, half stars, custom character and count.

Basic usage​

Basic usage
Current value: 3

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​

PropDescriptionTypeOptionsDefault
valueControlled rating valuenumber——
defaultValueUncontrolled default ratingnumber—0
maxMax starsnumber—5
allowHalfAllow half starsboolean—false
readonlyRead-only (outputs star text for screen readers)boolean—false
disabledWhether to disableboolean—false
characterCustom characterstring—★
showScoreShow score textboolean—false
scoreTemplateScore template ({n} placeholder)string—locale rate.stars
sxShorthand layout propsSxProps——

LhRate events​

EventDescriptionCallback signatureVue equivalent
onChangeRating 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'