Skip to the content
Konstruktor UI

Actions and inputs

Number

A native <input type="number"> inside <kui-number>, which adds a decrease and an increase button around it. For a count a person changes by a few steps: guests, nights, copies.

<kui-number> needs kui.js; the markup works without it as described below

Examples

A count with steppers

The buttons are disabled at min and max. Their names come from the kit’s words and the field’s label: “Decrease: Guests”. Each press is announced.

From 1 to 12 people.

HTML
<div class="kui-field">
  <label class="kui-label" for="number-guests">Guests</label>
  <kui-number class="kui-number">
    <input class="kui-input" id="number-guests" name="guests" type="number" min="1" max="12" step="1" value="2" aria-describedby="number-guests-hint">
  </kui-number>
  <p class="kui-hint" id="number-guests-hint">From 1 to 12 people.</p>
</div>

Decimal steps

With a decimal step the element sets inputmode="decimal", so a phone shows the keyboard with a decimal separator.

HTML
<div class="kui-field">
  <label class="kui-label" for="number-hours">Hours worked on Thursday</label>
  <kui-number class="kui-number">
    <input class="kui-input" id="number-hours" name="hours" type="number" min="0" max="16" step="0.5" value="7.5">
  </kui-number>
</div>

Without JavaScript

Before the kit loads, or without it, the field is the browser’s own number input. It still has its arrow keys and submits the same value.

HTML
<div class="kui-field">
  <label class="kui-label" for="number-copies">Copies</label>
  <div class="kui-number"><input class="kui-input" id="number-copies" type="number" min="1" max="99" value="1"></div>
</div>

States

Every state

Hover darkens a button; keyboard focus shows the ring on the field or on the button. At the minimum the decrease button is disabled. A disabled or read-only field disables both buttons. An invalid value has its message under the field.

Choose at most 12 guests.

HTML
<div class="kui-form kui-form--wide">
<div class="kui-form__row">
  <div class="kui-field"><label class="kui-label" for="number-s1">At the minimum</label><kui-number class="kui-number"><input class="kui-input" id="number-s1" type="number" min="0" max="10" value="0"></kui-number></div>
  <div class="kui-field"><label class="kui-label" for="number-s2">Empty</label><kui-number class="kui-number"><input class="kui-input" id="number-s2" type="number" min="1" max="10" placeholder="–"></kui-number></div>
  <div class="kui-field"><label class="kui-label" for="number-s3">Disabled</label><kui-number class="kui-number"><input class="kui-input" id="number-s3" type="number" value="4" disabled></kui-number></div>
  <div class="kui-field"><label class="kui-label" for="number-s4">Read only</label><kui-number class="kui-number"><input class="kui-input" id="number-s4" type="number" value="3" readonly></kui-number></div>
  <div class="kui-field"><label class="kui-label" for="number-s5">Invalid</label><kui-number class="kui-number"><input class="kui-input" id="number-s5" type="number" min="1" max="12" value="14" aria-invalid="true" aria-describedby="number-s5-e"></kui-number><p class="kui-error-text" id="number-s5-e"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#circle-alert"></use></svg><span>Choose at most 12 guests.</span></p></div>
</div>
</div>

Classes and attributes

kui-number.kui-number
Wraps one input type="number" and adds the two buttons. Give it the class too, so the layout is right before the script runs.
input min, max, step
The limits and the step. The buttons stop at the limits; the field keeps the browser’s own checks for the form.
.kui-number__step
A decrease or increase button, made by the element.
events input, change
Fired on the input after every button press or key, as if the person had typed.

Keyboard

Up or Down
One step up or down (the browser’s own keys).
Page Up or Page Down
Ten steps up or down.
Home or End
To the minimum or the maximum, when they are set.
Tab
From the decrease button to the field to the increase button.

Accessibility

  • The input keeps its native spin button role, so a screen reader reads its value, minimum and maximum.
  • The two buttons are labelled with the action and the field’s name, and they point to the field with aria-controls.
  • Each press is announced in a polite live region, because focus stays on the button.
  • Every button is at least 44 by 44 pixels on a phone.

Do and do not

Do

  • Use it for small whole numbers that a person changes by a step or two.
  • Set min and max, and say them in the hint.
  • Keep the field as narrow as its largest value.

Do not

  • Do not use it for numbers that are not quantities: a postcode, a card number or a phone number is a text field with inputmode="numeric".
  • Do not use it for amounts of money with many digits; use a text field with a unit.
  • Do not hide the field and leave only the buttons.