Components

Rating

Accessible rating input with fractional values, hover preview, keyboard navigation, and forms.

Rating is a radio-group control for bounded scores. It supports fractional steps, hover previews, clearable values, RTL, vertical navigation, native validation, and custom slots.

Use Meter to display a read-only score.

Anatomy

  • #item: Replaces one complete rating item and receives fill percentage and state.
  • #empty: Empty visual rendered inside each default item.
  • #filled: Filled visual clipped inside each default item.
  • #radio: Optional content inside each transparent fractional radio target.
  • #state: Optional renderless output with committed, preview, hover, and item state.

The component generates accessible radio buttons over each visual item. Keep those controls mounted when replacing visuals through slots.

Usage

Rating: 3.5 / 5

Examples

Fractional rating

Set step below 1 to expose fractional radio values. Akaza supports the Reka-compatible values 0.5, 0.25, and 0.1, plus other positive values up to 1.

<template>
  <Rating v-model="rating" :step="0.25" />
</template>

Clearable and hoverable

hoverable previews the pointer value without committing it. clearable resets the current value to 0 when selected again.

<template>
  <Rating v-model="rating" hoverable clearable />
</template>

Custom length and labels

Change the number of items and provide localized value text with getValueLabel.

<template>
  <Rating
    v-model="rating"
    :length="10"
    :get-value-label="(value, max) => `${value} points out of ${max}`"
  />
</template>

Read-only and disabled

Read-only ratings remain perceivable and focusable but reject changes. Disabled ratings are removed from interaction and native form submission.

<template>
  <Rating :model-value="4" read-only aria-label="Average rating" />
  <Rating :model-value="2" disabled aria-label="Unavailable rating" />
</template>

Field and native forms

Inside Field, Rating inherits label, name, required, disabled, and error metadata. Required validation treats 0 as empty.

<template>
  <Field label="Service rating" name="rating" required>
    <Rating v-model="rating" />
  </Field>
</template>

Fractional values

Rendering, normalization, keyboard navigation, and submission use the same legal value grid. Arbitrary steps such as 0.3 are supported; the terminal maximum remains selectable even when the step does not divide it evenly. An accepted nonzero value corresponds to a rendered checked radio.

Default star content is replaceable through #empty and #filled. Provide visual sizes and colors through ui; custom artwork belongs in those slots.

Native Form Reset

A native form reset restores the initial model and clears interaction state. Calling preventDefault() on the reset event preserves the current value. Reset updates v-model without emitting value-change.

API Reference

Model

ModelTypeDefaultDescription
v-modelnumber0Selected score. 0 means no rating.

Props

PropTypeDefaultDescription
lengthnumber5Number of rating items.
stepnumber1Selection granularity, clamped from 0.01 through 1.
clearablebooleanfalseSelecting the committed value clears it.
hoverablebooleanfalsePreviews pointer values before commit.
loopbooleantrueLoops arrow navigation at range boundaries.
orientation"horizontal" | "vertical""horizontal"Layout and arrow-key axis.
dir"ltr" | "rtl""ltr"Horizontal navigation direction.
autoFocusbooleanfalseFocuses selected or first value on mount.
idstringfield/generated idNative validity input id.
namestringfield nameNative form field name.
requiredbooleanfalseRequires a value above 0.
disabledbooleanfalseDisables interaction and form submission.
readOnlybooleanfalseBlocks value changes without disabling focus.
invalidbooleanfalseControlled invalid state.
ariaLabelstring"Rating"Accessible group label.
ariaLabelledbystringId of an external label.
ariaDescribedbystringfield idsAccessible description ids.
getValueLabel(value, maximum) => string"value of maximum"Accessible label for each radio value.
uiRatingUiClasses for structural parts.

Emits

EventPayloadDescription
update:modelValuevalueFired after an accepted selection.
value-change(value, details)Fired before commit. details.cancel() prevents it.
hover-change(value | null, details)Fired when hover preview enters, moves, or leaves. Cancelable.

Slots

SlotPropsDescription
itemitem, value, previewValue, fill, stateReplaces one full visual item.
emptyitemEmpty item visual.
filleditemFilled item visual.
radiovalue, labelContent inside a generated radio target.
statevalue, previewValue, items, hoveredValue, clearOptional state-driven custom UI.

Methods

MethodDescription
clear(event?)Sets the rating to 0 when editable.
focus()Focuses the selected value or first radio.

UI Options

KeyDescription
rootRadio-group root.
hiddenInputNative form/validity input.
itemOne visual item wrapper.
baseEmpty visual wrapper.
fillClipped filled visual wrapper.
fillIconInner filled visual kept at full width.
radioFractional radio button.

Styling Hooks

UI keyCSS classData attrs / variables
rootakaza-rating`data-akaza-state="empty
hiddenInputakaza-rating-hidden-inputnative validity attrs
itemakaza-rating-item`data-akaza-state="active
baseakaza-rating-base
fillakaza-rating-fill--akaza-rating-item-fill
fillIconakaza-rating-fill-icon
radioakaza-rating-radio`data-akaza-state="checked

Plain class applies to the radio-group root. Use item/fill/radio UI keys for custom rating visuals.

Keyboard

KeyBehavior
ArrowRight / ArrowLeftMove by step in horizontal mode, respecting RTL.
ArrowDown / ArrowUpMove by step in vertical mode.
HomeSelect the first value.
EndSelect the maximum value.
Space / EnterSelect focused value; may clear it when clearable.