Skip to content

Rating ​

Star rating: keyboard and pointer input, or read-only display (decimal values allowed).

Usage ​

Input ​

3 / 5
vue
<script setup>
import { ref } from 'vue'

const rating = ref(3)
</script>

<template>
  <SuRating v-model="rating" />
</template>

With the keyboard: Tab enters the group, arrow keys change the rating. With clearable, choosing the current rating again resets it to zero.

Read only ​

vue
<SuRating :model-value="4.5" readonly />

In a form ​

vue
<SuFormField label="How was the delivery?" message="Optional">
  <SuRating v-model="review" clearable name="review" />
</SuFormField>

The stars are real radio buttons: with name, the rating is submitted with the form.

API ​

Props ​

PropTypeDefaultDescription
v-modelnumber0Rating (0: none)
maxnumber5Number of stars
readonlybooleanfalseRead only (decimal values allowed)
clearablebooleanfalseChoosing the rating again resets it to zero
namestringgenerated idRadio button name
size'sm' | 'md' | 'lg''md'Size
state'default' | 'success' | 'warning' | 'error''default'State (error: aria-invalid)
disabledbooleanfalseDisabled
requiredbooleanfalseRequired
ariaLabelstring'Rating'Group name outside SuFormField

Events ​

EventPayloadDescription
update:modelValuenumberChosen rating
changenumberChosen rating

Accessibility ​

  • Input: group of native radio buttons (role="radiogroup"), each star named ("3 stars out of 5"); the rating is announced as a checked option.
  • Named by the SuFormField label (aria-labelledby), otherwise "Rating"; message tied with aria-describedby.
  • Read only: an image named "Rated 4.5 out of 5"; the stars are decorative.
  • The hover preview does not change the rating; it goes away when the pointer leaves the stars.

Publié sous licence MIT.