Ant Design Svelte

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

number: 3

Basic input

bind:value binds a number to the Svelte model. Zero is stored as a number, an empty field returns null.

Three sizes

large, medium and small. Without local size, the ConfigProvider or SpaceCompact setting is valid.

Accessibility and reading

disabled disables interaction. readOnly retains the ability to focus the field and highlight the value.

string: 1

Exact decimal strings

stringMode stores the decimal value as a string, including a step less than the precision of a regular number.

Amount: 1000; percentage: 25

Formatting

formatter changes the display of the amount and percentage, parser restores the number. The model stores a number or null.

Step not completed yet

Keyboard and buttons

keyboard controls the keyboard arrows, controls controls the buttons. onStep reports the direction and source of the step.

Step not completed yet

Mouse wheel

changeOnWheel allows wheel changes only for the field with focus. In the example, the action is enabled explicitly.

Design options

outlined, filled, borderless and underlined are specified via variant.

Spinner mode

mode="spinner" places the buttons on the sides of the value. controls allows you to replace their icons.

0…10; meaning: 99; onChange: 0

Value out of range

External value and bounds changes do not by themselves trigger onChange. User input normalization takes into account min and max.

₽
Price
₽
₽
RUB

prefix and suffix

In-field additions and composition with SpaceCompact / SpaceAddon.

₽
RUB

Error and warning

status highlights an error or warning, including the presence of a prefix and suffix.

Focus and highlighting

Through bind:this, focus() with selecting the cursor position and blur() are available.

Semantic styles

classNames and styles style internal elements: an object or function from { props }.

0.1

Fractional step and precision

step sets the fractional step, precision — the normalization accuracy. decimalSeparator changes the display's decimal separator.

Model: 3

Input normalization

changeOnBlur=false saves the draft when focus is lost. Enter normalizes the input to take into account the range.

From 0 to 99, step 1.
From 0 to 1000, step 0.1. The fractional part is entered through a dot.

Price: RUB 25.00

Order calculation in Form

Quantity and price are associated with Form. Validation, calculation, sending and reset save numbers and null.

3
General: suite; local: project-input-number

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.

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.

Main parameters InputNumber
PropertyDescriptionTypeDefault
prefixClsFull 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
valueNumber or null; supports bind:value and function binding. In stringMode the value is of type string | null.InputNumberProps['value']—
defaultValueInitial value. Native reset restores it without callbacks; for the Form model, use reset it.InputNumberProps['defaultValue']—
minLower bound, number, or decimal string. The outer value may be out of range.InputNumberProps['min']Number.MIN_SAFE_INTEGER
maxUpper limit. Changing the boundaries itself does not trigger onChange.InputNumberProps['max']Number.MAX_SAFE_INTEGER
stepInteger or fractional step, number or string; default 1.InputNumberProps['step']1
precisionNormalization accuracy. Doesn't cut off the user's draft while typing.InputNumberProps['precision']—
stringModeDecimal strings without conversion to Number; model and callbacks use string | null.InputNumberProps['stringMode']false
decimalSeparatorSeparator in display. The model value remains a number or a decimal string with a dot.InputNumberProps['decimalSeparator']"."
formatterFormats the display; info.userTyping and info.input allow you to save a draft as you type.InputNumberProps['formatter']—
parserRetrieves a numeric value from a formatted string; returns a number or string.InputNumberProps['parser']—
controlsShows step buttons; object allows you to specify upIcon and downIcon with text or snippets.InputNumberProps['controls']true
keyboardUp and down arrows change value; false disables this action.InputNumberProps['keyboard']true
changeOnWheelChange with the wheel near the field with focus; disabled by default.InputNumberProps['changeOnWheel']false
changeOnBlurDefault true. false saves draft when blur; Enter continues to normalize the input.InputNumberProps['changeOnBlur']true
modeinput - a regular field, spinner - buttons on the sides of the value.InputNumberProps['mode']input
sizesmall, medium or large. Inherits SpaceCompact or ConfigProvider.InputNumberProps['size']medium
variantoutlined, filled, borderless or underlined. Precedence: local prop → nearest Form.variant → inputNumber.variant → shared ConfigProvider.variant → outlined.InputNumberProps['variant']outlined
statuserror or warning; The error status can also come from the FormItem.InputNumberProps['status']—
readOnlyPrevents changes while maintaining focus and text selection.InputNumberProps['readOnly']false
prefixText or Svelte snippet before the number inside the field.InputNumberProps['prefix']—
suffixText or snippet after the number.InputNumberProps['suffix']—
onValueChangeGets the model value. Called after a compatible onChange.InputNumberProps['onValueChange']—
onChangeGets a number, a string in stringMode, or null. This is a model value, not a DOM event.InputNumberProps['onChange']—
onInputAfter onChange reports the original input line; it may differ from the model.InputNumberProps['onInput']—
onStepGets the result and info: offset, type (up/down), emitter (handler/keyboard/wheel).InputNumberProps['onStep']—
classNamesSemantic slots classes: object or function from { props }.InputNumberProps['classNames']—
stylesCSS strings for semantic slots: object or function from { props }.InputNumberProps['styles']—
inputElementbind:inputElement gets the native input.InputNumberProps['inputElement']—
nativeElementbind:nativeElement gets the root div of the number field.InputNumberProps['nativeElement']—
refBindable 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

classstylevariantclassNamesstyles

Local 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.

₽
RUB
root: External element of a numeric field.

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>
InputNumber component tokens
TokenPurpose
paddingInlineHorizontal padding of a regular field.
paddingInlineSMHorizontal padding of a small field.
paddingInlineLGLarge margin horizontal indents.
paddingBlockVertical padding of a regular field.
paddingBlockSMVertical indents of a small field.
paddingBlockLGVertical indents of a large field.
addonBgAdd-ons background.
hoverBorderColorFrame hover color.
activeBorderColorFrame color when focused.
activeShadowFocus shadow.
errorActiveShadowFocus shadow on error.
warningActiveShadowFocus shadow when warning.
hoverBgBackground when hovering.
activeBgBackground when focusing.
inputFontSizeNormal field font size.
inputFontSizeLGLarge margin font size.
inputFontSizeSMSmall margin font size.
controlWidthStandard field width.
handleWidthStep button width.
handleFontSizeSize of button icons.
handleVisibleShow buttons automatically or continuously.
handleBgStep button background.
handleActiveBgBackground of the active button.
handleHoverColorIcon hover color.
handleBorderColorButton separator color.
filledHandleBgButton background is filled.
handleOpacityButton transparency.
handleVisibleWidthWidth 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.

Common tokens of the current topic
TokenPurposeCurrent value
colorPrimaryPrimary color of interactive states.#2f54eb
colorBgContainerBackground of a regular field.#ffffff
colorBorderFrame color.#d9d9d9
colorErrorError color.#ff4d4f
controlHeightNormal field height.32
controlHeightSMHeight of the small field.24
controlHeightLGLarge field height.40
fontSizeBasic 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.