Rating
The VdRating component renders an interactive star-rating widget. Configure the maximum number of stars, pre-set a value, make it read-only, or pick a size variant — all through component props.
Basic 5-Star Rating
Pre-set Value (3 of 5)
Read-Only
Custom Max (10 Stars)
Size Variants
Small
Default
Large
API Reference
Usage
<script setup lang="ts">
import { ref } from "vue";
import { VdRating } from "@vanduo-oss/vd3";
const value = ref(3);
</script>
<template>
<VdRating v-model="value" :max="5" @change="onChange" />
</template>CSS Classes
| Class | Description |
|---|---|
.vd-rating | Container wrapping the star elements |
.vd-rating-star | Individual star element (filled or empty depending on value) |
.vd-rating-readonly | Added to the container when readonly; disables hover/click interactions |
.vd-rating-sm | Small size variant — rendered when the size prop is "sm" |
.vd-rating-lg | Large size variant — rendered when the size prop is "lg" |
.vd-rating-value | Optional text element displaying the numeric value (e.g. "4 / 5") |
Component API
| Prop / event | Description |
|---|---|
v-model (modelValue) | Two-way bound rating value (number). |
:max | Number of stars (default 5). |
:size | 'sm' | 'lg' size variant. |
:readonly | Display-only, non-interactive when true. |
@update:modelValue / @change | Fired with the new value when the user picks a star. |
Accessibility
- The container renders
role="radiogroup"witharia-label="Rating". - Each star button has
role="radio"witharia-checked,aria-label(e.g."1 star","3 stars"), and rovingtabindex(0on the active/first star,-1on the rest). - ArrowRight / ArrowUp increment the rating and ArrowLeft / ArrowDown decrement it, moving DOM focus to the newly selected star.
- When
readonlyis set, all star buttons receivetabindex="-1"and ignore pointer and keyboard changes.