Skip to content

Rating ​

A star rating that displays a fractional average or collects a whole score with the mouse or keyboard.

Open in demo
Open in demo

Usage ​

Import SaRating and bind a number with v-model. The value starts at 0, which means not rated.

Examples ​

Read-only and fractional ​

Add readonly to display a score. A read-only rating can show fractions: 4.3 fills the fifth star 30%. show-value prints the number beside the stars, with one decimal when the value has one.

Sizes ​

size takes sm (16px stars), md (20px, the default) or lg (28px).

Interactive ​

Without readonly, hovering previews a score and clicking sets it. Clicking the current score again clears it back to 0.

Custom maximum ​

max sets the number of stars. It defaults to 5.

Disabled ​

disabled dims the stars to 50% and ignores clicks and keys.

API ​

Source: src/shared/components/common/SaRating.vue

Props ​

PropTypeDefaultDescription
modelValuenumber0The current rating. Fractional values render partial stars when read-only.
maxnumber5Number of stars.
size'sm' | 'md' | 'lg''md'Star size: 16px, 20px or 28px.
readonlybooleanfalseDisplay only: no hover, no focus, no pointer.
disabledbooleanfalseDims the stars and blocks input.
showValuebooleanfalseShows the numeric value beside the stars.
labelstring—Accessible name for the group. Falls back to the common.rating translation ("Rating" in English).

Emits ​

EventPayloadDescription
update:modelValuevalue: numberFires on click and on keyboard input. 0 when the current score is cleared.

Slots ​

None.

Accessibility ​

  • Interactive (neither readonly nor disabled): the stars group has role="slider", the label as its name, and aria-valuenow, aria-valuemin="0" and aria-valuemax set to max. The group is one tab stop. Each star is a button named "1 of 5", "2 of 5" and so on.
  • Keyboard: ArrowUp and ArrowRight add one, ArrowDown and ArrowLeft remove one, Home sets 0 and End sets max. In a right-to-left layout ArrowRight and ArrowLeft swap, so the arrow keys follow the reading direction.
  • Read-only or disabled: the group has role="img" and a name such as "Rating: 4 out of 5". It takes no focus. A disabled rating also sets aria-disabled="true".
  • The partial fill grows from the start edge using logical properties, so fractions read correctly in right-to-left layouts.