Skip to content

Scale input

Give a rating on a short labeled scale and, where clearing is allowed, take it back by choosing the same value again.

Difficulty
6 / 10
easyhard
Rating
— / 5
mehtop

Empty until you decide. A click on the mark clears it.

<script setup lang="ts">import { ref } from 'vue'import { UiField, UiScaleInput } from 'grani' const difficulty = ref(6) const rating = ref(null)</script> <template>  <div class="flex w-80 max-w-full flex-col gap-6">    <UiField label="Difficulty" group>      <UiScaleInput v-model="difficulty" low-label="easy" high-label="hard" />    </UiField>    <UiField      label="Rating"      description="Empty until you decide. A click on the mark clears it."      group    >      <UiScaleInput v-model="rating" :max="5" low-label="meh" high-label="top" />    </UiField>  </div></template>

Also called rating, nps scale, likert scale, score input.

Usage

<UiScaleInput v-model="value" />

With GraniResolver in the Vite config, a template needs no import: set it up once.

API

Name · typeDefaultDescription
Value
modelValue*number | nullThe mark (v-model); null while there is no answer.
Behavior
minnumber= 11First step of the scale.
maxnumber= 1010Last step. Twelve steps at most.
clearableboolean= truetrueA click on the mark, Delete or Backspace clears the answer; off, an answer once given stays.
unitstring= """"Shown after the readout: "7 / 10 km".
readoutboolean= truetrueThe line "mark / max" above the bar.
showNumbersboolean= truetrueNumbers in the segments; off for a dense row.
invertboolean= falsefalseReverses the thermometer: more is worse (difficulty, pain, load).
lowLabelstring= """"What the low end means: "easy".
highLabelstring= """"What the high end means: "hard".
Look
variantbrand | thermometer= "brand""brand"brand fills with the brand; thermometer colors the fill by the mark, danger through warning to success.
sizexs | smHeight of the bar on the control ladder: xs 28, sm 36. Unset, the app's size (createGrani({ size })); md is read as sm: the scale has no md.
Form and access
disabledboolean= falsefalseNothing can be picked.
invalidboolean= falsefalseMarks the control invalid: the empty segments and the frame take the danger tone. Inside UiField the error sets this.
requiredboolean= falsefalseAn answer is needed: said to a reader on the group. Not enforced by a form: the hidden input takes no validation. Inside UiField group the legend says it instead.
idstringOwn id of the group, for a reference from elsewhere (aria-controls, a link); a field names it by its legend.
namestringForm field name: a hidden input sends the mark; nothing is sent while there is no answer or the scale is disabled.
ariaLabelstringAccessible name of the scale when there is no UiField around.

Attributes: class and style stay on the outer element; the rest (native attributes, aria-*, data-testid) reach the control inside it.

When to use another component

When you needTake
A free numberInput numeric
A count of thingsStepper
One answer in wordsRadio group segmented
A mark shown without editingProgress with :step="1", in a table or on a card