vael-ui v0.5.7

Forms & inputs

Layout

Rating

A row of stars you click, drag or set with the arrow keys, with optional half steps. Use it for reviews and feedback.

Validating a form? vael-form wires this up with a schema

Install

import { Rating } from 'vael-ui'

Playground

Placement, behaviour and animation

Usage
<script setup lang="ts">
import { ref } from 'vue'
import { Rating } from 'vael-ui'

const value = ref(0)
</script>

<template>
  <Rating aria-label="Rating" v-model="value" />
</template>

Props

NameTypeDefaultDescription
maxnumber5Number of stars, which is also the highest rating.
allowHalfbooleanfalseHalf-star precision, for both pointer and keyboard (arrow keys step by 0.5).
readonlybooleanfalseShows the rating but ignores pointer and keyboard input. Stays focusable.
disabledbooleanfalseDisables the rating and blocks interaction.
size'sm' | 'md' | 'lg''md'Control size.
namestringNative name for form submission, via a hidden input.
valueText((value: number) => string)Drives aria-valuetext. Defaults to the rating.valueText message ("{value} of {max}").
motionRatingMotiontrueHow it moves: its appearance, star by star ({ initial: { item: { opacity: 0, scale: 0.6 } }, stagger: 0.04 }), and its states ({ states: { disabled: { root: { opacity: 0.5 } } } }). false turns its own animation off, the built-in fill sweep and commit pop too.
uiPartial<Record<'root' | 'item', UiPartValue>>Class and style overrides for each part.
modelValuenumber0Current rating; 0 means unrated.

Events

NameTypeDescription
update:modelValue(value: number)Fires when modelValue changes (v-model).

Slots

No slots.

Exposed

NameTypeDescription
elHTMLElement | nullRoot element.
itemElsHTMLElement[] | nullStar elements, one per star.
partsRecord<string, HTMLElement | HTMLElement[] | null>Its elements by part name, for your own animation; a repeated part is an array.

Motion New

Rating: its appearance, star by star, and states.

<Rating
  :motion="{ states: { disabled: { item: { scale: 1.04 } } } }"
/>
NameTypeDescription
initialexitrootitemSets where each part comes in from and leaves to: any CSS property, plus x, y and blur. A plain number is px, or degrees for rotate.
statesdisabledfocusSets values per part that hold while a state is on. An array is a set of keyframes that plays once as the state turns on, such as a shake on invalid.
enterleave(parts, context) => animationAnimates the parts with GSAP, motion or element.animate(). Return the animation and the component waits for it, and stops it if interrupted.
springdurationeasing{ damping, response } | number | stringTimes all of it: a spring, or a duration in ms with an easing. Never both.
falsebooleanTurns its motion off, for an animation of your own on its exposed elements.

Accessibility

Follows the Slider pattern from the WAI-ARIA Authoring Practices Guide.

KeyAction
ArrowRightArrowUpAdds one star, or half a star with allowHalf.
ArrowLeftArrowDownRemoves one star, or half a star with allowHalf.
HomeSets the rating to 0.
EndSets the rating to max.
  • The rating is one focusable element with role="slider", not a group of radio buttons. aria-valuetext reads “3 of 5” by default; change it with valueText or the rating.valueText message.
  • readonly sets aria-readonly. The rating stays focusable but ignores keys and the pointer. The hover preview is visual only: screen readers hear the committed value.
  • Inside a Field, the label and description are linked, and error sets aria-invalid. Without one, pass aria-label.
  • Right to left, ArrowLeft and ArrowRight swap.