Rate
Half stars, touch scoring, keyboard adjustment and precise readonly fractions.
Import
With uni-app easycom, use hui-rate。 Standalone Vue imports @nscode/handy-uni/web HuiRate or installs the preview plugin.
Examples
Interaction and event results
Interact with the control. The latest event and its full payload are shown below. Popup selectors commit only after confirmation; cancellation keeps the previous value.
vue
<script setup lang="ts">
import { ref } from 'vue'
const result = ref('')
const value = ref(2.5)
function event0(arg0: unknown) {
result.value = 'update:modelValue' + ': ' + JSON.stringify([arg0])
}
function event1(arg0: unknown) {
result.value = 'change' + ': ' + JSON.stringify([arg0])
}
</script>
<template>
<view>
<hui-rate
v-model="value"
allow-half
clearable
show-text
@update:model-value="event0"
@change="event1"
></hui-rate>
<text aria-live="polite">{{ result }}</text>
</view>
</template>
Clear through a component ref
clear() requests a score of 0. Disabled and readonly controls ignore it. A changed score emits update:modelValue, then change; controlled display waits for the parent update.
vue
<script setup lang="ts">
import { ref } from 'vue'
import type { RateExpose } from '@nscode/handy-uni'
const control = ref<RateExpose>()
const value = ref(3)
</script>
<template>
<view>
<hui-rate ref="control" v-model="value" />
<hui-button @click="control?.clear()">Clear</hui-button>
<text>{{ value }}</text>
</view>
</template>
Props
| Property | Type | Default | Description |
|---|---|---|---|
model-value | number | undefined | undefined | Controlled committed value; display remains unchanged until the parent writes back. |
default-value | number | undefined | 0 | Initial uncontrolled value. |
max | number | undefined | 5 | Upper bound, star count for Rate, or maximum multiple-selection count. |
allow-half | boolean | undefined | false | Allow half-star values. |
clearable | boolean | undefined | false | Show clear action and emit model/change updates. |
touchable | boolean | undefined | true | Allow horizontal touch scoring. |
disabled | boolean | undefined | false | Disable user interaction, including inherited form state. |
readonly | boolean | undefined | undefined | Readonly; inherit form context when omitted. |
show-text | boolean | undefined | false | Show descriptive text or score. |
texts | string[] | undefined | — | Text for each score. |
icon | string | undefined | 'star' | Selected icon name. |
void-icon | string | undefined | 'star' | Unselected icon name. |
size | ComponentSize | undefined | — | small, default or large size. |
custom-class | string | undefined | '' | Additional root classes. |
custom-style | string | CSSProperties | undefined | — | Additional root styles. |
Events
| Event | Parameters | Description |
|---|---|---|
update:modelValue | (value: number) | Requests a controlled value update. |
change | (value: number) | Reports change with the arguments shown in the example. |
Slots
| Slot | Description |
|---|
Methods
| Method | Signature |
|---|---|
clear | () => void |
Types
RateProps、RateEmits、RateExpose。 Public types are exported from the package entry.
Platform notes
| Scope | Behavior and validation limits |
|---|---|
| Shared implementation | Rating and half-step rules are shared across targets. Touch positions use platform measurements. |
| Device checks pending | Check full and half ratings, readonly/disabled behavior and accessible labels on devices; also check keyboard ratings in ordinary Vue. |
See examples/uni-demo/smoke/Rate.md for the checklist. Unit tests do not replace device acceptance.