Skip to content
LIBRARYForms

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.

Web preview
Open example ↗
vue
<MRating v-model="score" :step="0.5" label="How was your stay?" />
PropTypeDefaultDescription
modelValue / v-modelnumber0Rating from zero through max.
max / stepnumber / 1 or 0.55 / 1One to ten stars, whole or half increments.
readonly / disabledbooleanfalseSummary without controls or disabled controls.
clearable / clearLabelboolean / stringtrue / Clear ratingExplicit 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.

vue
<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.

Components for NativeScript and Web. Starting with Vue.