Ant Design Svelte

Input

Text fields for entering, searching, passwords and verification codes.

When to use

Input is suitable for free text: name, address, search query or identifier. For a multi-line message, use TextArea. If the value is involved in the calculation and changes in numerical steps, select InputNumber. Select is intended for choosing from ready-made options.

The caption must explain the purpose of the field and remain visible after entry. placeholder complements the label, but does not replace it. Inside Form, the signature and description of the error links the FormItem; Give the independent field a label or an accessible name.

CSS Input Prefixes show global ConfigProvider.prefixCls and local prefixCls without resetting state. Input and TextArea use the same basic prefix. Password/Search shares shell prefixCls and inputPrefixCls fields. OTP changes group, cells and separators; the internal Input and the Search button separately inherit the common prefix of the provider.

How to select field

The names Input.Search, Input.Password and Input.OTP identify parts of the family. Individual components are imported into Svelte:

Problem Export Example
One line of text Input Basic input
Several lines TextArea Automatic height
Start search InputSearch Search
Visibility toggle password InputPassword Password
Code by individual cells InputOTP Verification code
Related fields and actions SpaceCompact, SpaceAddon Compact group

Phone numbers, SKUs, and codes with leading zeros usually require a text Input: such values ​​should not be converted to a number just because of the digits in the entry. Example tooltip formats numeric text while preserving the string model.

Meaning, events and Form

Input, TextArea, InputPassword and InputSearch support bind:value. defaultValue specifies the initial content; for subsequent updates, use the managed value. Cleaning reports the new value and returns focus to the field.

Select one method for updating the application state: binding or value with onValueChange. Native oninput receives a browser event. Compatible onChange is called on input and clear and contains a snapshot of the value; the original event is available via nativeEvent. There is no need to duplicate one model record in multiple handlers.

In Form, pass the value from the model and call setFieldValue via onValueChange. Do not link the readonly model via bind:value. Input Family Form shows check, send and reset; The password is not displayed along with the public result.

In InputSearch, the onSearch handler is separated from the line change: Enter and the button start the search, clearing reports source='clear'. loading blocks launch by Enter and button, saving cleaning. A custom button snippet must apply context.getButtonProps() or getNativeProps() to get the handlers and search state. Both scenarios are found in example and loading.

Content, length and focus

prefix and suffix place content within a field; SpaceAddon is next to it in a compact composition. For dynamic additions, keep a persistent snippet with a wrapper and change the content inside: rebuilding the wrapper may recreate the input and lose focus. Focus Methods allow you to select the cursor position and selection.

showCount shows the length, count.max sets the soft limit, and maxLength limits the input. By default, the counter uses UTF-16 units. For custom characters, including compound emoji, you need your own strategy and optionally exceedFormatter. Example of graphemes uses Intl.Segmenter. The external managed value is not trimmed by this formatter.

TextArea with autoSize measures content and available width; minRows and maxRows limit the height. Fixed CSS height interferes with this setting. The error or warning status specifies the design, but does not check the text itself: the rules belong to the Form or the application.

Input uses design tokens from the current theme for its appearance.

Examples

Current value: Svelte

Basic input

bind:value binds native input to Svelte string state.

Three sizes

large, medium and small. Without a local size, the field inherits the size from the ConfigProvider.

Design options

outlined, filled, borderless and underlined; decoration is also available for compound fields.

https://
Submit field value

Compact groups

SpaceCompact connects Input to Select, Button or SpaceAddon and matches their sizes.

Search blocked while loading

Search with loading

loading blocks search by Enter and button. Clearing the field remains available.

Characters: 35

TextArea

Multi-line field with bind:value, rows and native maxLength constraint.

Automatic height

autoSize adjusts the height to the content. minRows and maxRows limit the number of visible rows.

—
Cells: not filled Code not filled in yet

Input.OTP

Confirmation code with length selection, mask, formatting and separator. onInput reports the cells, onChange reports the full code.

Formatting in tooltip

Tooltip shows numbers with place separators while preserving text input. For the numerical step, InputNumber is intended.

@ ₽ RUB ₽ RUB Key

prefix and suffix

Text and Svelte snippets are placed inside the field before and after the value.

Input.Password

Switch visibility, own icon and control visibility from outside. The password value is saved.

Clear button returns focus to field

Cleaning

allowClear adds a clear button. onClear reports the action; focus returns to the field.

0 / 20 0 / 100 0 / 100

Character counter

showCount shows the length, maxLength sets a hard input limit for Input and TextArea.

14 / 10 3 1 / 6

Your own counting rules

count.max - soft limit. strategy counts graphemes, and exceedFormatter trims user input if necessary.

@ @

Field states

Error, warning, disabled and readOnly. readOnly allows you to select and copy a value.

Focus and highlighting

The focus() method uses bind:this to select the cursor position or highlight text in the Input and TextArea.

8
— — —

Semantic styles

classNames and styles style family elements. CSS strings are specified by an object or function from props.

In the form of Svelte

Input, InputPassword and TextArea are associated with the Form model: validation, submission and reset of values.

11
Found: —
General: suite; local: project-input

Input and TextArea use the same base prefix. Password/Search shares shell prefixCls and inputPrefixCls fields. OTP changes group, cells and separators; the internal Input and the Search button separately inherit the common prefix of the provider.

CSS prefixes Input

Common namespace ConfigProvider and local prefixCls; the state of the component is preserved when the name is changed.

API

Basic parameters of the Input family. The exact signatures are available in the public types of the installed package @woodger/antd. Property names in tables are checked against these types.

Input

Main parameters Input
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.InputProps['prefixCls']ant-input
valueString value; supports bind:value.InputProps['value']""
defaultValueInitial value without binding. Subsequent changes do not reinitialize the field.InputProps['defaultValue']—
sizesmall, medium or large. Inherited from SpaceCompact or ConfigProvider.InputProps['size']medium
variantoutlined, filled, borderless or underlined. Local variant → closest Form.variant → input.variant → shared ConfigProvider.variant → outlined.InputProps['variant']outlined
statuserror or warning; the state can also be set by FormItem.InputProps['status']—
prefixText, number or snippet before the value inside the field.InputProps['prefix']—
suffixContent after the value inside the field.InputProps['suffix']—
allowClearClear button: boolean or clearIcon and disabled settings.InputProps['allowClear']false
showCountCharacter counter or object with formatter.InputProps['showCount']false
countSoft maximum, counting strategy, display and optional input trimming. The exact type is InputCountConfig.InputProps['count']—
maxLengthHard native limit; without count.max specifies the maximum of the counter.InputProps['maxLength']—
onValueChangeGets the string after input and clearing; bind:value has now been updated.InputProps['onValueChange']—
onChangeCompatible event with a copy of target/currentTarget and the original nativeEvent. Native oninput and onchange remain separate.InputProps['onChange']—
onClearCalled after onValueChange and onChange when clearing.InputProps['onClear']—
onPressEnterEnter outside IME composition. Does not replace native onkeydown.InputProps['onPressEnter']—
classNamesSemantic slots classes: object or function from { props }.InputProps['classNames']—
stylesCSS strings for semantic slots: object or function from { props }.InputProps['styles']—
inputElementbind:inputElement receives the native input, regardless of the presence of a wrapper.InputProps['inputElement']—
nativeElementbind:nativeElement receives an external root: input or a wrapper.InputProps['nativeElement']—

Native name, required, disabled, readonly, inputmode and aria-* are transmitted to the field. htmlSize specifies the size HTML attribute; visual size is set via size.

TextArea

Multiline field has its own TextAreaProps, preserves native textarea attributes and supports variants, status, clear/count and semantic styles.

Basic parameters TextArea
PropertyDescriptionTypeDefault
prefixClsFull prefix for this part of the family; empty string/undefined select ConfigProvider. Internal Input and buttons retain independent namespace.TextAreaProps['prefixCls']ant-input
valueString with bind:value, including newlines.TextAreaProps['value']""
autoSizetrue or { minRows, maxRows }; the height is measured by the content or placeholder.TextAreaProps['autoSize']false
allowClearClearing a multi-line value.TextAreaProps['allowClear']false
countCommon soft limit, strategy and exceedFormatter rules with Input.TextAreaProps['count']—
onResizeGets the measured width and height when resizing.TextAreaProps['onResize']—
nativeElementbind:nativeElement always returns textarea.TextAreaProps['nativeElement']—
rootElementbind:rootElement returns the outer textarea or span.TextAreaProps['rootElement']—

Input.Password

InputPasswordProps extends Input: string value, events and focus methods are preserved. The native type is determined by the visibility of the password.

Input.Password parameters
PropertyDescriptionTypeDefault
inputPrefixClsFull independent prefix of nested Input; is not output from prefixCls shell. The empty string/undefined inherits the common Input prefix.InputPasswordProps['inputPrefixCls']ant-input
prefixClsFull prefix for this part of the family; empty string/undefined select ConfigProvider. Internal Input and buttons retain independent namespace.InputPasswordProps['prefixCls']ant-input-password
visibilityToggletrue by default; false hides the radio button. An object with visible and onVisibleChange controls visibility from the outside.InputPasswordProps['visibilityToggle']true
iconRenderThe visibility function returns the text or Svelte snippet for the radio button.InputPasswordProps['iconRender']—
actionclick by default; hover changes visibility when hovering, but leaving the mouse does not return it.InputPasswordProps['action']click
suffixAdditional content before the visibility switch.InputPasswordProps['suffix']—

Input.Search

InputSearchProps expands Input. Handlers receive their buttons via context.getButtonProps() or context.getNativeProps(); search example shows connection.

Input.Search parameters
PropertyDescriptionTypeDefault
inputPrefixClsFull independent prefix of nested Input; is not output from prefixCls shell. The empty string/undefined inherits the common Input prefix.InputSearchProps['inputPrefixCls']ant-input
prefixClsFull prefix for this part of the family; empty string/undefined select ConfigProvider. Internal Input and buttons retain independent namespace.InputSearchProps['prefixCls']ant-input-search
enterButtonfalse - regular icon, true - main button, line - label. Snippet gets context getButtonProps/getNativeProps.InputSearchProps['enterButton']false
searchIconIcon for boolean enterButton; null or false hide it.InputSearchProps['searchIcon']—
loadingLocks the button and search by Enter, maintaining the availability of cleaning.InputSearchProps['loading']false
onSearchGets the value, event and info.source: input or clear. Cleanup calls onSearch before onChange.InputSearchProps['onSearch']—
classNamesInput and button slots: class string or Button slots object.InputSearchProps['classNames']—
stylesInput and button slots; For a button, you can pass an object of CSS strings root, icon and content.InputSearchProps['styles']—

Input.OTP

Input.OTP parameters
PropertyDescriptionTypeDefault
prefixClsFull prefix for this part of the family; empty string/undefined select ConfigProvider. Internal Input and buttons retain independent namespace.InputOTPProps['prefixCls']ant-otp
lengthNumber of cells, default 6.InputOTPProps['length']6
defaultValueInitial value also used for SSR; formatter is applied once.InputOTPProps['defaultValue']""
valueChanging prop synchronizes cells after mount. bind:value not provided; use onInput and onChange.InputOTPProps['value']—
formatterConverts the entire string with spaces in place of empty cells before the length limit.InputOTPProps['formatter']—
masktrue hides symbols with dots; the line specifies its own mask. The original value is retained.InputOTPProps['mask']false
separatorContents between cells or a function of the index. For rich content the function returns snippet.InputOTPProps['separator']—
onInputGets an array of cells on every input, including empty positions.InputOTPProps['onInput']—
onChangeCalled only for changed fully filled code; incomplete input does not trigger a callback.InputOTPProps['onChange']—
inputModeNative virtual keyboard tooltip; does not itself limit input to numbers.InputOTPProps['inputMode']—
nativeElementbind:nativeElement gets the group div, not the individual input.InputOTPProps['nativeElement']—

Compact groups

SpaceCompact merges adjacent fields, and SpaceAddon adds a caption before or after the field.

ConfigProvider Settings

Overall size and availability are set via componentSize and componentDisabled. The following sections are used for registration:

ConfigProvider.input

allowClearautoCompletevariantclassstyleclassNamesstyles

ConfigProvider.textArea

allowClearautoCompletevariantclassstyleclassNamesstyles

ConfigProvider.inputPassword

iconRendervariantclassstyleclassNamesstyles

ConfigProvider.inputSearch

searchIconvariantclassstyleclassNamesstyles

ConfigProvider.otp

variantclassstyleclassNamesstyles

For variant, the order is: local prop → nearest Form.variant → component configuration → general ConfigProvider.variant → outlined. InputPassword, InputSearch and InputOTP additionally use input.variant after customization. The nested ConfigProvider replaces the entire component object passed in.

Focus methods

Via bind:this at Input, InputPassword and InputSearch available focus(), blur(), select() and setSelectionRange(). TextArea supports focus() and blur(); InputOTP - focus the first cell and remove focus. Example shows cursor selection and text selection.

Semantic DOM

Select a component and element to see its border on the actual field. The names correspond to the public semantic slots of the package. classNames specifies classes, and styles - CSS strings.

@ 6ID
root: External field element; with prefix, suffix, clear or count a wrapper appears.

Password slots are the same as Input. Search adds button, TextArea uses textarea, and OTP - input for each cell and separator for separators.

Registration tokens

Family uses ConfigProvider.theme.components.Input, including TextArea and internal Password, Search and OTP fields. Names are verified by ComponentTokenMap['Input']; The Search button additionally uses the Button design.

<script lang="ts">
  import { ConfigProvider, Input, InputPassword, TextArea } from '@woodger/antd';
</script>

<style>
  .example {
    display: grid;
    gap: 20px;
  }
</style>

<ConfigProvider theme={{
  cssVar: {},
  components: {
    Input: {
      activeBorderColor: '#389e0d',
      hoverBorderColor: '#73d13d',
      activeShadow: '0 0 0 2px rgba(82,196,26,.15)',
      paddingInline: 14
    }
  }
}}>
  <div class="example">
    <Input aria-label={("Own theme Input")} placeholder={("Point or change focus")} />
    <InputPassword aria-label={("Custom password theme")} placeholder={("Common Input Tokens")} />
    <TextArea aria-label={("Own theme TextArea")} rows={2} placeholder={("Same tokens for TextArea")} />
  </div>
</ConfigProvider>
Input 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.
addonBgBackground of external additions.
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.

Common tokens of the current topic

Values obtained via theme.useToken() and are updated 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

How to connect fields with state and Form?

For standalone text fields, use bind:value. In Form, pass the value from form.values and update it through onValueChange. Example form shows verification, sending and reset without displaying the password.

What is the difference between onChange and oninput?

oninput is a native Svelte event. onChange is called on input and cleanup and contains a copy of the value in target/currentTarget; the original event is in nativeEvent. For a string without an event object, use onValueChange.

Why doesn't count.max limit the length?

It shows the excess while saving the input. The hard limit is set by maxLength. For your counting rule, specify strategy and, if necessary, exceedFormatter. External values ​​are not trimmed by this formatter.

Why can a managed TextArea contain more than maxLength?

The content specifies the application model. An external entry should not imperceptibly change its meaning. If a restriction is required for data, check it when entering and submitting; A single HTML attribute does not replace a model rule.

How to count emoji as one character?

The default length is UTF-16. Your own counter uses Intl.Segmenter to count graphemes, including compound emoji. This rule is different from the number of OTP cells.

Why does the focus change when adding a prefix, suffix or counter?

The appearance or disappearance of a shell changes the DOM. Keep a persistent snippet with a wrapper element for dynamic additions; change its individual parts inside. For explicit focus, use public methods via bind:this.

How to control Input.OTP and what to show when SSR?

InputOTP does not have bind:value. onInput reports an array of cells with empty positions, onChange reports only completely filled changed code. The cell stores one UTF-16 unit; The field accepts text, not just numbers. value is synchronized after mount; defaultValue is intended for initial server display. The code review belongs to the application.

Why doesn't TextArea reduce its height?

With autoSize, text, placeholder, width and minRows/maxRows are taken into account. Do not set a fixed height at the same time. Auto height example allows you to check the increase and decrease of the field.

How to format parts of a compound field?

classNames defines semantic slots classes, styles defines CSS strings. Search adds a button slot, OTP - input and separator. Semantic DOM shows the actual boundaries; the overall size and variant are specified via ConfigProvider.