Skip to main content
Vuetify0 is now in alpha!
Vuetify0 Logo
Theme
Mode
Palettes
Accessibility
Vuetify One
Sign in to Vuetify One

Access premium tools across the Vuetify ecosystem — Bin, Play, Studio, and more.

Not a subscriber? See what's included

createRating

Bounded number with discrete items. Give it a size, get items to iterate with full/half/empty state. Half-step support for 0.5 increments.

Usage

ts
import { createRating } from '@vuetify/v0'
import { shallowRef } from 'vue'

// Basic — standalone
const rating = createRating({ size: 5 })
rating.select(3)
rating.items.value
// [
//   { value: 1, state: 'full' },
//   { value: 2, state: 'full' },
//   { value: 3, state: 'full' },
//   { value: 4, state: 'empty' },
//   { value: 5, state: 'empty' },
// ]

// With half-step support
const half = createRating({ size: 5, half: true })
half.select(2.5)
half.items.value[2].state // 'half'

// With v-model (pass a ref)
const value = shallowRef(0)
const bound = createRating({ value, size: 5 })
bound.select(4)
value.value // 4

Context / DI

Use createRatingContext to share a rating instance across a component tree:

ts
import { createRatingContext } from '@vuetify/v0'

export const [useProductRating, provideProductRating, productRating] =
  createRatingContext({ namespace: 'my:rating', max: 5 })

// In parent component
provideProductRating()

// In child component
const rating = useProductRating()
rating.select(4)

Reactivity

PropertyTypeReactiveDescription
valueWritableComputedRef<number>YesCurrent rating, clamped 0–size
sizenumberGetterTotal items
halfbooleanGetterHalf-step enabled
itemsComputedRef<RatingItem[]>YesItems with full/half/empty state
isFirstReadonly<Ref<boolean>>YesValue is 0
isLastReadonly<Ref<boolean>>YesValue equals size
select(v)(value: number) => voidSet rating
next()() => voidIncrement by step
prev()() => voidDecrement by step
first()() => voidSet to 0
last()() => voidSet to size

Examples

API Reference

The following API details are for the createRating composable.
Was this page helpful?

Ctrl+/