Unit Field
Usage
Unit Field is a numeric input combined with a unit selector for measurements such as lengths, weights, or other values that may switch between compatible units. Use it when users should enter a value together with a measurement unit, and when unit conversion should happen as part of the input flow.
import { MtUnitField } from "@shopware-ag/meteor-component-library";
Examples
Disabled
Error
API reference
Props
| Prop | Type | Default |
|---|---|---|
default-unit * | convert.Unit | "mm" |
measurement-type | "length" | "mass" | "length" |
model-value | number | undefined |
placeholder | string | |
number-type | "float" | "int" | |
step | number | 1 |
min | number | |
max | number | |
digits | number | |
fill-digits | boolean | |
allow-empty | boolean | |
number-align-end | boolean | |
label | string | |
error | object | |
disabled | boolean | |
required | boolean | |
name | string | |
size | string | |
help-text | string | |
is-inherited | boolean | |
is-inheritance-field | boolean | |
disable-inheritance-toggle | boolean | |
copyable | boolean | |
copyable-tooltip | boolean | |
z-index | number | null | null |
Events
| Event | Payload |
|---|---|
update:modelValue | [value: number | undefined] |
inheritance-remove | [] |
inheritance-restore | [] |
update:defaultUnit | [value: convert.Unit] |
update:measurementType | [value: "length" | "mass"] |
Best practices
Do
- Use a clear label that explains what is being measured.
- Set a sensible
defaultUnitfor the most common case. - Choose the right
measurementTypeso the available units match the use case.
Don't
- Do not use Unit Field when the unit is fixed and never changes.
- Do not use it for non-measurement values such as counts or identifiers.
- Do not hide the meaning of the measurement behind a vague label.
Behavior
- Unit Field combines Number Field behavior with a unit selector.
- Changing the selected unit can convert the current value to keep the measurement consistent.
measurementTypecontrols which units are available, anddefaultUnitcontrols the current selection.
Accessibility
- Always provide a visible label so users understand what the measurement refers to.
- Make sure unit changes remain understandable, especially when the displayed numeric value updates after conversion.
- Use help text when users need guidance about accepted ranges or preferred units.
Related components
- Number Field: when the value is numeric and the unit is fixed or communicated elsewhere.