Numeric field with KtUI lifecycle on the native input[type=number], optional decrement/increment buttons, and custom events. Not the wizard Stepper—see Stepper for multi-step flows.
Examples
Basic
Initialize on a wrapper that contains one input[type="number"], or put data-kt-input-number on the input itself.
Use native min, max, and step on the number input. Optional + / − controls use the browser’s stepUp() / stepDown() so behavior matches native constraints.
If a wrapper contains more than one number input, the component binds to the first in tree order (avoid multiple fields per instance).
Optional buttons
Use kt-input-group so decrement/increment controls share one edge with the field and match the input height (items-stretch on the group). The group stylesheet squares the inner corners of outline buttons next to a kt-input (and removes their side shadow) so the join matches the addon pattern—no extra radius utilities on the minus button are required.
min, max, step, and value use the native attributes on input[type="number"].
Methods
Method
Description
new KTInputNumber(element, options?)
Creates an instance if markup includes a number input.
getNumberInput()
Returns the controlled HTMLInputElement or null.
getValue()
Parsed numeric value, or when empty / non-finite.
Static methods
Method
Description
KTInputNumber.init()
Initializes [data-kt-input-number] (except lazy).
KTInputNumber.createInstances()
Same discovery; safe to call after DOM updates.
KTInputNumber.getInstance(element)
Returns the instance on the root, or null.
KTInputNumber.init();const el = document.querySelector('[data-kt-input-number]');const num = KTInputNumber.getInstance(el);console.log(num?.getValue());
Events
Native input and change on the number control still fire. KtUI dispatches:
Event
When
event.detail.payload
kt.input-number.input
Native input
{ value, valueAsString, min?, max?, step? } — value is null when empty; step omitted when step="any".
Focus, spin buttons (where the browser provides them), and validation come from the nativeinput[type="number"]. Keep the real input in the tab order. When using custom + / − buttons, give each an aria-label (or visible text) and avoid disabling focus to the input unless the whole control is disabled.
TypeScript
import { KTInputNumber, type KTInputNumberConfigInterface, type KTInputNumberEventPayloadInterface, type KTInputNumberInterface,} from '@keenthemes/ktui';const root = document.querySelector<HTMLElement>('[data-kt-input-number]');if (!root) { throw new Error('missing root');}const widget: KTInputNumberInterface | null = KTInputNumber.getOrCreateInstance(root, {} satisfies KTInputNumberConfigInterface);if (widget) { const input = widget.