Usage
Use the v-model directive to control the rating value of the InputRating component.
<script setup lang="ts">
const value = ref(3)
</script>
<template>
<UInputRating v-model="value" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const value = ref(3)
</script>
<template>
<UInputRating v-model="value" />
</template>
Use the default-value prop to set the initial value when you do not need to control its state.
<template>
<UInputRating :default-value="3" />
</template>
Step
Use the step prop to control the granularity of each star. Set it to 0.5 to allow half-star ratings.
<template>
<UInputRating :step="0.5" :default-value="3.5" />
</template>
Length
Use the length prop to set the number of stars. Defaults to 5.
<template>
<UInputRating :length="10" :step="0.5" :default-value="7.5" />
</template>
Clearable
Use the clearable prop to allow users to clear the rating by clicking on the currently selected value. Defaults to false.
<template>
<UInputRating clearable :default-value="3" />
</template>
Hoverable
Use the hoverable prop to control whether the rating previews the value when hovering over the stars. Defaults to false.
<template>
<UInputRating hoverable :default-value="3" />
</template>
Icon
Use the icon prop to customize the icon used for stars. Defaults to i-lucide-star.
<template>
<UInputRating icon="i-lucide-heart" :default-value="4" />
</template>
Empty Icon
Use the empty-icon prop to customize the icon used for empty stars. If not provided, uses the same icon as icon.
<template>
<UInputRating empty-icon="i-ph-star" icon="i-ph-star-fill" :default-value="3" />
</template>
Color
Use the color prop to change the color of the filled stars.
<template>
<UInputRating color="neutral" :default-value="4" />
</template>
Size
Use the size prop to change the size of the stars.
<template>
<UInputRating size="xl" :default-value="4" />
</template>
Orientation
Use the orientation prop to change the orientation of the rating. Defaults to horizontal.
<template>
<UInputRating orientation="vertical" :default-value="4" />
</template>
Disabled
Use the disabled prop to disable the InputRating component. When disabled, the component has reduced opacity (75%) and shows a not-allowed cursor to indicate it's not interactive.
<template>
<UInputRating disabled :default-value="3" />
</template>
Readonly
Use the readonly prop to display a rating without allowing user interaction. Unlike disabled, it maintains normal appearance (full opacity, default cursor). Use when you want to display a rating that cannot be changed but should look normal.
<template>
<UInputRating readonly :default-value="4.5" />
</template>
API
Props
| Prop | Default | Type |
|---|---|---|
as | 'div' | anyThe element or component this component should render as. |
id | stringThe id of the rating. | |
readonly | false | boolean Make the rating readonly (non-interactive). |
icon | appConfig.ui.icons.star | anyThe icon displayed for each rating value. |
emptyIcon | anyThe icon displayed for empty rating values. Defaults to | |
color | 'primary' | "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral" |
size | 'md' | "xs" | "sm" | "md" | "lg" | "xl" |
orientation | 'horizontal' | "horizontal" | "vertical"The orientation of the rating. |
step | 1 | 1 | 0.5 | 0.25 | 0.1The granularity each rating item is divided into. |
disabled | boolean When | |
required | boolean When | |
name | stringThe name of the field. Submitted with its owning form as part of a name/value pair. | |
modelValue | numberThe controlled rating value. Can be bound with | |
defaultValue | 0 | numberThe rating value when initially rendered. Use when you do not need to control the state of the rating. |
length | 5 | numberThe number of rating items to render. |
clearable | false | boolean When |
hoverable | false | boolean When |
ui | { root?: SlotClass; item?: SlotClass; indicator?: SlotClass; icon?: SlotClass; emptyIcon?: SlotClass; } |
Slots
| Slot | Type |
|---|---|
item | { index: number; filled: boolean; }Rendered for each item. |
Emits
| Event | Type |
|---|---|
update:modelValue | [payload: number] |
change | [event: Event] |
Theme
export default defineAppConfig({
ui: {
inputRating: {
slots: {
root: '',
item: [
'relative inline-block cursor-pointer select-none rounded-sm has-focus-visible:outline-3',
'transition'
],
indicator: 'absolute inset-0 overflow-hidden outline-none text-transparent w-(--reka-rating-item-step-width) opacity-(--reka-rating-item-step-opacity) z-(--reka-rating-item-step-z-index)',
icon: 'block',
emptyIcon: 'block w-full h-full text-muted pointer-events-none'
},
variants: {
orientation: {
horizontal: {
root: 'inline-flex items-center gap-0.5'
},
vertical: {
root: 'inline-flex flex-col items-center gap-0.5'
}
},
size: {
xs: {
item: 'size-3',
icon: 'size-3'
},
sm: {
item: 'size-4',
icon: 'size-4'
},
md: {
item: 'size-5',
icon: 'size-5'
},
lg: {
item: 'size-6',
icon: 'size-6'
},
xl: {
item: 'size-7',
icon: 'size-7'
}
},
color: {
primary: {
indicator: 'data-[state=active]:text-primary',
item: 'outline-primary/25'
},
secondary: {
indicator: 'data-[state=active]:text-secondary',
item: 'outline-secondary/25'
},
success: {
indicator: 'data-[state=active]:text-success',
item: 'outline-success/25'
},
info: {
indicator: 'data-[state=active]:text-info',
item: 'outline-info/25'
},
warning: {
indicator: 'data-[state=active]:text-warning',
item: 'outline-warning/25'
},
error: {
indicator: 'data-[state=active]:text-error',
item: 'outline-error/25'
},
neutral: {
indicator: 'data-[state=active]:text-highlighted',
item: 'outline-inverted/25'
}
},
readonly: {
true: {
root: 'cursor-default',
item: 'cursor-default'
},
false: {}
},
disabled: {
true: {
root: 'opacity-75 cursor-not-allowed',
item: 'cursor-not-allowed pointer-events-none'
},
false: {}
}
},
compoundVariants: [
{
readonly: false,
disabled: false,
class: {
item: 'hover:scale-110'
}
}
],
defaultVariants: {
color: 'primary',
size: 'md'
}
}
}
})
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'
export default defineConfig({
plugins: [
vue(),
ui({
ui: {
inputRating: {
slots: {
root: '',
item: [
'relative inline-block cursor-pointer select-none rounded-sm has-focus-visible:outline-3',
'transition'
],
indicator: 'absolute inset-0 overflow-hidden outline-none text-transparent w-(--reka-rating-item-step-width) opacity-(--reka-rating-item-step-opacity) z-(--reka-rating-item-step-z-index)',
icon: 'block',
emptyIcon: 'block w-full h-full text-muted pointer-events-none'
},
variants: {
orientation: {
horizontal: {
root: 'inline-flex items-center gap-0.5'
},
vertical: {
root: 'inline-flex flex-col items-center gap-0.5'
}
},
size: {
xs: {
item: 'size-3',
icon: 'size-3'
},
sm: {
item: 'size-4',
icon: 'size-4'
},
md: {
item: 'size-5',
icon: 'size-5'
},
lg: {
item: 'size-6',
icon: 'size-6'
},
xl: {
item: 'size-7',
icon: 'size-7'
}
},
color: {
primary: {
indicator: 'data-[state=active]:text-primary',
item: 'outline-primary/25'
},
secondary: {
indicator: 'data-[state=active]:text-secondary',
item: 'outline-secondary/25'
},
success: {
indicator: 'data-[state=active]:text-success',
item: 'outline-success/25'
},
info: {
indicator: 'data-[state=active]:text-info',
item: 'outline-info/25'
},
warning: {
indicator: 'data-[state=active]:text-warning',
item: 'outline-warning/25'
},
error: {
indicator: 'data-[state=active]:text-error',
item: 'outline-error/25'
},
neutral: {
indicator: 'data-[state=active]:text-highlighted',
item: 'outline-inverted/25'
}
},
readonly: {
true: {
root: 'cursor-default',
item: 'cursor-default'
},
false: {}
},
disabled: {
true: {
root: 'opacity-75 cursor-not-allowed',
item: 'cursor-not-allowed pointer-events-none'
},
false: {}
}
},
compoundVariants: [
{
readonly: false,
disabled: false,
class: {
item: 'hover:scale-110'
}
}
],
defaultVariants: {
color: 'primary',
size: 'md'
}
}
}
})
]
})