Skip to main content

Number field

A number with a unit, steppers and spinbutton keys.

<mm-number-field name="timeout" label="Query timeout" unit="ms" min="100" max="30000" step="100" value="500"></mm-number-field>

Guidance​

Number fields take a quantity: a retention period, a row limit, a timeout. Numbers are set in tabular figures and right-aligned so they line up with the tables they configure. An optional unit follows the number after a non-breaking space ("500 ms", "10,000 rows").

Keyboard follows the WAI-ARIA spinbutton pattern (https://www.w3.org/WAI/ARIA/apg/patterns/spinbutton/): ArrowUp and ArrowDown change the value by step, PageUp and PageDown by ten steps, Home and End jump to min and max when set. Steps count from step-base (default 0), not from min, so min="1" step="100" gives 1, 100, 200 and so on; min and max themselves are always valid. The stepper buttons are labelled for assistive technology and stay out of the tab order, since the arrow keys do the same job.

Form-associated: submits the number as text under name, validates required, min, max and step, resets with the form and is disabled by a disabled fieldset.

Properties​

PropertyAttributeTypeDefaultDescription
valuevaluestring''The current value as text, as it submits. The value attribute is the default the form resets to.
minminnumber | undefined
maxmaxnumber | undefined
stepstepnumber | undefinedStep for the arrow keys and steppers; PageUp and PageDown move ten steps. Default 1.
stepBasestep-basenumber | undefinedThe value the step grid counts from. Default 0, so steps stay round numbers whatever min is. Unlike a native number input, min is not the base.
unitunitstring''Unit shown after the number, such as ms or rows.
placeholderplaceholderstring''
readonlyreadonlybooleanfalse
noSteppersno-steppersbooleanfalseHides the stepper buttons; the arrow keys still work.
valueAsNumbernumberThe value as a number, or NaN when empty.
labellabelstring''Field label. Rendered above the control unless hide-label, and always the accessible name.
helphelpstring''Help text under the control.
errorerrorstring''Error text: a sentence saying what to fix. Shows the crimson border, an icon and sets aria-invalid.
hideLabelhide-labelbooleanfalseHides the label visually; it stays the accessible name.
optionaloptionalbooleanfalseMarks the field as optional, in words.
namenamestring''Name submitted with the form.
disableddisabledbooleanfalseDisables the control and excludes it from submission.
requiredrequiredbooleanfalseRequires a value before the form submits.
formHTMLFormElement | null
validityValidityState
validationMessagestring
willValidateboolean
isDisabledbooleanTrue when disabled directly or by a disabled ancestor fieldset.

Methods​

MethodDescription
formResetCallback()Restore the initial value when the owning form resets.
stepBy()Moves the value by n steps, clamped to min and max.

Events​

EventDetailDescription
mm-inputCustomEvent<MmValueDetail>On every edit and every step.
mm-changeCustomEvent<MmValueDetail>When the value is committed (blur after typing, or a step).
inputInputEventNative, composed; on every edit and step.
changeEventNative, re-dispatched on the host when the value is committed.

CSS parts​

PartDescription
labelThe label.
controlThe bordered box.
inputThe native number input.
unitThe unit suffix.
stepperEach stepper button.
helpThe help line.
errorThe error line.

Examples​

Every state of mm-number-field in Storybook, with keyboard and screen reader tests.