Skip to content
Nana UI

Rating

View .md Download

A rating component for displaying and collecting star (or heart/dot) ratings. Supports fractional display, half- and full-step input, multiple symbols, read-only and disabled states, sizes, hover preview, keyboard control and an optional value label.

Terminal window
npm install @nana-tec/ui-components
import "@nana-tec/ui-components/rating";
<nana-rating value="3"></nana-rating>

precision="half" enables half-stars; show-value shows the number; readonly / disabled make it non-interactive.

The variant attribute sets the symbol — star (default), heart, or circle.

Properties

PropertyAttributeTypeDefaultDescription
ariaLabelaria-labelstring | nullnullAccessible label
clearablebooleanfalseClicking the current value resets it to zero
disabledbooleanfalseDisable interaction and dim the control
maxnumber5Number of symbols
precisionRatingPrecision'full'Selection granularity
readonlybooleanfalseDisplay only — no interaction
showValueshow-valuebooleanfalseShow the numeric value beside the symbols
sizeSize'md'Component size
valuenumber0Current rating value
variantRatingVariant'star'Symbol shape

Events

EventDescription
nana-changeFired when the value is committed (`detail.value`)
nana-inputFired while hovering over a new value (`detail.value`)

CSS parts

PartDescription
::part(base)The root container
::part(symbols)The symbol group
::part(symbol)A single rating symbol
::part(label)The value label

CSS custom properties

PropertyDescription
--nana-rating-colorActive symbol colour
--nana-rating-empty-colorEmpty symbol colour
--nana-rating-sizeSymbol size (overrides `size`)
--nana-rating-gapGap between symbols
EventTypeDescription
nana-changeCustomEventFired when the value is committed (detail.value)
nana-inputCustomEventFired while hovering over a new value (detail.value)
VariableDefaultDescription
--nana-rating-colorActive symbol colour
--nana-rating-empty-colorEmpty symbol colour
--nana-rating-sizeSymbol size (overrides size)
--nana-rating-gapGap between symbols
PartDescription
baseThe root container
symbolsThe symbol group
symbolA single rating symbol
labelThe value label
  • Keyboard accessible
  • Screen-reader labels
  • Focus-visible states
  • ARIA roles and states
  • WCAG 2.2 AA contrast
Explore Rating interactively Every state, prop, and edge case — with live controls — in Storybook.
View in Storybook