Data input

Number Input

A number input with − and + buttons that step its value within its minimum and maximum.

Class nameTypeDescription
joinplf:joinComponentJoins the input and its buttons
join-itemplf:join-itemPartThe input and each button

Disabled and read-only

The script disables the buttons of a disabled or readonly input; a read-only value still submits.

JavaScript

The − and + buttons need JavaScript, so author them hidden; without it the native input still steps with its arrow keys. The Full script (pelatform-ui.min.js) starts every component on page load, with no code of your own; with ESM imports, call init() yourself, as in Installation. For markup you add later, see Dynamic content.

<link rel="stylesheet" href="pelatform-ui.min.css">
<link rel="stylesheet" href="icons/icons.min.css">
<script src="pelatform-ui.min.js" defer></script>
<link rel="stylesheet" href="pelatform-ui.prefixed.min.css">
<link rel="stylesheet" href="icons/icons.prefixed.min.css">
<script src="pelatform-ui.min.js" defer></script>
Attribute Purpose
data-plf-decrement, data-plf-increment On a button beside one <input type="number">: steps its value down or up within the input’s min, max and step, then sends input and change. The script shows the button, takes it out of the Tab order and disables it at the limit and while the input is disabled or read-only. Named Decrease or Increase unless it has a name; in a form, write type="button" so it does not submit
min, max, step On the input, natively; step="any" cannot be stepped by a button
Method Behavior
PLF.NumberInput.getOrCreateInstance(button) Returns the button’s instance, creating it for valid markup
PLF.NumberInput.getInstance(button) Returns the instance or null
instance.destroy() Removes listeners and what the script added, so the button is hidden again; the input keeps its value

With ESM, import NumberInput from @pelatform/ui/components/number-input. Number Input fires no events of its own: listen to the input’s native input and change. After setting the value in code, dispatch an input event so the buttons follow.

Keyboard

Key Action
Tab, Shift+Tab Move to and from the input; the buttons are not tab stops
Arrow Up, Arrow Down Step the value, natively
Digits Type a value, natively

React

NumberInput from @pelatform/react renders the input with its − and + buttons, which step the value as the script’s do; inside a Field the input takes the field’s label, help and error.

Prop Values Default
size sm, lg, for the input and its buttons The default size
buttons after, around (the − button before the input) after
value A number, or null when empty, which the application changes in onValueChange Its own state
defaultValue The number it starts with when the application does not set value Empty
onValueChange (value), called with the number, or null when empty, when typing or a button changes it None
decrementLabel The − button’s name Decrease
incrementLabel The + button’s name Increase

The other props are the native input’s, className and ref included; step is a number, and a button’s step reaches onChange as typing does.

CSS variables

The input takes Input’s variables and the buttons Button’s; joined to the input, an outline button’s border follows --plf-input-border.


Built with Pelatform UIv0.1.0

Components

Getting started

Foundations

Components

Actions

Data display

Navigation

Feedback

Data input

Layout

Advanced

Integrations

Blocks

Application

Authentication

Icons