Measurement Unit View
A measurement unit view displays a measurement unit in a <span> element. A measurement unit is a standard quantity used to express a measurement, such as "kg", "lb", "cm", or "inch". This component is part of the Input/View pattern for measurement data, providing a read-only display of unit abbreviations or names.
The component supports an optional aria-label for additional accessible context, which is useful when abbreviated units may not be clear to screen reader users (e.g., labeling "lb" as "Pounds").
Example
cm
Show demo markup
<span class="measurement-unit-view">cm</span>
Usage example
<script lang="ts">
import MeasurementUnitView from "./MeasurementUnitView.svelte";
</script>
<MeasurementUnitView value="kg" />
Show Svelte source
// In your Svelte component:
import MeasurementUnitView from "lily-design-system-svelte-headless/components/MeasurementUnitView/MeasurementUnitView.svelte";
<MeasurementUnitView label="Label" value="Sample value" />
Usage
Display a unit alongside a measurement value:
<MeasurementInstanceView value="72" />
<MeasurementUnitView value="kg" label="Kilograms" />
Display an abbreviated unit with accessible label:
<MeasurementUnitView value="lb" label="Pounds" />
Display a unit in a clinical summary:
<MeasurementUnitView value="mmHg" label="Millimetres of mercury" />
Props
value: string (required) -- the measurement unit to display
label: string (optional) -- accessible name via aria-label for additional context
Keyboard Interactions
None -- this is a display-only component.
ARIA
aria-label -- optionally set from the label prop to provide additional context beyond the displayed unit abbreviation
When to Use
- Use to display a measurement unit in read-only format.
- Use alongside MeasurementInstanceView to show the unit separately from the value.
- Use in dashboards, reports, or detail views where the unit should be visible but not editable.
When Not to Use
- Do not use for selecting a unit -- use MeasurementUnitInput instead.
- Do not use for displaying the measurement system -- use MeasurementSystemView instead.
Headless
This headless component renders a <span> with the measurement unit as text content and optional aria-label for additional accessible context. The consumer provides all visual styling, including typography, positioning relative to the value, and any abbreviation expansion.
Styles
The consumer provides all CSS styling. The component renders with a .measurement-unit-view class for targeting. No default styles are included — this is a fully headless component.
Testing
- Verify the component renders a
<div> element with class measurement-unit-view
- Verify aria-label
-- optionally set from the label` prop to provide additional context beyond the displayed unit abbreviation
- Verify pass-through attributes are applied
Advice
- Designers: Display units in a consistent style (e.g., smaller font size or muted color) positioned immediately after their corresponding values.
- Developers: Provide the
label prop when displaying abbreviated units (e.g., labeling "lb" as "Pounds") so screen reader users understand the full meaning.
Implementation Notes
- Renders as a
<span> element displaying the measurement unit as text content
- A measurement unit is a standard quantity for expressing measurements (e.g., "kg", "lb", "cm", "inch")
- Optional
label prop maps to aria-label for additional accessible context
- Text content is inherently accessible to screen readers
- Spreads
...restProps on the root <span> element for consumer customization
- No hardcoded user-facing strings; all text comes through props
Composition
MeasurementUnitView is part of the measurement component family. It is the read-only counterpart to MeasurementUnitInput and works alongside MeasurementInstanceView, MeasurementSystemView, and their input counterparts.
Related components
measurement-unit-input — an input for selecting a measurement unit
References
Canonical contract
Generated from this component's canonical metadata — the machine-checked source the implementations are held to.
Metadata
- Component: measurement-unit-view
- PascalCase: MeasurementUnitView
- Description: a read-only display of a measurement unit
- Status: beta — implemented and unit-tested in all seven frameworks with an axe-clean demo page; not yet exercised in composed flows
- HTML tag: <div>
- CSS class: .measurement-unit-view
- Interactive: no
ARIA
aria-label -- optionally set from the label prop to provide additional context beyond the displayed unit abbreviation
Keyboard
- No keyboard interactions — this is a passive element
Props
value: string (required) -- the measurement unit to display label: string (optional) -- accessible name via aria-label for additional context