Components/Rating

Rating

An input that sets a value by choosing stars.

VerifiedSince 0.3.4

Usage

Half Stars

With precision="0.5", clicking the selected full star again turns it into a half star.

Loading demo...

Custom Icons

icon sets every state; filledIcon / emptyIcon / halfIcon override one each. Built-in icons, Iconify classes, and emoji all work.

Loading demo...

Click Animation

A bounce, glow, and ripple play by default; :animated="false" turns them off.

Loading demo...

Custom Styles

Colors, size, and gap each have a prop; the #text slot rewrites the score text.

Loading demo...

Best Practices

  • Use precision="0.5" only when half steps mean something; use full stars for coarse satisfaction.
  • Use disabled when input is unavailable and readonly to display a past score.
  • Turn on showText or provide a #text slot when the exact value matters.
  • If an icon set's states don't contrast clearly, use one shared icon and tell states apart by color.
  • Turn off animated in dense forms and tables.

API Reference

Props

PropertyTypeDefaultDescription
modelValueThe current score, bound with `v-model`.
maxStarsNumber of stars.
precisionStep size; `0.5` enables half stars, other values only set the score text's decimal places.
showTextShows the score text after the stars.
disabledBlocks rating and marks the root `aria-disabled`.
readonlyDisplays the score only and marks the root `aria-readonly`.
icon-Icon shared by the filled and empty layers; state icons take precedence.
filledIconFilled icon; falls back to `icon`, then `star`.
emptyIconEmpty icon; falls back to `icon`, then `star`.
halfIcon-Half-star icon; when omitted, the filled layer is clipped from the left.
filledColorColor of filled icons.
emptyColorColor of empty icons.
hoverColorColor of the filled layer on hover.
textColorColor of the score text.
sizeStar icon size; numbers are treated as px.
gapGap between stars; numbers are treated as px.
animatedPlays the bounce and ripple after a selection.
starLabel-Accessible label for each star; defaults to English `Rate N star(s)`.

Events

EventPayloadDescription
update:modelValue(value: number)Fires with the new score after an interactive star is clicked.
change(value: number)Fires together with update:modelValue.

Slots

SlotPropsDescription
text{ value: number, max: number }Replaces the default value / max text when showText is on.

Overview

  • The star row renders as role="radiogroup", and each star is a role="radio" button.
  • Keyboard: the row is a single tab stop; ArrowRight/ArrowUp select the next star and ArrowLeft/ArrowDown the previous, without wrapping; Home/End select the first and last.
  • disabled and readonly both block updates; the score still shows.

Technologies

  • Source: packages/tuffex/packages/components/src/rating/; exports the RatingProps, RatingEmits, and RatingIcon types.
查看源码
packages/tuffex/packages/components/src/rating/index.ts