Forms

VeeRating

A rating component that uses the composition API provided by Vee-Validate to perform validation.

Source code

Click to see the source code for this component on GitHub. Feel free to copy it and adjust it for your own use.

Installation

Usage

UiVeeRating wraps UiRating with a label, hint and animated error message, and registers the value with the surrounding Vee-Validate form. It is always editable. Any other prop (max-rating, step, clearable, icon, size, show-value, filled-icon-class-name, ...) is forwarded to UiRating.

Basic example

A rating starts at 0 (nothing selected). Validate it with min(1) (or min(0.5) when using half stars) to make it required. The required prop only adds the asterisk and aria-required; the schema is what enforces it.

Tap a star to rate us.

Default value

Use v-model or initialValues to set an initial rating. Set step to 0.5 to allow half stars.

3.5

Half stars are supported.

Current value: 3.5

Clearable and custom icon

Set clearable to let users click the current value again to reset it to 0. This is useful for optional ratings. Use icon, size and the *-class-name props to restyle the stars.

Click the selected star again to clear your rating.

Disabled

Ratings can no longer be changed after 30 days.

Review form

Write a review

Tell others what you think about this product.

Minimum 20 characters.

Props

PropTypeDescription
namestringField name registered with Vee-Validate. Falls back to a generated id.
labelstringLabel shown above the rating.
label-hintstringExtra hint shown next to the label.
hintstringHelper text. Hidden while there is an error.
rulesanyVee-Validate rules (or use a schema on useForm).
v-modelnumberCurrent rating.
requiredbooleanShows the required asterisk and sets aria-required.
disabledbooleanPrevents interaction.
validate-on-mountbooleanValidates as soon as the field mounts.
classHTMLAttributes["class"]Classes for the wrapper element.

The label, hint and errorMessage slots are available for custom markup and receive error-message and value.

Accessibility

The rating is exposed as a labelled group containing a radio group, so it supports keyboard navigation (Tab to focus, arrow keys to move between stars, Space to select). The label, hint and error message are linked with aria-labelledby and aria-describedby, and the group is marked aria-invalid when validation fails. The field is marked as touched once focus leaves the rating. Like the other Vee components, errors are shown after a value change or on submit.