Meter
A graphical display of a numeric value within a range.
<script setup lang="ts">
import { Meter } from '@vase-ui/vue/meter';
import styles from './index.module.css';
</script>
<template>
<Meter.Root :class="styles.Meter" :value="24">
<Meter.Label :class="styles.Label">Storage Used</Meter.Label>
<Meter.Value :class="styles.Value" />
<Meter.Track :class="styles.Track">
<Meter.Indicator :class="styles.Indicator" />
</Meter.Track>
</Meter.Root>
</template>.Meter {
display: grid;
grid-template-columns: 1fr 1fr;
row-gap: 0.5rem;
width: 15rem;
max-width: 100%;
}
.Label {
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 400;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
color: white;
}
}
.Value {
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(14.5% 0 0deg);
text-align: right;
@media (prefers-color-scheme: dark) {
color: white;
}
}
.Track {
grid-column: 1 / 3;
overflow: hidden;
height: 0.75rem;
background-color: oklch(92.2% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
.Indicator {
background-color: oklch(14.5% 0 0deg);
transition: width 500ms;
@media (prefers-color-scheme: dark) {
background-color: white;
}
}<script setup lang="ts">
import { Meter } from '@vase-ui/vue/meter';
</script>
<template>
<Meter.Root class="grid max-w-full w-60 grid-cols-2 gap-y-2" :value="24">
<Meter.Label class="text-sm font-normal text-neutral-950 dark:text-white"
>Storage Used</Meter.Label
>
<Meter.Value class="text-right text-sm text-neutral-950 dark:text-white" />
<Meter.Track class="col-span-2 h-3 overflow-hidden bg-neutral-200 dark:bg-neutral-800">
<Meter.Indicator class="bg-neutral-950 transition-[width] duration-500 dark:bg-white" />
</Meter.Track>
</Meter.Root>
</template>Anatomy
Import the component and assemble its parts:
<script setup lang="ts">
import { Meter } from '@vase-ui/vue/meter';
</script>
<template>
<Meter.Root :value="0">
<Meter.Label />
<Meter.Track>
<Meter.Indicator />
</Meter.Track>
<Meter.Value />
</Meter.Root>
</template>API reference
Meter.Root
Groups all parts of the meter and provides the value for screen readers. Without a
Meter.Label, give it aria-label or aria-labelledby. With the element slot, put text in
your element, such as a Meter.Label: NVDA and JAWS can need text in a meter to say its name.
Renders a <div> element with the role meter.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
format | Intl.NumberFormatOptions | undefined | The options of Intl.NumberFormat for the text. With none, the text is a percent of the range. | |
getAriaValueText | ((formattedValue: string, value: number) => string) | undefined | Gives aria-valuetext from the text and the value prop. | |
locale | Intl.LocalesArgument | the locale of the nearest LocaleProvider, else 'en-US' | The locale of the text. |
max | number | undefined | 100 | The value at the end of the range. |
min | number | undefined | 0 | The value at the start of the range. |
value | number | Required | The value of the meter. |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | The content of the part. | |
element | props: Record<string, unknown>elementRef: (target: unknown) => void | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLDivElement | null | The element of the part, or null while it is not mounted. |
Meter.Track
Contains the meter indicator and represents the entire range of the meter.
Renders a <div> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | The content of the part. | |
element | props: Record<string, unknown>elementRef: (target: unknown) => void | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLDivElement | null | The element of the part, or null while it is not mounted. |
Meter.Indicator
Visualizes the position of the value along the range. It has the inline style
inset-inline-start: 0, height: inherit and a width with the percent of the range.
Renders a <div> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | The content of the part. | |
element | props: Record<string, unknown>elementRef: (target: unknown) => void | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLDivElement | null | The element of the part, or null while it is not mounted. |
Meter.Value
A text element that shows the current value.
Renders a <span> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | formattedValue: stringvalue: number | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidformattedValue: stringvalue: number | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLSpanElement | null | The element of the part, or null while it is not mounted. |
Meter.Label
An accessible label for the meter. Use one in each meter.
Renders a <span> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | undefined | The meter names the label by this id in aria-labelledby from the mount on. To name the meter
in the server HTML too, give Meter.Root this id in aria-labelledby. An id in the
element slot does not name the meter. | |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | The content of the part. | |
element | props: Record<string, unknown>elementRef: (target: unknown) => void | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLSpanElement | null | The element of the part, or null while it is not mounted. |
Differences from Base UI
Vase UI ports Meter from Base UI 1.9.0.
API
| Base UI | Vase UI |
|---|---|
Meter.Root prop aria-valuetext | An ARIA attribute is a plain attribute of the root, not a prop. It reaches the element with the other attributes, and it wins over the text of the part. |
Meter.Root | The state of the root is {}, so a state type and a state slot prop give the developer nothing. With no locale, the text has the locale of the nearest LocaleProvider, else en-US, and not the locale of the browser, so that the server HTML and the first render of the browser agree. |
Meter.Track | The state of the track is {}, so a state type and a state slot prop give the developer nothing. |
Meter.Indicator | The state of the indicator is {}, so a state type and a state slot prop give the developer nothing. |
Meter.Value | The state of the value is {}, so a state type and a state slot prop give the developer nothing. |
Meter.Label | The state of the label is {}, so a state type and a state slot prop give the developer nothing. |
Behavior
| Vase UI | Evidence |
|---|---|
The server HTML of Progress.Root, Meter.Root and Fieldset.Root has the id of the label part in aria-labelledby, when that part has no id prop. The root assumes a label until it is mounted, unless the consumer gives it an aria-label or aria-labelledby, also a blank one. A progressbar or a meter that has a label thus has its required name before the page hydrates. It has that name on a page with no client code too. Base UI adds the attribute after the page hydrates. With no label part, the server HTML of the root points at an id that no element has, and a user agent ignores that reference. |
|
With no locale prop, Meter.Root, Progress.Root, Slider.Root and NumberField.Root format their text in the locale of the nearest LocaleProvider, else in en-US. The server and the browser use the same locale, so the text does not change after the hydration. Base UI formats the text of Meter, Progress and Slider in en-US until the hydration, and then in the locale of the browser. It formats the text of Number Field in the default locale of each runtime, so the server and the browser can differ. |
The handbook gives the differences that all components share: Styling, Animation, Composition, Customization, Forms and TypeScript.