Skip to content

Rate ​

17:06

Description ​

Rating component supporting tap and slide to rate. Configurable star count, size, gutter and selected/unselected colors, plus allow-half half stars and colors / icons for segment coloring by rating range. The selected star count is bound via v-model (model-value defaults to -1 as a sentinel) and change returns the current value.

Compatibility ​

PlatformSupport
App✅ Supported
H5✅ Supported
WeChat Mini Program✅ Supported

Examples ​

Basic Usage ​

Click a star to rate; clicking the first star clears the rating.

View source
vue
<template>
    <ux-rate :model-value="value" @change="onChange" />
</template>

<script setup lang="uts">
const value = ref<number>(0);

const onChange = (val: number) => {
    value.value = val;
};
</script>

Count & Size ​

Set the number of stars via count and star size via size.

View source
vue
<template>
    <ux-rate :count="8" :current="5" :size="22" />
</template>

Custom Colors ​

Customize selected/unselected colors via active-color / inactive-color.

View source
vue
<template>
    <ux-rate :current="3" active-color="#ff9900" inactive-color="#c8c9cc" />
</template>

Half Star allow-half ​

When allow-half=true, tap the left half of a star to select half a star (0.5) or the right half for a full star; tapping the first star's half or full clears the rating.

View source
vue
<template>
    <ux-rate :model-value="value" allow-half active-color="#fa3534" @change="onChange" />
</template>

<script setup lang="uts">
const value = ref<number>(3.5);

const onChange = (val: number) => {
    value.value = val;
};
</script>

Disabled State ​

When disabled=true the component is not interactive and only displays the rating.

View source
vue
<template>
    <ux-rate :current="4" disabled />
</template>

Segmented Colors ​

Use the colors array to display different colors by rating range.

View source
vue
<template>
    <ux-rate :model-value="value" :colors="colors" @change="onChange" />
</template>

<script setup lang="uts">
const value = ref<number>(3);
const colors: string[] = ['#2979ff', '#ff9900', '#fa3534'];

const onChange = (val: number) => {
    value.value = val;
};
</script>

API ​

Props ​

PropertyDescriptionTypeDefaultVersion
customStyleCustom root element stylestring | UTSJSONObject--
customClassCustom root element style classstring''-
modelValueNumber of selected stars, two-way bound via v-modelnumber | string-1-
countNumber of stars to displaynumber | string5-
currentStar count selected by defaultnumber | string0-
disabledWhether selection is disabledbooleanfalse-
sizeStar sizenumber | string16-
inactiveColorColor of unselected starsstring''-
activeColorColor of selected starsstring''-
gutterGutter between starsnumber | string5-
minCountMinimum number of stars to selectnumber | string0-
allowHalfWhether half stars are allowedbooleanfalse-
activeIconIcon of selected starsstring'star-fill'-
inactiveIconIcon of unselected starsstring'star'-
customPrefixCustom icon prefixstring'uicon'-
colorsSegmented colorsstring[]--
iconsSegmented iconsstring[]--

Events ​

EventDescriptionParamsVersion
changeFires when the selected stars changevalue: number-

Slots ​

ux-rate has no slots.

Notes ​

  1. model-value defaults to -1 as a sentinel: only a non--1 value (or v-model) enables two-way binding and syncs update:modelValue on change; with current alone the component does not write back.
  2. With allow-half, tapping a star's left half records 0.5 and the right half a full star; tapping the first star's full star (when already 1) or half star (when already 0.5) clears the rating.
  3. Tap and slide (touchmove) are both supported; slide rating converts by the measured single-star width, and half-star detection depends on the initial layout measurement — remeasure after the container width changes.
  4. min-count sets the minimum selectable stars; count sets the number of stars; disabled blocks both tap and slide.
  5. colors / icons only take effect when the array length is no greater than count, picking color / icon by rating range; otherwise they fall back to active-color / active-icon.
  6. Stars come from ux-icon; replace the icon names via active-icon / inactive-icon.
  7. Inside ux-form-item, a rating change triggers form validation; the -1 placeholder (unrated) does not.