Number Input
Numeric text field with increment/decrement triggers and locale-aware formatting.
Number Input implements the WAI-ARIA APG Spinbutton pattern, providing keyboard stepping, Intl.NumberFormat formatting and parsing, clamping, and form reset support.
import { component$, useStyles$ } from '@builder.io/qwik';
import { NumberInput } from '@leve-ui/number-input';
import { LuMinus, LuPlus } from '@qwikest/icons/lucide';
import styles from './default.css?inline';
export default component$(() => {
useStyles$(styles);
return (
<NumberInput.Root defaultValue={1} class="number-input-default">
<NumberInput.DecrementTrigger
class="number-input-default-trigger"
aria-label="Decrement quantity"
>
<LuMinus class="number-input-default-icon" aria-hidden="true" />
</NumberInput.DecrementTrigger>
<NumberInput.Input class="number-input-default-input" aria-label="Quantity" />
<NumberInput.IncrementTrigger
class="number-input-default-trigger"
aria-label="Increment quantity"
>
<LuPlus class="number-input-default-icon" aria-hidden="true" />
</NumberInput.IncrementTrigger>
</NumberInput.Root>
);
});.number-input-default {
display: inline-flex;
align-items: center;
font-family: inherit;
}
.number-input-default-input {
box-sizing: border-box;
width: 72px;
height: 36px;
padding: 0 8px;
border-top: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-bottom: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-left: none;
border-right: none;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font-family: inherit;
font-size: 14px;
text-align: center;
}
.number-input-default-input:focus-visible {
outline: 2px solid #009dfd;
outline-offset: -1px;
z-index: 1;
}
.number-input-default-trigger {
box-sizing: border-box;
display: inline-flex;
align-items: center;
justify-content: center;
width: 36px;
height: 36px;
padding: 0;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
cursor: pointer;
}
.number-input-default-trigger[data-leve-number-input-decrement-trigger] {
border-radius: 6px 0 0 6px;
}
.number-input-default-trigger[data-leve-number-input-increment-trigger] {
border-radius: 0 6px 6px 0;
}
.number-input-default-trigger:hover:not(:disabled) {
background: light-dark(#f1f5f9, #ffffff14);
}
.number-input-default-trigger[data-disabled] {
opacity: 0.5;
cursor: not-allowed;
}
.number-input-default-icon {
width: 16px;
height: 16px;
}Installation#
Install the individual package, or use @leve-ui/core to get every component at once:
pnpm add @leve-ui/number-inputnpm install @leve-ui/number-inputyarn add @leve-ui/number-inputbun add @leve-ui/number-inputpnpm add @leve-ui/corenpm install @leve-ui/coreyarn add @leve-ui/corebun add @leve-ui/coreAnatomy#
import { NumberInput } from '@leve-ui/number-input'; // or '@leve-ui/core'
<NumberInput.Root>
<NumberInput.DecrementTrigger>-</NumberInput.DecrementTrigger>
<NumberInput.Input />
<NumberInput.IncrementTrigger>+</NumberInput.IncrementTrigger>
</NumberInput.Root>
| Part | Element | Description |
|---|---|---|
NumberInput.Root | <div> | Wraps the parts, manages the numeric state, and provides context. |
NumberInput.Input | <input> | Spinbutton text input (role="spinbutton", inputMode="decimal"). |
NumberInput.IncrementTrigger | <button> | Button (tabIndex={-1}) that increments the value by step. |
NumberInput.DecrementTrigger | <button> | Button (tabIndex={-1}) that decrements the value by step. |
Examples#
Controlled#
Control the numeric value with bind:value.
Value: 10
import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
import { NumberInput } from '@leve-ui/number-input';
import { LuChevronDown, LuChevronUp } from '@qwikest/icons/lucide';
import styles from './controlled.css?inline';
export default component$(() => {
useStyles$(styles);
const value = useSignal<number | null>(10);
return (
<div class="number-input-controlled-wrapper">
<NumberInput.Root bind:value={value} class="number-input-controlled">
<NumberInput.Input class="number-input-controlled-input" aria-label="Controlled number" />
<div class="number-input-controlled-triggers">
<NumberInput.IncrementTrigger
class="number-input-controlled-trigger"
aria-label="Increment"
>
<LuChevronUp class="number-input-controlled-icon" aria-hidden="true" />
</NumberInput.IncrementTrigger>
<NumberInput.DecrementTrigger
class="number-input-controlled-trigger"
aria-label="Decrement"
>
<LuChevronDown class="number-input-controlled-icon" aria-hidden="true" />
</NumberInput.DecrementTrigger>
</div>
</NumberInput.Root>
<p class="number-input-controlled-status">
Value: {value.value === null ? 'empty' : value.value}
</p>
</div>
);
});.number-input-controlled-wrapper {
display: flex;
flex-direction: column;
gap: 8px;
font-family: inherit;
}
.number-input-controlled {
display: inline-flex;
align-items: stretch;
width: 160px;
}
.number-input-controlled-input {
box-sizing: border-box;
flex: 1;
min-width: 0;
height: 36px;
padding: 0 10px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-right: none;
border-radius: 6px 0 0 6px;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font-family: inherit;
font-size: 14px;
}
.number-input-controlled-input:focus-visible {
outline: 2px solid #009dfd;
outline-offset: -1px;
z-index: 1;
}
.number-input-controlled-triggers {
box-sizing: border-box;
display: flex;
flex-direction: column;
width: 28px;
height: 36px;
}
.number-input-controlled-trigger {
box-sizing: border-box;
display: inline-flex;
align-items: center;
justify-content: center;
flex: 1;
padding: 0;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
cursor: pointer;
}
.number-input-controlled-trigger[data-leve-number-input-increment-trigger] {
border-bottom: none;
border-radius: 0 6px 0 0;
}
.number-input-controlled-trigger[data-leve-number-input-decrement-trigger] {
border-radius: 0 0 6px 0;
}
.number-input-controlled-trigger:hover:not(:disabled) {
background: light-dark(#f1f5f9, #ffffff14);
}
.number-input-controlled-trigger[data-disabled] {
opacity: 0.5;
cursor: not-allowed;
}
.number-input-controlled-icon {
width: 14px;
height: 14px;
}
.number-input-controlled-status {
margin: 0;
font-size: 13px;
color: light-dark(#475569, #c9ddf0);
}Min, Max, and Step#
Configure min, max, step, and largeStep (for PageUp / PageDown).
import { component$, useStyles$ } from '@builder.io/qwik';
import { NumberInput } from '@leve-ui/number-input';
import { LuMinus, LuPlus } from '@qwikest/icons/lucide';
import styles from './min-max-step.css?inline';
export default component$(() => {
useStyles$(styles);
return (
<NumberInput.Root
defaultValue={0}
min={-10}
max={10}
step={0.5}
largeStep={2}
class="number-input-min-max-step"
>
<NumberInput.DecrementTrigger
class="number-input-min-max-step-trigger"
aria-label="Decrement by 0.5"
>
<LuMinus class="number-input-min-max-step-icon" aria-hidden="true" />
</NumberInput.DecrementTrigger>
<NumberInput.Input class="number-input-min-max-step-input" aria-label="Offset (-10 to 10)" />
<NumberInput.IncrementTrigger
class="number-input-min-max-step-trigger"
aria-label="Increment by 0.5"
>
<LuPlus class="number-input-min-max-step-icon" aria-hidden="true" />
</NumberInput.IncrementTrigger>
</NumberInput.Root>
);
});.number-input-min-max-step {
display: inline-flex;
align-items: center;
font-family: inherit;
}
.number-input-min-max-step-input {
box-sizing: border-box;
width: 80px;
height: 36px;
padding: 0 8px;
border-top: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-bottom: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-left: none;
border-right: none;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font-family: inherit;
font-size: 14px;
text-align: center;
}
.number-input-min-max-step-input:focus-visible {
outline: 2px solid #009dfd;
outline-offset: -1px;
z-index: 1;
}
.number-input-min-max-step-trigger {
box-sizing: border-box;
display: inline-flex;
align-items: center;
justify-content: center;
width: 36px;
height: 36px;
padding: 0;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
cursor: pointer;
}
.number-input-min-max-step-trigger[data-leve-number-input-decrement-trigger] {
border-radius: 6px 0 0 6px;
}
.number-input-min-max-step-trigger[data-leve-number-input-increment-trigger] {
border-radius: 0 6px 6px 0;
}
.number-input-min-max-step-trigger:hover:not(:disabled) {
background: light-dark(#f1f5f9, #ffffff14);
}
.number-input-min-max-step-trigger[data-disabled] {
opacity: 0.5;
cursor: not-allowed;
}
.number-input-min-max-step-icon {
width: 16px;
height: 16px;
}Formatted#
Pass locale and formatOptions (such as currency or percentage) to format and parse numbers with Intl.NumberFormat.
import { component$, useStyles$ } from '@builder.io/qwik';
import { NumberInput } from '@leve-ui/number-input';
import { LuMinus, LuPlus } from '@qwikest/icons/lucide';
import styles from './formatted.css?inline';
export default component$(() => {
useStyles$(styles);
return (
<NumberInput.Root
defaultValue={1250}
min={0}
step={50}
locale="en-US"
formatOptions={{ style: 'currency', currency: 'USD' }}
class="number-input-formatted"
>
<NumberInput.DecrementTrigger
class="number-input-formatted-trigger"
aria-label="Decrease price"
>
<LuMinus class="number-input-formatted-icon" aria-hidden="true" />
</NumberInput.DecrementTrigger>
<NumberInput.Input class="number-input-formatted-input" aria-label="Price" />
<NumberInput.IncrementTrigger
class="number-input-formatted-trigger"
aria-label="Increase price"
>
<LuPlus class="number-input-formatted-icon" aria-hidden="true" />
</NumberInput.IncrementTrigger>
</NumberInput.Root>
);
});.number-input-formatted {
display: inline-flex;
align-items: center;
font-family: inherit;
}
.number-input-formatted-input {
box-sizing: border-box;
width: 120px;
height: 36px;
padding: 0 10px;
border-top: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-bottom: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-left: none;
border-right: none;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font-family: inherit;
font-size: 14px;
text-align: center;
}
.number-input-formatted-input:focus-visible {
outline: 2px solid #009dfd;
outline-offset: -1px;
z-index: 1;
}
.number-input-formatted-trigger {
box-sizing: border-box;
display: inline-flex;
align-items: center;
justify-content: center;
width: 36px;
height: 36px;
padding: 0;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
cursor: pointer;
}
.number-input-formatted-trigger[data-leve-number-input-decrement-trigger] {
border-radius: 6px 0 0 6px;
}
.number-input-formatted-trigger[data-leve-number-input-increment-trigger] {
border-radius: 0 6px 6px 0;
}
.number-input-formatted-trigger:hover:not(:disabled) {
background: light-dark(#f1f5f9, #ffffff14);
}
.number-input-formatted-trigger[data-disabled] {
opacity: 0.5;
cursor: not-allowed;
}
.number-input-formatted-icon {
width: 16px;
height: 16px;
}Disabled#
disabled on the Root disables both the input and the trigger buttons.
import { component$, useStyles$ } from '@builder.io/qwik';
import { NumberInput } from '@leve-ui/number-input';
import { LuMinus, LuPlus } from '@qwikest/icons/lucide';
import styles from './disabled.css?inline';
export default component$(() => {
useStyles$(styles);
return (
<NumberInput.Root defaultValue={5} disabled class="number-input-disabled">
<NumberInput.DecrementTrigger class="number-input-disabled-trigger" aria-label="Decrement">
<LuMinus class="number-input-disabled-icon" aria-hidden="true" />
</NumberInput.DecrementTrigger>
<NumberInput.Input class="number-input-disabled-input" aria-label="Disabled quantity" />
<NumberInput.IncrementTrigger class="number-input-disabled-trigger" aria-label="Increment">
<LuPlus class="number-input-disabled-icon" aria-hidden="true" />
</NumberInput.IncrementTrigger>
</NumberInput.Root>
);
});.number-input-disabled {
display: inline-flex;
align-items: center;
font-family: inherit;
}
.number-input-disabled-input {
box-sizing: border-box;
width: 72px;
height: 36px;
padding: 0 8px;
border-top: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-bottom: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-left: none;
border-right: none;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font-family: inherit;
font-size: 14px;
text-align: center;
}
.number-input-disabled-input[data-disabled] {
opacity: 0.5;
cursor: not-allowed;
}
.number-input-disabled-trigger {
box-sizing: border-box;
display: inline-flex;
align-items: center;
justify-content: center;
width: 36px;
height: 36px;
padding: 0;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
cursor: pointer;
}
.number-input-disabled-trigger[data-leve-number-input-decrement-trigger] {
border-radius: 6px 0 0 6px;
}
.number-input-disabled-trigger[data-leve-number-input-increment-trigger] {
border-radius: 0 6px 6px 0;
}
.number-input-disabled-trigger[data-disabled] {
opacity: 0.5;
cursor: not-allowed;
}
.number-input-disabled-icon {
width: 16px;
height: 16px;
}Read Only#
readOnly prevents editing and stepping while keeping the input focusable.
import { component$, useStyles$ } from '@builder.io/qwik';
import { NumberInput } from '@leve-ui/number-input';
import { LuMinus, LuPlus } from '@qwikest/icons/lucide';
import styles from './read-only.css?inline';
export default component$(() => {
useStyles$(styles);
return (
<NumberInput.Root defaultValue={42} readOnly class="number-input-read-only">
<NumberInput.DecrementTrigger class="number-input-read-only-trigger" aria-label="Decrement">
<LuMinus class="number-input-read-only-icon" aria-hidden="true" />
</NumberInput.DecrementTrigger>
<NumberInput.Input class="number-input-read-only-input" aria-label="Read-only value" />
<NumberInput.IncrementTrigger class="number-input-read-only-trigger" aria-label="Increment">
<LuPlus class="number-input-read-only-icon" aria-hidden="true" />
</NumberInput.IncrementTrigger>
</NumberInput.Root>
);
});.number-input-read-only {
display: inline-flex;
align-items: center;
font-family: inherit;
}
.number-input-read-only-input {
box-sizing: border-box;
width: 72px;
height: 36px;
padding: 0 8px;
border-top: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-bottom: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-left: none;
border-right: none;
background: light-dark(#f1f5f9, #ffffff14);
color: light-dark(#0f172a, #ffffff);
font-family: inherit;
font-size: 14px;
text-align: center;
}
.number-input-read-only-input:focus-visible {
outline: 2px solid #009dfd;
outline-offset: -1px;
z-index: 1;
}
.number-input-read-only-trigger {
box-sizing: border-box;
display: inline-flex;
align-items: center;
justify-content: center;
width: 36px;
height: 36px;
padding: 0;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
cursor: pointer;
}
.number-input-read-only-trigger[data-leve-number-input-decrement-trigger] {
border-radius: 6px 0 0 6px;
}
.number-input-read-only-trigger[data-leve-number-input-increment-trigger] {
border-radius: 0 6px 6px 0;
}
.number-input-read-only-trigger[data-disabled] {
opacity: 0.5;
cursor: not-allowed;
}
.number-input-read-only-icon {
width: 16px;
height: 16px;
}With Field#
Inside a Field.Root, Field.Label, Field.Description, Field.ErrorMessage, and the disabled / readOnly / required / invalid states are wired automatically.
import { component$, useStyles$ } from '@builder.io/qwik';
import { Field } from '@leve-ui/field';
import { NumberInput } from '@leve-ui/number-input';
import { LuMinus, LuPlus } from '@qwikest/icons/lucide';
import styles from './with-field.css?inline';
export default component$(() => {
useStyles$(styles);
return (
<Field.Root class="number-input-with-field" hasDescription invalid required>
<Field.Label class="number-input-with-field-label">
Seat count
<Field.RequiredIndicator class="number-input-with-field-required">
*
</Field.RequiredIndicator>
</Field.Label>
<NumberInput.Root defaultValue={0} min={1} max={10} class="number-input-with-field-control">
<NumberInput.DecrementTrigger
class="number-input-with-field-trigger"
aria-label="Decrement seats"
>
<LuMinus class="number-input-with-field-icon" aria-hidden="true" />
</NumberInput.DecrementTrigger>
<NumberInput.Input class="number-input-with-field-input" />
<NumberInput.IncrementTrigger
class="number-input-with-field-trigger"
aria-label="Increment seats"
>
<LuPlus class="number-input-with-field-icon" aria-hidden="true" />
</NumberInput.IncrementTrigger>
</NumberInput.Root>
<Field.Description class="number-input-with-field-description">
Choose between 1 and 10 seats.
</Field.Description>
<Field.ErrorMessage class="number-input-with-field-error">
Please select at least 1 seat.
</Field.ErrorMessage>
</Field.Root>
);
});.number-input-with-field {
display: flex;
flex-direction: column;
gap: 6px;
font-family: inherit;
}
.number-input-with-field-label {
font-size: 14px;
font-weight: 500;
color: light-dark(#0f172a, #ffffff);
}
.number-input-with-field-required {
margin-left: 2px;
color: light-dark(#dc2626, #f87171);
}
.number-input-with-field-control {
display: inline-flex;
align-items: center;
}
.number-input-with-field-input {
box-sizing: border-box;
width: 72px;
height: 36px;
padding: 0 8px;
border-top: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-bottom: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-left: none;
border-right: none;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font-family: inherit;
font-size: 14px;
text-align: center;
}
.number-input-with-field-input[data-invalid] {
border-color: light-dark(#dc2626, #f87171);
}
.number-input-with-field-input:focus-visible {
outline: 2px solid #009dfd;
outline-offset: -1px;
z-index: 1;
}
.number-input-with-field-trigger {
box-sizing: border-box;
display: inline-flex;
align-items: center;
justify-content: center;
width: 36px;
height: 36px;
padding: 0;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
cursor: pointer;
}
.number-input-with-field-trigger[data-leve-number-input-decrement-trigger] {
border-radius: 6px 0 0 6px;
}
.number-input-with-field-trigger[data-leve-number-input-increment-trigger] {
border-radius: 0 6px 6px 0;
}
.number-input-with-field-trigger:hover:not(:disabled) {
background: light-dark(#f1f5f9, #ffffff14);
}
.number-input-with-field-trigger[data-disabled] {
opacity: 0.5;
cursor: not-allowed;
}
.number-input-with-field-icon {
width: 16px;
height: 16px;
}
.number-input-with-field-description {
margin: 0;
font-size: 13px;
color: light-dark(#475569, #c9ddf0);
}
.number-input-with-field-error {
margin: 0;
font-size: 13px;
color: light-dark(#dc2626, #f87171);
}With Form#
Works with native <form> submission and resets to defaultValue on <form> reset.
import { $, component$, useSignal, useStyles$ } from '@builder.io/qwik';
import { NumberInput } from '@leve-ui/number-input';
import { LuMinus, LuPlus } from '@qwikest/icons/lucide';
import styles from './with-form.css?inline';
export default component$(() => {
useStyles$(styles);
const submitted = useSignal<string>('None');
return (
<div class="number-input-with-form-wrapper">
<form
class="number-input-with-form"
preventdefault:submit
onSubmit$={$((_, form) => {
const data = new FormData(form);
submitted.value = String(data.get('quantity') ?? '');
})}
>
<NumberInput.Root defaultValue={3} min={1} max={10} class="number-input-with-form-control">
<NumberInput.DecrementTrigger
class="number-input-with-form-trigger"
aria-label="Decrement quantity"
>
<LuMinus class="number-input-with-form-icon" aria-hidden="true" />
</NumberInput.DecrementTrigger>
<NumberInput.Input
name="quantity"
class="number-input-with-form-input"
aria-label="Quantity"
/>
<NumberInput.IncrementTrigger
class="number-input-with-form-trigger"
aria-label="Increment quantity"
>
<LuPlus class="number-input-with-form-icon" aria-hidden="true" />
</NumberInput.IncrementTrigger>
</NumberInput.Root>
<div class="number-input-with-form-actions">
<button type="submit" class="number-input-with-form-button">
Submit
</button>
<button type="reset" class="number-input-with-form-button-secondary">
Reset
</button>
</div>
</form>
<output class="number-input-with-form-output">Submitted: {submitted.value}</output>
</div>
);
});.number-input-with-form-wrapper {
display: flex;
flex-direction: column;
gap: 10px;
font-family: inherit;
}
.number-input-with-form {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 10px;
}
.number-input-with-form-control {
display: inline-flex;
align-items: center;
}
.number-input-with-form-input {
box-sizing: border-box;
width: 72px;
height: 36px;
padding: 0 8px;
border-top: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-bottom: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-left: none;
border-right: none;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font-family: inherit;
font-size: 14px;
text-align: center;
}
.number-input-with-form-input:focus-visible {
outline: 2px solid #009dfd;
outline-offset: -1px;
z-index: 1;
}
.number-input-with-form-trigger {
box-sizing: border-box;
display: inline-flex;
align-items: center;
justify-content: center;
width: 36px;
height: 36px;
padding: 0;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
cursor: pointer;
}
.number-input-with-form-trigger[data-leve-number-input-decrement-trigger] {
border-radius: 6px 0 0 6px;
}
.number-input-with-form-trigger[data-leve-number-input-increment-trigger] {
border-radius: 0 6px 6px 0;
}
.number-input-with-form-trigger:hover:not(:disabled) {
background: light-dark(#f1f5f9, #ffffff14);
}
.number-input-with-form-trigger[data-disabled] {
opacity: 0.5;
cursor: not-allowed;
}
.number-input-with-form-icon {
width: 16px;
height: 16px;
}
.number-input-with-form-actions {
display: flex;
gap: 8px;
}
.number-input-with-form-button {
height: 32px;
padding: 0 12px;
border: none;
border-radius: 6px;
background: #009dfd;
color: #ffffff;
font-family: inherit;
font-size: 13px;
cursor: pointer;
}
.number-input-with-form-button:hover {
background: #006ce9;
}
.number-input-with-form-button-secondary {
height: 32px;
padding: 0 12px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 6px;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font-family: inherit;
font-size: 13px;
cursor: pointer;
}
.number-input-with-form-button-secondary:hover {
background: light-dark(#f1f5f9, #ffffff14);
}
.number-input-with-form-output {
font-size: 13px;
color: light-dark(#475569, #c9ddf0);
}API Reference#
Root#
| Prop | Default | Type |
|---|---|---|
| ids | – | { input?: string } Overrides the element IDs of the parts. Only used outside a Field. |
| defaultValue | null | number | null The initial numeric value (uncontrolled). |
| bind:value | – | Signal<number | null> A signal with the numeric value (controlled). |
| onValueChange$ | – | QRL<(value: number | null) => void> Called when the numeric value changes. |
| min | – | number Minimum allowed value. |
| max | – | number Maximum allowed value. |
| step | 1 | number Amount to increment or decrement on ArrowUp / ArrowDown or trigger click. |
| largeStep | step * 10 | number Amount to increment or decrement on PageUp / PageDown. |
| locale | 'en-US' | string BCP 47 locale tag used by |
| formatOptions | – | Intl.NumberFormatOptions Formatting options passed to |
| clampValueOnBlur | true | boolean Whether to clamp out-of-range typed values to |
| disabled | false | boolean Disables the input and trigger buttons. Inside a Field or Fieldset, inherited |
| readOnly | false | boolean Marks the number input as read-only. Inside a Field, the Field's |
| required | false | boolean Marks the number input as required. Inside a Field, the Field's |
| invalid | false | boolean Marks the number input as invalid. Inside a Field, the Field's |
Also accepts all <div> attributes.
| Data attribute | Value |
|---|---|
data-leve-number-input | Always present |
data-state | "empty" | "filled" |
data-disabled | Present when disabled |
data-readonly | Present when read-only |
data-invalid | Present when invalid |
The numeric value is uncontrolled with defaultValue, or controlled with bind:value. onValueChange$ is called when the committed value changes.
Inside a Field, the input ID comes from the Field and ids is ignored (ADR 0024).
Input#
No props of its own. Accepts all <input> attributes.
| Data attribute | Value |
|---|---|
data-leve-number-input-input | Always present |
data-state | "empty" | "filled" |
data-disabled | Present when disabled |
data-readonly | Present when read-only |
data-invalid | Present when invalid |
IncrementTrigger#
No props of its own. Accepts all <button> attributes.
| Data attribute | Value |
|---|---|
data-leve-number-input-increment-trigger | Always present |
data-disabled | Present when disabled, read-only, or at max |
DecrementTrigger#
No props of its own. Accepts all <button> attributes.
| Data attribute | Value |
|---|---|
data-leve-number-input-decrement-trigger | Always present |
data-disabled | Present when disabled, read-only, or at min |
Accessibility#
Follows the WAI-ARIA APG Spinbutton pattern.
- Provide an accessible name for
NumberInput.InputviaField.Label,aria-label, oraria-labelledby. NumberInput.Inputsetsrole="spinbutton",aria-valuenow,aria-valuemin,aria-valuemax, andaria-valuetext(when the formatted text differs from the plain number string).IncrementTriggerandDecrementTriggerare excluded from the tab order (tabIndex={-1}) and preventmousedowndefault so clicking them keeps focus on the input. They defaultaria-labelto"Increment"and"Decrement".
Keyboard Interactions#
| Key | Description |
|---|---|
ArrowUp | Increments the value by step. |
ArrowDown | Decrements the value by step. |
PageUp | Increments the value by largeStep. |
PageDown | Decrements the value by largeStep. |
Home | Sets the value to min (when min is defined). |
End | Sets the value to max (when max is defined). |
Enter | Parses, clamps (if clampValueOnBlur is true), commits, and formats the input value. |