Skip to content

Rating

Choose a rating with whole or fractional values.

Demos

Size

Usage

vue
<script setup lang="ts">
import { Accordion } from '~/components/ui/accordion'

const items = [
  { value: 'source', label: 'Do I own the source?', content: 'Yes. Copy and adapt the files.' },
]
</script>

<template>
  <Accordion :items="items" />
</template>

Rating uses SVG stars with a clipped fill for fractional values. The native radio buttons cover the star area and retain keyboard interaction. Coarse pointers get a 44px target around each star while the icon follows the selected size. Set step="0.5" to try half ratings.

Installation

Complete the shared installation. Copy Rating.vue and index.ts into app/components/ui/rating/.

API

Variants and defaults

PropValuesDefault
sizexs, sm, md, lg, xlsm

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.
ariaLabelledbystring—Id of an external label.
ariaDescribedbystringfield idsAccessible description ids.
getValueLabel(value, maximum) => string"value of maximum"Accessible label for each radio value.
uiRatingUi—Classes for structural parts.

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.

Events

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.

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.