Skip to content

Forms

IRating ​

A score out of five, read or set. Read-only by default — most ratings on a page are being shown, not collected.

Fractions are painted, not rounded ​

A score of 3.7 fills seven tenths of the fourth star. The filled icon is layered over the empty one and clipped, so a partial star is the same shape cut short rather than a second icon that has to line up with the first — which is what makes any icon work, not just a star.

vue
<IRating :model-value="3.7" />

Collecting one ​

interactive lets the reader set the value. It is one tab stop, not five: arrow keys move by a step, and go to the ends, and a click sets the value directly.

Chosen: 3

Half stars ​

step is the smallest amount the reader can choose. Display is continuous either way.

vue
<IRating v-model="score" interactive :step="0.5" />

Another icon ​

Any Hugeicons export, or any component that renders an SVG. The fill colour comes from ui.fill, so a heart can be red without touching the rest.

Accessibility ​

The two modes announce differently, because they are different things.

Read-only, the row is one image with a text alternative: a screen reader hears "Overall rating: 4 out of 5", not five icons in a row. Interactive, it is a slider — one value between a minimum and a maximum, which is what the reader is actually setting, and the role brings the arrow keys they already expect.

Either way it needs a name. label is that name, and the default of "Rating" is only right when the page has one.

Props ​

PropTypeDefaultDescription
modelValuenumber0The score. Clamped to the range
maxnumber5How many icons
interactivebooleanfalseLet the reader set it
stepnumber1Smallest amount the reader can choose
size'sm' | 'md' | 'lg''md'Icon size
disabledbooleanfalseDim it and ignore input
iconIconLikeStarIconThe icon to repeat
labelstring'Rating'Accessible name
showValuebooleanfalsePrint the score beside the icons
unstyledboolean—Drop built-in classes
classstring—Merged with the built-in classes
ui{ root?, items?, item?, empty?, fill?, label? }—Per-element class overrides