Rating
Added in alpha.11
Included in Mavis 0.1.0-alpha.11 for Vue + Vite, Nuxt and NativeScript iOS/Android. Keep core and renderers on the same version.
<MRating v-model="score" :step="0.5" label="How was your stay?" />| Prop | Type | Default | Description |
|---|---|---|---|
modelValue / v-model | number | 0 | Rating from zero through max. |
max / step | number / 1 or 0.5 | 5 / 1 | One to ten stars, whole or half increments. |
readonly / disabled | boolean | false | Summary without controls or disabled controls. |
clearable / clearLabel | boolean / string | true / Clear rating | Explicit action to clear. |
formatValue | (value, max) => string | — | Score text and accessible names. |
Actionable stars choose whole values and use MButton’s Jolt feedback. Stars that light together rise one after another, so choosing four from one reads as a single gesture; stars that go out settle back without the cascade. With step 0.5, a slider selects half stars by touch, keyboard or assistive input. Readonly displays icons and a textual score without actions. Values clamp and snap; use the numeric model rather than extracting icon text.
<script setup lang="ts">
import { computed, ref } from 'vue'
import { useCatalogLocale } from '../locale'
const props = defineProps<{ lang?: 'en' | 'pt' }>()
const { locale } = useCatalogLocale(() => props.lang)
const pt = computed(() => (props.lang ?? locale.value) === 'pt')
const t = (en: string, br: string) => (pt.value ? br : en)
const score = ref(3.5)
</script>
<template>
<MCard padding="lg" gap="lg">
<MRow gap="md"
><MAvatar name="Marina Costa" size="lg" /><MColumn gap="xs"
><MText text="Marina Costa" weight="600" /><MText
:text="
t('A thoughtful host, a lovely stay.', 'Uma anfitriã atenciosa. Uma estadia especial.')
"
variant="caption"
tone="muted" /></MColumn
></MRow>
<MSeparator />
<MRating
v-model="score"
:step="0.5"
:label="t('How was your stay?', 'Como foi sua estadia?')"
/>
<MRating
:modelValue="4.5"
:step="0.5"
readonly
:label="t('Guest favorite', 'Favorito dos hóspedes')"
/>
<MText id="rating-value" :text="String(score)" variant="caption" tone="muted" />
</MCard>
</template>Desktop
On the desktop each star is a button drawn with the colours of the theme, reached with Tab and chosen with a click or Space; half steps add a slider, as on the other targets. The stars tilt and rise in turn as they light up, as on the other targets; see Desktop components.