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 schemaInstall
import { Rating } from 'vael-ui'Playground
undefined
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>Motion New
Rating: its appearance, star by star, and states.
<Rating
:motion="{ states: { disabled: { item: { scale: 1.04 } } } }"
/>| Name | Type | Description |
|---|---|---|
initialexit | rootitem | Sets 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. |
states | disabledfocus | Sets 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) => animation | Animates 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 | string | Times all of it: a spring, or a duration in ms with an easing. Never both. |
false | boolean | Turns 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.
| Key | Action |
|---|---|
| ArrowRightArrowUp | Adds one star, or half a star with allowHalf. |
| ArrowLeftArrowDown | Removes one star, or half a star with allowHalf. |
| Home | Sets the rating to 0. |
| End | Sets the rating to max. |
- The rating is one focusable element with
role="slider", not a group of radio buttons.aria-valuetextreads “3 of 5” by default; change it withvalueTextor therating.valueTextmessage. readonlysetsaria-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, anderrorsetsaria-invalid. Without one, passaria-label. - Right to left, ArrowLeft and ArrowRight swap.