InputNumber
Numeric input with range, step and formatting.
When to use
InputNumber is needed for quantity, price, percentage and other numeric quantities to which step, range or calculations are applied. For phone, article and other identifier, use Input: the numbers in the entry do not make it a number.
Provide a label and clear units of measurement. prefix and suffix place them inside the field; SpaceCompact and SpaceAddon allow you to add an external signature or action. In Form, the model rules check the value regardless of the field's design.
CSS prefixes InputNumber show global ConfigProvider.prefixCls and local prefixCls without resetting state. The styles of options, paddings, and control buttons follow prefixCls. The topic namespace and Compact common variables are independent; the value and incomplete input are saved.
Value and accuracy of
Link the model via bind:value or pass value with onValueChange. Emptiness and zero are different states:
| State | Model value | Example |
|---|---|---|
| Zero | 0 |
Basic input |
| Cleared field | null |
Numbers in the form |
| Exact decimal value | string in stringMode |
Exact decimal strings |
For stringMode, use string values, bounds, and stride. Do not convert the result using Number if you want to maintain precision. Normal mode returns number or null, string mode returns string or null; example changes the number in steps less than the precision of a regular number.
defaultValue specifies the initial content. The external update value controls the model and is not considered a custom onChange. Check for emptiness through value === null so as not to lose zero.
Enter, step and confirm
While typing, the displayed string may not be complete. Completed input is able to update the model immediately; Enter and, by default, blur normalize the draft, taking into account range and precision. changeOnBlur=false saves the draft when leaving the field, but does not defer all model changes until Enter. Confirmation example shows the difference.
min and max limit normalization of user input. The outer model can contain a value beyond their boundaries, and changing boundaries does not automatically trigger onChange. Range separates external recording from user actions.
step sets the increment, precision sets the normalization accuracy. keyboard controls the arrows, controls controls the step buttons; one does not replace the other. mode='spinner' places buttons on the sides of the value. Keyboard and spinner show these variations.
The wheel controls the value only when changeOnWheel is enabled and the focus is in the field. Native numeric input may have its own wheel behavior, so don't add type="number" for the sake of limiting the input. Wheel example enables the action explicitly.
Formatting and Form
formatter is responsible for display, parser is responsible for restoring the numeric record. Check them together: the place separators, currency sign, and decimal separator should not turn into a random model value. During typing, the formatter receives userTyping and the original input to save the draft. Amount and interest store numbers regardless of design.
DOM blur event contains the display string, including the formatter. For calculations, use the model or onValueChange/onChange; onInput reports the original input string. decimalSeparator changes the display, not the data type.
In Form, pass the model value and update it via callback. Order calculation checks quantity and price, sends numbers and restores defaults. Native FormData contains strings; The component does not automatically convert the form into an application format.
Examples
Basic input
bind:value binds a number to the Svelte model. Zero is stored as a number, an empty field returns null.
<script lang="ts">
import { InputNumber } from '@woodger/antd';
let value = $state<number | null>(3);
</script>
<style>
.example {
display: grid;
gap: 16px;
}
output { color: var(--ant-color-text-secondary); }
</style>
<div class="example">
<InputNumber
bind:value
min={0}
max={10}
aria-label={("Basic InputNumber")}
style="width:100%"
/>
<output aria-label={("InputNumber value")}>{(value === null ? "null - field is empty" : `number: ${value}`)}</output>
</div>
Three sizes
large, medium and small. Without local size, the ConfigProvider or SpaceCompact setting is valid.
<script lang="ts">
import { InputNumber } from '@woodger/antd';
</script>
<style>
.example {
display: grid;
gap: 20px;
}
</style>
<div class="example">
<InputNumber
size="large"
defaultValue={3}
aria-label={("Large InputNumber")}
style="width:100%"
/>
<InputNumber
size="medium"
defaultValue={3}
aria-label={("Normal InputNumber")}
style="width:100%"
/>
<InputNumber
size="small"
defaultValue={3}
aria-label={("Small InputNumber")}
style="width:100%"
/>
</div>
Accessibility and reading
disabled disables interaction. readOnly retains the ability to focus the field and highlight the value.
<script lang="ts">
import { Button, InputNumber } from '@woodger/antd';
let disabled = $state(true);
</script>
<style>
.example {
display: grid;
gap: 20px;
justify-items: start;
}
</style>
<div class="example">
<InputNumber
{disabled}
defaultValue={3}
aria-label={("Availability InputNumber")}
style="width:100%"
/>
<Button type="primary" onclick={() => { disabled = !disabled; }}>
{(disabled ? "Allow input" : "Disable input")}
</Button>
<InputNumber readOnly defaultValue={12.5} aria-label={("InputNumber read-only")} style="width:100%" />
</div>
Exact decimal strings
stringMode stores the decimal value as a string, including a step less than the precision of a regular number.
<script lang="ts">
import { InputNumber } from '@woodger/antd';
let value = $state<string | null>('1');
</script>
<style>
.example {
display: grid;
gap: 16px;
}
output {
color: var(--ant-color-text-secondary);
overflow-wrap: anywhere;
}
</style>
<div class="example">
<InputNumber bind:value stringMode min="0" max="10" step="0.00000000000001"
aria-label={("Exact decimal value")} style="width:100%" />
<output aria-label={("stringMode value")}>{(value === null ? 'null' : `string: ${value}`)}</output>
</div>
Formatting
formatter changes the display of the amount and percentage, parser restores the number. The model stores a number or null.
<script lang="ts">
import { InputNumber, type InputNumberProps } from '@woodger/antd';
let amount = $state<number | null>(1000);
let percent = $state<number | null>(25);
const formatAmount: InputNumberProps['formatter'] = (value, info) => {
if (info.userTyping) {
return info.input;
}
if (value === undefined || value === '') {
return '';
}
const [whole, fraction] = String(value).split('.');
return `${whole.replace(/\B(?=(\d{3})+(?!\d))/g, ' ')}${fraction ? `.${fraction}` : ''} ₽`;
};
const parseAmount: InputNumberProps['parser'] = value => (value ?? '').replace(/[\s₽]/g, '');
const formatPercent: InputNumberProps['formatter'] = (value, info) => {
if (info.userTyping) {
return info.input;
}
return value === undefined || value === '' ? '' : `${value}%`;
};
</script>
<style>
.example {
display: grid;
gap: 20px;
}
output {
color: var(--ant-color-text-secondary);
overflow-wrap: anywhere;
}
</style>
<div class="example">
<InputNumber bind:value={amount} formatter={formatAmount} parser={parseAmount}
aria-label={("Amount with formatting")} style="width:100%" />
<InputNumber bind:value={percent} min={0} max={100}
formatter={formatPercent}
parser={value => (value ?? '').replace('%', '')}
aria-label={("Percentage with formatting")} style="width:100%" />
<output
aria-label={("Numeric formatting values")}
>{("Amount: ")}{(amount ?? 'null')}{("; percentage: ")}{(percent ?? 'null')}</output>
</div>
Keyboard and buttons
keyboard controls the keyboard arrows, controls controls the buttons. onStep reports the direction and source of the step.
<script lang="ts">
import { Checkbox, InputNumber, type InputNumberProps } from '@woodger/antd';
let keyboard = $state(true);
let controls = $state(true);
let value = $state<number | null>(3);
let result = $state(("Step not completed yet"));
const onStep: InputNumberProps['onStep'] = (next, info) => {
result = ("" + String((info.emitter)) + ": " + String((info.type)) + ", value " + String((next)) + "");
};
</script>
<style>
.example {
display: grid;
gap: 16px;
}
.options {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
output { color: var(--ant-color-text-secondary); }
</style>
<div class="example">
<InputNumber bind:value min={0} max={10} {keyboard} {controls} {onStep}
aria-label={("Keyboard Step")} style="width:100%" />
<div class="options">
<Checkbox bind:checked={keyboard}>{("Keyboard arrows")}</Checkbox>
<Checkbox bind:checked={controls}>{("Step Buttons")}</Checkbox>
</div>
<output aria-label={("Step source")}>{result}</output>
</div>
Mouse wheel
changeOnWheel allows wheel changes only for the field with focus. In the example, the action is enabled explicitly.
<script lang="ts">
import { Checkbox, InputNumber } from '@woodger/antd';
let enabled = $state(false);
let value = $state<number | null>(3);
let result = $state(("Step not completed yet"));
</script>
<style>
.example {
display: grid;
gap: 16px;
}
output { color: var(--ant-color-text-secondary); }
</style>
<div class="example">
<Checkbox bind:checked={enabled}>{("Change with mouse wheel")}</Checkbox>
<InputNumber bind:value min={0} max={10} changeOnWheel={enabled}
aria-label={("Mouse wheel step")} style="width:100%"
onStep={(next, info) => { result = ("" + String((info.emitter)) + ": " + String((next)) + ""); }} />
<output aria-label={("Wheel result")}>{result}</output>
</div>
Design options
outlined, filled, borderless and underlined are specified via variant.
<script lang="ts">
import { InputNumber, type InputVariant } from '@woodger/antd';
const variants = ['outlined', 'filled', 'borderless', 'underlined'] satisfies InputVariant[];
</script>
<style>
.example {
display: grid;
gap: 20px;
}
</style>
<div class="example">
{#each variants as variant (variant)}
<InputNumber {variant} defaultValue={3} aria-label={("InputNumber " + String((variant)) + "")} style="width:100%" />
{/each}
</div>
Spinner mode
mode="spinner" places the buttons on the sides of the value. controls allows you to replace their icons.
<script lang="ts">
import { InputNumber } from '@woodger/antd';
</script>
<style>
.example {
display: grid;
gap: 20px;
}
</style>
<div class="example">
<InputNumber mode="spinner" min={0} max={10} defaultValue={3}
aria-label={("Spinner InputNumber")} style="width:100%" />
<InputNumber mode="spinner" min={0} max={10} defaultValue={3} variant="filled"
controls={{ upIcon: '+', downIcon: '−' }}
aria-label={("Spinner with its own buttons")} style="width:100%" />
</div>
Value out of range
External value and bounds changes do not by themselves trigger onChange. User input normalization takes into account min and max.
<script lang="ts">
import { Button, InputNumber } from '@woodger/antd';
let value = $state<number | null>(99);
let max = $state(10);
let changes = $state(0);
</script>
<style>
.example {
display: grid;
gap: 16px;
}
.actions {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
output { color: var(--ant-color-text-secondary); }
</style>
<div class="example">
<InputNumber
bind:value
min={0}
{max}
aria-label={("Value out of range")}
style="width:100%"
onChange={() => { changes += 1; }}
/>
<div class="actions">
<Button onclick={() => { value = 99; }}>{("Set 99")}</Button>
<Button onclick={() => { max = max === 10 ? 5 : 10; }}>{("Maximum ")}{(max === 10 ? 5 : 10)}</Button>
</div>
<output
aria-label={("InputNumber Range")}
>0…{max}{("; meaning: ")}{(value ?? 'null')}; onChange: {changes}</output>
</div>
prefix and suffix
In-field additions and composition with SpaceCompact / SpaceAddon.
<script lang="ts">
import { InputNumber, SpaceAddon, SpaceCompact } from '@woodger/antd';
</script>
<style>
.example {
display: grid;
gap: 20px;
}
</style>
{#snippet addon()}<SpaceAddon>{("Price")}</SpaceAddon>{/snippet}
{#snippet amount()}
<InputNumber prefix="₽" defaultValue={100} aria-label={("Price in group")} style="
flex: 1;
min-width: 0;
" />
{/snippet}
<div class="example">
<InputNumber
prefix="₽"
defaultValue={100}
aria-label={("Number with prefix")}
style="width:100%"
/>
<SpaceCompact block items={([addon, amount])} />
<InputNumber prefix="₽" disabled defaultValue={100} aria-label={("Unavailable number with prefix")} style="width:100%" />
<InputNumber
suffix="RUB"
defaultValue={100}
aria-label={("Number with suffix")}
style="width:100%"
/>
</div>
Error and warning
status highlights an error or warning, including the presence of a prefix and suffix.
<script lang="ts">
import { InputNumber } from '@woodger/antd';
</script>
<style>
.example {
display: grid;
gap: 20px;
}
</style>
<div class="example">
<InputNumber
status="error"
aria-label={("InputNumber with error")}
placeholder={("Error")}
style="width:100%"
/>
<InputNumber
status="warning"
aria-label={("InputNumber with warning")}
placeholder={("Warning")}
style="width:100%"
/>
<InputNumber
status="error"
prefix="₽"
aria-label={("Error with prefix")}
style="width:100%"
/>
<InputNumber
status="warning"
suffix="RUB"
aria-label={("Warning with suffix")}
style="width:100%"
/>
</div>
Focus and highlighting
Through bind:this, focus() with selecting the cursor position and blur() are available.
<script lang="ts">
import { Button, InputNumber } from '@woodger/antd';
let value = $state<number | null>(12345);
let control = $state<InputNumber>();
</script>
<style>
.example {
display: grid;
gap: 20px;
}
.actions {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
</style>
<div class="example">
<div class="actions">
<Button
onclick={() => control?.focus({ cursor: 'start' })}
>{("To the beginning of the number")}</Button>
<Button
onclick={() => control?.focus({ cursor: 'end' })}
>{("To the end of the number")}</Button>
<Button
onclick={() => control?.focus({ cursor: 'all' })}
>{("Select number")}</Button>
<Button onclick={() => control?.focus({ preventScroll: true })}>
{("Focus without scrolling")}
</Button>
</div>
<InputNumber
bind:this={control}
bind:value
aria-label={("Focus InputNumber")}
style="width:100%"
/>
</div>
Semantic styles
classNames and styles style internal elements: an object or function from { props }.
<script lang="ts">
import { InputNumber, type InputNumberProps } from '@woodger/antd';
const styles: InputNumberProps['styles'] = ({ props }) => ({
root: props.size === 'small'
? 'border-color:#389e0d'
: 'border-color:#722ed1',
input: 'font-weight:600'
});
</script>
<style>
.example {
display: grid;
gap: 20px;
}
.example :global(.number-rounded) { border-radius: 12px; }
</style>
<div class="example">
<InputNumber classNames={{ root: 'number-rounded' }} styles={{ input: 'font-size:16px' }}
defaultValue={3} aria-label={("Styles InputNumber object")} style="width:100%" />
<InputNumber classNames={{ root: 'number-rounded' }} {styles}
defaultValue={3} aria-label={("Styles InputNumber function")} style="width:100%" />
</div>
Fractional step and precision
step sets the fractional step, precision — the normalization accuracy. decimalSeparator changes the display's decimal separator.
<script lang="ts">
import { InputNumber } from '@woodger/antd';
let value = $state<number | null>(0.1);
</script>
<style>
.example {
display: grid;
gap: 20px;
}
output { color: var(--ant-color-text-secondary); }
</style>
<div class="example">
<InputNumber bind:value step={0.1} precision={2} min={0} max={10}
aria-label={("Fractional step and precision")} style="width:100%" />
<InputNumber defaultValue={12.5} precision={2} decimalSeparator=","
aria-label={("Decimal point")} style="width:100%" />
<output aria-label={("Fractional value of the model")}>{(value === null ? 'null' : String(value))}</output>
</div>
Input normalization
changeOnBlur=false saves the draft when focus is lost. Enter normalizes the input to take into account the range.
<script lang="ts">
import { InputNumber } from '@woodger/antd';
let value = $state<number | null>(3);
</script>
<style>
.example {
display: grid;
gap: 16px;
}
output { color: var(--ant-color-text-secondary); }
</style>
<div class="example">
<InputNumber bind:value min={0} max={10} changeOnBlur={false}
aria-label={("Range correction by Enter")} style="width:100%" />
<output
aria-label={("Model with changeOnBlur=false")}
>{("Model: ")}{(value ?? 'null')}</output>
</div>
Order calculation in Form
Quantity and price are associated with Form. Validation, calculation, sending and reset save numbers and null.
<script lang="ts">
import { Button, Form, FormItem, InputNumber, createForm } from '@woodger/antd';
let result = $state('');
const money = new Intl.NumberFormat("en", { style: 'currency', currency: 'RUB' });
const form = createForm<{ quantity: number | null; price: number | null }>({
initialValues: { quantity: 2, price: 12.5 },
rules: ({
quantity: [
{ required: true, message: "Enter quantity." },
{ min: 0, max: 99, message: "The quantity must be from 0 to 99." },
{
validator: (value) =>
value === null || Number.isInteger(value)
? undefined
: "Enter an integer quantity."
}
],
price: [
{ required: true, message: "Enter price." },
{ min: 0, max: 1000, message: "Price must be from 0 to 1000." }
]
})
});
let total = $derived(
form.values.quantity === null || form.values.price === null
? '—'
: money.format(form.values.quantity * form.values.price)
);
function setValue(name: 'quantity' | 'price', value: number | null) {
form.setFieldValue(name, value);
result = '';
}
</script>
<style>
.example { max-width: 640px; }
.fields {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 0 24px;
}
.total {
margin: 0 0 24px;
font-size: 18px;
}
.actions {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
.result {
margin: 16px 0 0;
color: var(--ant-color-success);
}
@media (max-width: 560px) { .fields { grid-template-columns: minmax(0, 1fr); } }
</style>
<div class="example">
<Form {form} onFinish={() => { result = ("Order calculated: " + String((total)) + ""); }}>
<div class="fields">
<FormItem name="quantity" label={("Quantity")} help={("From 0 to 99, step 1.")}>
<InputNumber
value={form.values.quantity}
onValueChange={(value) => setValue('quantity', value)}
min={0}
max={99}
precision={0}
style="width: 100%"
/>
</FormItem>
<FormItem
name="price"
label={("Unit price")}
help={("From 0 to 1000, step 0.1. The fractional part is entered through a dot.")}
>
<InputNumber
value={form.values.price}
onValueChange={(value) => setValue('price', value)}
min={0}
max={1000}
step={0.1}
precision={2}
style="width: 100%"
/>
</FormItem>
</div>
<p class="total" role="status" aria-label={("Order cost")}>{("Price: ")}<strong>
{total}
</strong></p>
<div
class="actions"
><Button
type="primary"
htmlType="submit"
loading={form.isSubmitting}
>{("Calculate order")}</Button><Button
htmlType="reset"
onclick={() => { result = ''; }}
>{("Reset order")}</Button></div>
</Form>
{#if result}<p
class="result"
role="status"
aria-label={("Calculation result")}
>{result}</p>{/if}
</div>
The styles of options, additions and control buttons follow prefixCls. The topic namespace and Compact common variables are independent; the value and incomplete input are saved.
CSS prefixes InputNumber
Common namespace ConfigProvider and local prefixCls; the state of the component is preserved when the name is changed.
<script lang="ts">
import { Checkbox, ConfigProvider, InputNumber } from '@woodger/antd';
let custom = $state(true);
let local = $state(true);
const prefix = $derived(custom ? 'suite' : 'ant');
const localPrefix = $derived(local ? 'project-input-number' : '');
let value = $state<number | null>(3);
</script>
<style>
.example,
.prefix-stage {
display: grid;
grid-template-columns: minmax(0, 1fr);
gap: 16px;
min-width: 0;
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
p { margin: 0; }
output { overflow-wrap: anywhere; }
</style>
<div class="example">
<div class="controls">
<Checkbox bind:checked={custom}>{("General prefix InputNumber suite")}</Checkbox>
<Checkbox bind:checked={local}>{("Local prefix InputNumber")}</Checkbox>
</div>
<ConfigProvider prefixCls={prefix} theme={{ cssVar: { prefix: 'input-number-theme' } }}>
<div class="prefix-stage">
<InputNumber prefixCls={localPrefix} {value} onChange={next => value = next}
min={0} max={20} aria-label={("InputNumber with prefix")} style="width:100%" />
<output
aria-label={("InputNumber value with prefix")}
>{(value ?? '—')}</output>
</div>
</ConfigProvider>
<output
aria-label={("CSS prefix InputNumber")}
>{("General: ")}{prefix}{("; local: ")}{(localPrefix
|| ("from the provider"))}</output>
<p>
{("The styles of options, additions and control buttons follow prefixCls. The topic namespace and Compact common variables are independent; the value and incomplete input are saved.")}
</p>
</div>
API
Basic parameters InputNumber. Precise signatures define public types InputNumberProps, InputNumberConfig and InputNumberRef installed package @woodger/antd.
Numerical model uses InputNumberProps<number>, exact decimal strings - InputNumberProps<string>. The value type in the Svelte examples is inferred from the binding.
| Property | Description | Type | Default |
|---|---|---|---|
prefixCls | Full CSS prefix of the component and its parts. A non-empty local prop takes precedence; empty string and undefined inherit ConfigProvider. The namespace of the topic is set separately. | InputNumberProps['prefixCls'] | ant-input-number |
value | Number or null; supports bind:value and function binding. In stringMode the value is of type string | null. | InputNumberProps['value'] | — |
defaultValue | Initial value. Native reset restores it without callbacks; for the Form model, use reset it. | InputNumberProps['defaultValue'] | — |
min | Lower bound, number, or decimal string. The outer value may be out of range. | InputNumberProps['min'] | Number.MIN_SAFE_INTEGER |
max | Upper limit. Changing the boundaries itself does not trigger onChange. | InputNumberProps['max'] | Number.MAX_SAFE_INTEGER |
step | Integer or fractional step, number or string; default 1. | InputNumberProps['step'] | 1 |
precision | Normalization accuracy. Doesn't cut off the user's draft while typing. | InputNumberProps['precision'] | — |
stringMode | Decimal strings without conversion to Number; model and callbacks use string | null. | InputNumberProps['stringMode'] | false |
decimalSeparator | Separator in display. The model value remains a number or a decimal string with a dot. | InputNumberProps['decimalSeparator'] | "." |
formatter | Formats the display; info.userTyping and info.input allow you to save a draft as you type. | InputNumberProps['formatter'] | — |
parser | Retrieves a numeric value from a formatted string; returns a number or string. | InputNumberProps['parser'] | — |
controls | Shows step buttons; object allows you to specify upIcon and downIcon with text or snippets. | InputNumberProps['controls'] | true |
keyboard | Up and down arrows change value; false disables this action. | InputNumberProps['keyboard'] | true |
changeOnWheel | Change with the wheel near the field with focus; disabled by default. | InputNumberProps['changeOnWheel'] | false |
changeOnBlur | Default true. false saves draft when blur; Enter continues to normalize the input. | InputNumberProps['changeOnBlur'] | true |
mode | input - a regular field, spinner - buttons on the sides of the value. | InputNumberProps['mode'] | input |
size | small, medium or large. Inherits SpaceCompact or ConfigProvider. | InputNumberProps['size'] | medium |
variant | outlined, filled, borderless or underlined. Precedence: local prop → nearest Form.variant → inputNumber.variant → shared ConfigProvider.variant → outlined. | InputNumberProps['variant'] | outlined |
status | error or warning; The error status can also come from the FormItem. | InputNumberProps['status'] | — |
readOnly | Prevents changes while maintaining focus and text selection. | InputNumberProps['readOnly'] | false |
prefix | Text or Svelte snippet before the number inside the field. | InputNumberProps['prefix'] | — |
suffix | Text or snippet after the number. | InputNumberProps['suffix'] | — |
onValueChange | Gets the model value. Called after a compatible onChange. | InputNumberProps['onValueChange'] | — |
onChange | Gets a number, a string in stringMode, or null. This is a model value, not a DOM event. | InputNumberProps['onChange'] | — |
onInput | After onChange reports the original input line; it may differ from the model. | InputNumberProps['onInput'] | — |
onStep | Gets the result and info: offset, type (up/down), emitter (handler/keyboard/wheel). | InputNumberProps['onStep'] | — |
classNames | Semantic slots classes: object or function from { props }. | InputNumberProps['classNames'] | — |
styles | CSS strings for semantic slots: object or function from { props }. | InputNumberProps['styles'] | — |
inputElement | bind:inputElement gets the native input. | InputNumberProps['inputElement'] | — |
nativeElement | bind:nativeElement gets the root div of the number field. | InputNumberProps['nativeElement'] | — |
ref | Bindable proxy of native input with focus({ cursor }) method and nativeElement property. | InputNumberProps['ref'] | — |
Native id, name, required, disabled, aria-* and Svelte events are passed to the field. bind:inputElement returns input, bind:nativeElement - external control.
ConfigProvider.inputNumber
classstylevariantclassNamesstylesLocal variant takes precedence over the nearest Form.variant, then inputNumber.variant, common ConfigProvider.variant and outlined are applied. General size and availability are set via componentSize and componentDisabled.
Methods and composition
Via bind:this available focus() and blur(). focus accepts cursor: 'start' | 'end' | 'all' and native preventScroll.
SpaceCompact and SpaceAddon add units of measurement or actions next to the field. variant specifies the design.
Semantic DOM
Select an element to see its border on the actual field. Names are used in classNames and styles. The step buttons are shown continuously here so you can see their elements.
styles accepts CSS strings. Object and function from { props } shows example of semantic design.
Registration tokens
Tokens are transferred via ConfigProvider.theme.components.InputNumber. Names are verified against public ComponentTokenMap['InputNumber'].
<script lang="ts">
import { ConfigProvider, InputNumber } from '@woodger/antd';
</script>
<ConfigProvider theme={{
cssVar: {},
components: {
InputNumber: {
activeBorderColor: '#389e0d',
hoverBorderColor: '#73d13d',
activeShadow: '0 0 0 2px rgba(82,196,26,.15)',
handleVisible: true,
handleWidth: 28
}
}
}}>
<InputNumber
defaultValue={3}
aria-label={("Own theme InputNumber")}
style="width:100%"
/>
</ConfigProvider>
| Token | Purpose |
|---|---|
paddingInline | Horizontal padding of a regular field. |
paddingInlineSM | Horizontal padding of a small field. |
paddingInlineLG | Large margin horizontal indents. |
paddingBlock | Vertical padding of a regular field. |
paddingBlockSM | Vertical indents of a small field. |
paddingBlockLG | Vertical indents of a large field. |
addonBg | Add-ons background. |
hoverBorderColor | Frame hover color. |
activeBorderColor | Frame color when focused. |
activeShadow | Focus shadow. |
errorActiveShadow | Focus shadow on error. |
warningActiveShadow | Focus shadow when warning. |
hoverBg | Background when hovering. |
activeBg | Background when focusing. |
inputFontSize | Normal field font size. |
inputFontSizeLG | Large margin font size. |
inputFontSizeSM | Small margin font size. |
controlWidth | Standard field width. |
handleWidth | Step button width. |
handleFontSize | Size of button icons. |
handleVisible | Show buttons automatically or continuously. |
handleBg | Step button background. |
handleActiveBg | Background of the active button. |
handleHoverColor | Icon hover color. |
handleBorderColor | Button separator color. |
filledHandleBg | Button background is filled. |
handleOpacity | Button transparency. |
handleVisibleWidth | Width of the visible area of the buttons. |
Common tokens of the current topic
The values below are obtained through theme.useToken() and change along with the settings in the Ant Design header.
| Token | Purpose | Current value |
|---|---|---|
colorPrimary | Primary color of interactive states. | #2f54eb |
colorBgContainer | Background of a regular field. | #ffffff |
colorBorder | Frame color. | #d9d9d9 |
colorError | Error color. | #ff4d4f |
controlHeight | Normal field height. | 32 |
controlHeightSM | Height of the small field. | 24 |
controlHeightLG | Large field height. | 40 |
fontSize | Basic text size. | 14 |
FAQ
What is the difference between zero, empty field and string mode?
0 - number. Clearing returns null. In stringMode, the value is a decimal string; don't convert it using Number if you need precision. String mode example maintains a small step without losing digits.
Why can the external value go beyond min and max?
The model is controlled by the application. External write and boundary changes do not themselves trigger the user's onChange and should not change the data invisibly. Check for validity in the form model or explicit handler; range example shows behavior.
Why is the input value different from the model?
DOM stores the display string, including the formatter, decimal point, and unterminated input. For calculations, use bind:value, onValueChange or onChange. onInput reports a string rather than a ready-made numeric value.
When do precision and boundaries apply?
The field saves a draft when typed. Enter and, by default, blur will normalize it. changeOnBlur=false disables blur normalization, saving other changes to the model. Confirmation of input shows this separately from the fractional step.
How to bind InputNumber to Form?
Pass the value from form.values and update it through onValueChange. The Model stores a number or null, and the FormData contains the text. Order form shows check, send and reset.
Why does the wheel change the number when changeOnWheel=false?
The type="number" attribute enables separate browser behavior. Do not add it if wheel control must remain with the component. In example, the wheel is turned on explicitly and only works for the field with focus.
How to clear a field and is there allowClear?
Removing text returns null; the application can also set null to the managed model. allowClear and onClear from Ant Design 6.7.0 are not yet included in the public InputNumberProps of our package. Their presence in the current Ant Design documentation does not mean support in Svelte.
How to design internal elements?
Use classNames and CSS styles specified by an object or function from props. Semantic DOM shows the boundaries and design tokens for InputNumber shows the overall theme of the component. For focus and selection methods are available via bind:this.