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
Basic input
bind:value binds native input to Svelte string state.
<script lang="ts">
import { Input } from '@woodger/antd';
let value = $state('Svelte');
</script>
<style>
.example {
display: grid;
gap: 12px;
}
output {
color: var(--ant-color-text-secondary);
overflow-wrap: anywhere;
}
</style>
<div class="example">
<Input aria-label={("Basic field Input")} bind:value placeholder={("Enter text")} />
<output aria-label={("Input value")}>{("Current value: ")}{(value
|| '—')}</output>
</div>
Three sizes
large, medium and small. Without a local size, the field inherits the size from the ConfigProvider.
<script lang="ts">
import { Input } from '@woodger/antd';
</script>
<style>
.example {
display: grid;
gap: 16px;
}
</style>
{#snippet userIcon()}
<svg
width="1em"
height="1em"
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
aria-hidden="true"
focusable="false"
><circle
cx="8"
cy="5"
r="3"
/><path
d="M2 15v-2a6 6 0 0 1 12 0v2"
/></svg>
{/snippet}
<div class="example">
<Input
size="large"
prefix={userIcon}
aria-label={("Large field")}
placeholder={("large")}
/>
<Input
size="medium"
prefix={userIcon}
aria-label={("Normal field")}
placeholder={("medium")}
/>
<Input
size="small"
prefix={userIcon}
aria-label={("Small field")}
placeholder={("small")}
/>
</div>
Design options
outlined, filled, borderless and underlined; decoration is also available for compound fields.
<script lang="ts">
import { Input, InputSearch, type InputVariant } from '@woodger/antd';
const variants = ['outlined', 'filled', 'borderless', 'underlined'] satisfies InputVariant[];
</script>
<style>
.example {
display: grid;
gap: 16px;
}
</style>
<div class="example">
{#each variants as variant (variant)}
<Input {variant} aria-label={("Option " + String((variant)) + "")} placeholder={(variant)} />
{/each}
<InputSearch variant="filled" aria-label={("Search filled")} placeholder={("Input.Search filled")} />
</div>
Compact groups
SpaceCompact connects Input to Select, Button or SpaceAddon and matches their sizes.
<script lang="ts">
import { Button, Input, Select, SpaceAddon, SpaceCompact } from '@woodger/antd';
let value = $state('woodger.org');
let result = $state('');
const options = [{ value: 'https', label: 'https://' }, { value: 'http', label: 'http://' }];
</script>
<style>
.example {
display: grid;
gap: 20px;
}
output {
color: var(--ant-color-text-secondary);
overflow-wrap: anywhere;
}
</style>
{#snippet protocol()}
<Select aria-label={("Protocol")} options={(options)} defaultValue="https" style="width:112px" />
{/snippet}
{#snippet address()}
<Input aria-label={("Website address")} placeholder={("woodger.org")} style="
min-width: 0;
flex: 1;
" />
{/snippet}
{#snippet field()}<Input
aria-label={("Compact field")}
bind:value
style="
min-width: 0;
flex: 1;
"
/>{/snippet}
{#snippet submit()}
<Button type="primary" onclick={() => { result = value; }}>
{("Send")}
</Button>
{/snippet}
{#snippet prefix()}<SpaceAddon>https://</SpaceAddon>{/snippet}
{#snippet domain()}
<Input aria-label={("Domain with addon")} placeholder={("woodger.org")} style="
min-width: 0;
flex: 1;
" />
{/snippet}
<div class="example">
<SpaceCompact block items={([protocol, address])} />
<SpaceCompact block items={([field, submit])} />
<SpaceCompact block items={([prefix, domain])} />
<output aria-label={("Compact group result")}>{(result
|| ("Submit field value"))}</output>
</div>
Input.Search
Search by Enter and button, clear and your button snippet. onSearch reports the source of the action.
<script lang="ts">
import { Button, InputSearch, type InputSearchProps } from '@woodger/antd';
let value = $state('Svelte');
let result = $state('');
const onSearch: InputSearchProps['onSearch'] = (next, _event, info) => {
result = ("" + String((info?.source === 'clear'
? ("Cleaning")
: ("Search"))) + ": " + String((next || ("empty request"))) + "");
};
</script>
<style>
.example {
display: grid;
gap: 20px;
}
output {
color: var(--ant-color-text-secondary);
overflow-wrap: anywhere;
}
</style>
<div class="example">
<InputSearch aria-label={("Search with icon")} placeholder={("Regular button")} {onSearch} />
<InputSearch aria-label={("Search with main icon")} placeholder={("Main button")} enterButton {onSearch} />
<InputSearch
aria-label={("Search by request")}
bind:value
allowClear
enterButton={("Find")}
{onSearch}
/>
<InputSearch aria-label={("Search with your own button")} placeholder={("Svelte snippet")} {onSearch}>
{#snippet enterButton(context)}
<Button {...context.getButtonProps({ type: 'primary' })}>{("Search")}</Button>
{/snippet}
</InputSearch>
<output aria-label={("Result Input.Search")}>{(result
|| ("Send a request using the button or the Enter key"))}</output>
</div>
Search with loading
loading blocks search by Enter and button. Clearing the field remains available.
<script lang="ts">
import { InputSearch } from '@woodger/antd';
let result = $state(("Search blocked while loading"));
</script>
<style>
.example {
display: grid;
gap: 20px;
}
output { color: var(--ant-color-text-secondary); }
</style>
<div class="example">
<InputSearch loading aria-label={("Loading search with icon")} placeholder={("Loading")} />
<InputSearch
loading
enterButton
aria-label={("Loading the main search button")}
placeholder={("Loading")}
/>
<InputSearch loading enterButton={("Find")} allowClear defaultValue="Svelte"
aria-label={("Loading search with cleaning")} onSearch={(_value, _event, info) => {
result = info?.source === 'clear'
? ("Request cleared during boot")
: ("Search completed");
}} />
<output aria-label={("Search loading status")}>{result}</output>
</div>
TextArea
Multi-line field with bind:value, rows and native maxLength constraint.
<script lang="ts">
import { TextArea } from '@woodger/antd';
let value = $state(("Task Description Additional Details"));
</script>
<style>
.example {
display: grid;
gap: 20px;
}
output { color: var(--ant-color-text-secondary); }
</style>
<div class="example">
<TextArea rows={4} aria-label={("Multi-line description")} bind:value />
<TextArea
rows={2}
maxLength={6}
aria-label={("Description up to six characters")}
placeholder={("Maximum 6 characters")}
/>
<output aria-label={("TextArea Length")}>{("Characters: ")}{(value.length)}</output>
</div>
Automatic height
autoSize adjusts the height to the content. minRows and maxRows limit the number of visible rows.
<script lang="ts">
import { TextArea } from '@woodger/antd';
let value = $state(("Managed multiline field"));
</script>
<style>
.example {
display: grid;
gap: 24px;
}
</style>
<div class="example">
<TextArea autoSize aria-label={("Automatic height")} placeholder={("Height by content")} />
<TextArea autoSize={{ minRows: 2, maxRows: 6 }} aria-label={("Height from two to six lines")}
placeholder={("From two to six lines")} />
<TextArea bind:value autoSize={{ minRows: 3, maxRows: 5 }} aria-label={("Controlled height of TextArea")} />
</div>
Input.OTP
Confirmation code with length selection, mask, formatting and separator. onInput reports the cells, onChange reports the full code.
<script lang="ts">
import { InputOTP } from '@woodger/antd';
let length = $state(6);
let masked = $state(false);
let cells = $state('');
let complete = $state('');
</script>
<style>
.example {
display: grid;
gap: 16px;
min-width: 0;
}
.options {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 12px;
}
label {
display: inline-flex;
align-items: center;
gap: 8px;
}
select {
padding: 4px;
border: 1px solid var(--ant-color-border);
border-radius: 4px;
background: var(--ant-color-bg-container);
color: var(--ant-color-text);
font: inherit;
}
.code {
max-width: 100%;
overflow-x: auto;
padding-block: 4px;
}
output {
color: var(--ant-color-text-secondary);
overflow-wrap: anywhere;
}
</style>
<div class="example">
<div class="options">
<label>{("Code length ")}<select bind:value={length} onchange={() => {
cells = '';
complete = '';
}}>
<option value={4}>4</option><option value={6}>6</option><option value={8}>8</option>
</select></label>
<label><input type="checkbox" bind:checked={masked} />{(" Hide code")}</label>
</div>
<div class="code">
{#key length}
<InputOTP {length} mask={masked} aria-label={("Input.OTP confirmation code")}
autoComplete="one-time-code" formatter={value => value.toUpperCase()}
separator={index => index === Math.floor(length / 2) - 1 ? '—' : undefined}
onInput={next => { cells = next.map(cell => cell || '·').join(''); }}
onChange={next => { complete = next; }} />
{/key}
</div>
<output aria-label={("Input.OTP Cells")}>{("Cells: ")}{(cells
|| ("not filled"))}</output>
<output aria-label={("Full code Input.OTP")}>{(complete ? `Latest complete code: ${complete}` : "Code not filled in yet")}</output>
</div>
Formatting in tooltip
Tooltip shows numbers with place separators while preserving text input. For the numerical step, InputNumber is intended.
<script lang="ts">
import { Input, Tooltip } from '@woodger/antd';
let value = $state('');
let lastValid = '';
const format = new Intl.NumberFormat("en", { maximumFractionDigits: 12 });
const title = $derived(
value && value !== '-'
? format.format(Number(value))
: "Enter number"
);
function handleInput(event: Event & { currentTarget: HTMLInputElement }) {
const next = event.currentTarget.value;
if (/^-?\d*(\.\d*)?$/.test(next)) {
lastValid = next;
}
else {
event.currentTarget.value = lastValid;
value = lastValid;
}
}
function normalize() {
value = value.replace(/\.$/, '').replace(/^(-?)0+(?=\d)/, '$1');
if (value === '-') value = '';
lastValid = value;
}
</script>
<Tooltip title={title} trigger="focus">
<Input
aria-label={("Number in text field")}
bind:value
inputmode="decimal"
maxLength={16}
placeholder={("Enter number")}
oninput={handleInput}
onblur={normalize}
/>
</Tooltip>
prefix and suffix
Text and Svelte snippets are placed inside the field before and after the value.
<script lang="ts">
import { Input, InputPassword, Tooltip } from '@woodger/antd';
</script>
<style>
.example {
display: grid;
gap: 20px;
}
.info {
display: inline-flex;
align-items: center;
justify-content: center;
width: 18px;
height: 18px;
padding: 0;
border: 1px solid currentColor;
border-radius: 50%;
background: none;
color: inherit;
font-size: 12px;
cursor: help;
}
</style>
{#snippet help()}
<Tooltip title={("Enter the username without spaces")}>
<button class="info" type="button" aria-label={("Name hint")}>i</button>
</Tooltip>
{/snippet}
<div class="example">
<Input
prefix="@"
suffix={help}
aria-label={("Name with hint")}
placeholder={("Username")}
/>
<Input prefix="₽" suffix="RUB" aria-label={("Amount with currency")} placeholder={("Amount")} />
<Input
prefix="₽"
suffix="RUB"
disabled
aria-label={("Unavailable amount")}
defaultValue="1200"
/>
<InputPassword
suffix={("Key")}
aria-label={("Password with suffix")}
placeholder={("Password")}
/>
</div>
Input.Password
Switch visibility, own icon and control visibility from outside. The password value is saved.
<script lang="ts">
import { Button, InputPassword } from '@woodger/antd';
let visible = $state(false);
</script>
<style>
.example {
display: grid;
gap: 20px;
}
.controlled {
display: grid;
gap: 12px;
justify-items: start;
}
</style>
<div class="example">
<InputPassword aria-label={("Normal password")} placeholder={("Enter password")} allowClear />
<InputPassword aria-label={("Password with its own icon")} placeholder={("Your switch")}
iconRender={shown => shown ? "Hide" : "Show"} />
<div class="controlled">
<InputPassword aria-label={("Managed password")} defaultValue="Svelte-5-demo"
visibilityToggle={{ visible, onVisibleChange: next => { visible = next; } }} />
<Button onclick={() => { visible = !visible; }}>{(visible ? "Hide password" : "Show password")}</Button>
</div>
<InputPassword
disabled
aria-label={("Inaccessible password")}
defaultValue="password"
/>
</div>
Cleaning
allowClear adds a clear button. onClear reports the action; focus returns to the field.
<script lang="ts">
import { Input, TextArea } from '@woodger/antd';
let input = $state(("Clear field"));
let text = $state(("Clear multi-line field"));
let result = $state('');
</script>
<style>
.example {
display: grid;
gap: 20px;
}
output { color: var(--ant-color-text-secondary); }
</style>
<div class="example">
<Input aria-label={("Input with cleaning")} bind:value={input} allowClear
onClear={() => { result = ("Input cleared"); }} />
<TextArea aria-label={("TextArea with cleaning")} bind:value={text} allowClear rows={3}
onClear={() => { result = ("TextArea cleared"); }} />
<output aria-label={("Cleaning result")}>{(result
|| ("Clear button returns focus to field"))}</output>
</div>
Character counter
showCount shows the length, maxLength sets a hard input limit for Input and TextArea.
<script lang="ts">
import { Input, TextArea } from '@woodger/antd';
</script>
<style>
.example {
display: grid;
gap: 24px;
}
</style>
<div class="example">
<Input
showCount
maxLength={20}
aria-label={("Input with counter")}
placeholder={("Up to 20 characters")}
/>
<TextArea showCount maxLength={100} rows={3} aria-label={("TextArea with counter")}
placeholder={("Up to 100 characters")} />
<TextArea showCount maxLength={100} rows={3} aria-label={("TextArea without resizing")}
placeholder={("Mouse height adjustment disabled")} style="resize:none" />
</div>
Your own counting rules
count.max - soft limit. strategy counts graphemes, and exceedFormatter trims user input if necessary.
<script lang="ts">
import { Input } from '@woodger/antd';
const segmenter = new Intl.Segmenter('ru', { granularity: 'grapheme' });
const characters = (value: string) => Array.from(segmenter.segment(value), part => part.segment);
</script>
<style>
.example {
display: grid;
gap: 24px;
}
</style>
<div class="example">
<Input defaultValue="Hello, Svelte!" count={{ show: true, max: 10 }}
aria-label={("Soft character limit")} />
<Input defaultValue="🔥🔥🔥" count={{ show: true, strategy: value => characters(value).length }}
aria-label={("Grapheme counter")} />
<Input defaultValue="🔥" aria-label={("Grapheme restriction")} count={{
show: true,
max: 6,
strategy: value => characters(value).length,
exceedFormatter: (value, { max }) => characters(value).slice(0, max).join('')
}} />
</div>
Field states
Error, warning, disabled and readOnly. readOnly allows you to select and copy a value.
<script lang="ts">
import { Input } from '@woodger/antd';
</script>
<style>
.example {
display: grid;
gap: 16px;
}
</style>
<div class="example">
<Input status="error" aria-label={("Error field")} placeholder={("Error")} />
<Input status="warning" aria-label={("Warning field")} placeholder={("Warning")} />
<Input
prefix="@"
status="error"
aria-label={("Error with prefix")}
placeholder={("Error with prefix")}
/>
<Input
prefix="@"
status="warning"
aria-label={("Warning with prefix")}
placeholder={("Warning with prefix")}
/>
<Input disabled aria-label={("Inaccessible Input field")} defaultValue="Недоступно" />
<Input
readOnly
aria-label={("Read-only field")}
defaultValue="Можно выделить и скопировать"
/>
</div>
Focus and highlighting
The focus() method uses bind:this to select the cursor position or highlight text in the Input and TextArea.
<script lang="ts">
import { Button, Checkbox, Input, TextArea } from '@woodger/antd';
let multiline = $state(false);
let value = $state(("Ant Design for Svelte"));
let control = $state<ReturnType<typeof Input> | ReturnType<typeof TextArea>>();
</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' })}>{("Back to top")}</Button>
<Button onclick={() => control?.focus({ cursor: 'end' })}>{("To the end")}</Button>
<Button
onclick={() => control?.focus({ cursor: 'all' })}
>{("Select all")}</Button>
<Button
onclick={() => control?.focus({ preventScroll: true })}
>{("Without scrolling")}</Button>
</div>
<Checkbox bind:checked={multiline}>{("Multiline field")}</Checkbox>
{#if multiline}
<TextArea
bind:this={control}
bind:value
aria-label={("Focus control field")}
/>
{:else}
<Input bind:this={control} bind:value aria-label={("Focus control field")} />
{/if}
</div>
Semantic styles
classNames and styles style family elements. CSS strings are specified by an object or function from props.
<script lang="ts">
import {
Input,
InputOTP,
InputPassword,
InputSearch,
TextArea,
type InputProps
} from '@woodger/antd';
const styles: InputProps['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(.input-semantic-root) { border-radius: 12px; }
.otp {
min-width: 0;
overflow-x: auto;
padding-block: 4px;
}
</style>
<div class="example">
<Input aria-label={("Styles Input function")} placeholder={("Styles function")}
classNames={{ root: 'input-semantic-root' }} {styles} />
<TextArea showCount defaultValue="TextArea" aria-label={("TextArea Styles")}
styles={{
textarea: 'resize:none',
count: 'color:#389e0d'
}} />
<InputPassword aria-label={("Input.Password Styles")} defaultValue="Password"
styles={{ root: 'border-color:#d46b08' }} />
<InputSearch aria-label={("Input.Search Styles")} placeholder={("Search Button Styles")} enterButton={("Find")}
styles={{ button: { root: `
background: #389e0d;
border-color: #389e0d;
` } }} />
<div class="otp">
<InputOTP length={4} separator="—" aria-label={("Input.OTP Styles")}
styles={{ input: 'border-color:#722ed1' }} />
</div>
</div>
In the form of Svelte
Input, InputPassword and TextArea are associated with the Form model: validation, submission and reset of values.
<script lang="ts">
import { Button, Form, FormItem, Input, InputPassword, TextArea, createForm } from '@woodger/antd';
const form = createForm<{ name: string; password: string; description: string }>({
initialValues: { name: '', password: '', description: '' },
rules: ({
name: [{ required: true, message: "Please enter a name." }],
password: [{
min: 6,
required: true,
message: "The password must contain at least 6 characters."
}]
})
});
let result = $state('');
</script>
<style>
.actions {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
output {
display: block;
margin-top: 16px;
color: var(--ant-color-text-secondary);
overflow-wrap: anywhere;
}
</style>
<Form {form} onFinish={values => { result = ("Saved: " + String((values.name)) + ""); }}>
<FormItem name="name" label={("Member name")} required>
<Input value={form.values.name} onValueChange={value => form.setFieldValue('name', value)} />
</FormItem>
<FormItem name="password" label={("Participant password")} required>
<InputPassword value={form.values.password} autoComplete="new-password"
onValueChange={value => form.setFieldValue('password', value)} />
</FormItem>
<FormItem name="description" label={("Note about the participant")}>
<TextArea value={form.values.description} autoSize={{ minRows: 2, maxRows: 4 }}
onValueChange={value => form.setFieldValue('description', value)} />
</FormItem>
<div class="actions">
<Button type="primary" htmlType="submit">{("Save member")}</Button>
<Button
htmlType="reset"
onclick={() => { result = ''; }}
>{("Reset form")}</Button>
</div>
<output aria-label={("Result of the Input form")}>{result}</output>
</Form>
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.
<script lang="ts">
import {
Checkbox,
ConfigProvider,
Input,
TextArea,
InputPassword,
InputSearch,
InputOTP
} from '@woodger/antd';
let custom = $state(true);
let local = $state(true);
const prefix = $derived(custom ? 'suite' : 'ant');
const localPrefix = $derived(local ? 'project-input' : '');
let draft = $state(("Draft field"));
let text = $state(("Several lines"));
let password = $state('secret');
let query = $state('Svelte');
let code = $state('1234');
let searched = $state('—');
</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 Input suite")}</Checkbox>
<Checkbox bind:checked={local}>{("Local prefix Input")}</Checkbox>
</div>
<ConfigProvider prefixCls={prefix} theme={{ cssVar: { prefix: 'input-theme' } }}>
<div class="prefix-stage">
<Input prefixCls={localPrefix} bind:value={draft} allowClear showCount
aria-label={("Input with prefix")} />
<TextArea prefixCls={localPrefix} bind:value={text} autoSize={{ minRows: 2, maxRows: 4 }}
aria-label={("TextArea with prefix")} />
<InputPassword prefixCls={local ? 'project-password' : ''} inputPrefixCls={localPrefix}
bind:value={password} aria-label={("Password with prefix")} />
<InputSearch prefixCls={local ? 'project-search' : ''} inputPrefixCls={localPrefix}
bind:value={query} enterButton={("Find")} onSearch={value => searched = value}
aria-label={("Search with prefix")} />
<InputOTP
prefixCls={local ? 'project-otp' : ''}
length={4}
value={code}
onChange={next => code = next}
aria-label={("OTP with prefix")}
/>
<output
aria-label={("Search Input with prefix")}
>{("Found: ")}{searched}</output>
</div>
</ConfigProvider>
<output
aria-label={("CSS prefix Input")}
>{("General: ")}{prefix}{("; local: ")}{(localPrefix
|| ("from the provider"))}</output>
<p>
{("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.")}
</p>
</div>
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
| 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. | InputProps['prefixCls'] | ant-input |
value | String value; supports bind:value. | InputProps['value'] | "" |
defaultValue | Initial value without binding. Subsequent changes do not reinitialize the field. | InputProps['defaultValue'] | — |
size | small, medium or large. Inherited from SpaceCompact or ConfigProvider. | InputProps['size'] | medium |
variant | outlined, filled, borderless or underlined. Local variant → closest Form.variant → input.variant → shared ConfigProvider.variant → outlined. | InputProps['variant'] | outlined |
status | error or warning; the state can also be set by FormItem. | InputProps['status'] | — |
prefix | Text, number or snippet before the value inside the field. | InputProps['prefix'] | — |
suffix | Content after the value inside the field. | InputProps['suffix'] | — |
allowClear | Clear button: boolean or clearIcon and disabled settings. | InputProps['allowClear'] | false |
showCount | Character counter or object with formatter. | InputProps['showCount'] | false |
count | Soft maximum, counting strategy, display and optional input trimming. The exact type is InputCountConfig. | InputProps['count'] | — |
maxLength | Hard native limit; without count.max specifies the maximum of the counter. | InputProps['maxLength'] | — |
onValueChange | Gets the string after input and clearing; bind:value has now been updated. | InputProps['onValueChange'] | — |
onChange | Compatible event with a copy of target/currentTarget and the original nativeEvent. Native oninput and onchange remain separate. | InputProps['onChange'] | — |
onClear | Called after onValueChange and onChange when clearing. | InputProps['onClear'] | — |
onPressEnter | Enter outside IME composition. Does not replace native onkeydown. | InputProps['onPressEnter'] | — |
classNames | Semantic slots classes: object or function from { props }. | InputProps['classNames'] | — |
styles | CSS strings for semantic slots: object or function from { props }. | InputProps['styles'] | — |
inputElement | bind:inputElement receives the native input, regardless of the presence of a wrapper. | InputProps['inputElement'] | — |
nativeElement | bind: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.
| Property | Description | Type | Default |
|---|---|---|---|
prefixCls | Full prefix for this part of the family; empty string/undefined select ConfigProvider. Internal Input and buttons retain independent namespace. | TextAreaProps['prefixCls'] | ant-input |
value | String with bind:value, including newlines. | TextAreaProps['value'] | "" |
autoSize | true or { minRows, maxRows }; the height is measured by the content or placeholder. | TextAreaProps['autoSize'] | false |
allowClear | Clearing a multi-line value. | TextAreaProps['allowClear'] | false |
count | Common soft limit, strategy and exceedFormatter rules with Input. | TextAreaProps['count'] | — |
onResize | Gets the measured width and height when resizing. | TextAreaProps['onResize'] | — |
nativeElement | bind:nativeElement always returns textarea. | TextAreaProps['nativeElement'] | — |
rootElement | bind: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.
| Property | Description | Type | Default |
|---|---|---|---|
inputPrefixCls | Full independent prefix of nested Input; is not output from prefixCls shell. The empty string/undefined inherits the common Input prefix. | InputPasswordProps['inputPrefixCls'] | ant-input |
prefixCls | Full prefix for this part of the family; empty string/undefined select ConfigProvider. Internal Input and buttons retain independent namespace. | InputPasswordProps['prefixCls'] | ant-input-password |
visibilityToggle | true by default; false hides the radio button. An object with visible and onVisibleChange controls visibility from the outside. | InputPasswordProps['visibilityToggle'] | true |
iconRender | The visibility function returns the text or Svelte snippet for the radio button. | InputPasswordProps['iconRender'] | — |
action | click by default; hover changes visibility when hovering, but leaving the mouse does not return it. | InputPasswordProps['action'] | click |
suffix | Additional 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.
| Property | Description | Type | Default |
|---|---|---|---|
inputPrefixCls | Full independent prefix of nested Input; is not output from prefixCls shell. The empty string/undefined inherits the common Input prefix. | InputSearchProps['inputPrefixCls'] | ant-input |
prefixCls | Full prefix for this part of the family; empty string/undefined select ConfigProvider. Internal Input and buttons retain independent namespace. | InputSearchProps['prefixCls'] | ant-input-search |
enterButton | false - regular icon, true - main button, line - label. Snippet gets context getButtonProps/getNativeProps. | InputSearchProps['enterButton'] | false |
searchIcon | Icon for boolean enterButton; null or false hide it. | InputSearchProps['searchIcon'] | — |
loading | Locks the button and search by Enter, maintaining the availability of cleaning. | InputSearchProps['loading'] | false |
onSearch | Gets the value, event and info.source: input or clear. Cleanup calls onSearch before onChange. | InputSearchProps['onSearch'] | — |
classNames | Input and button slots: class string or Button slots object. | InputSearchProps['classNames'] | — |
styles | Input and button slots; For a button, you can pass an object of CSS strings root, icon and content. | InputSearchProps['styles'] | — |
Input.OTP
| Property | Description | Type | Default |
|---|---|---|---|
prefixCls | Full prefix for this part of the family; empty string/undefined select ConfigProvider. Internal Input and buttons retain independent namespace. | InputOTPProps['prefixCls'] | ant-otp |
length | Number of cells, default 6. | InputOTPProps['length'] | 6 |
defaultValue | Initial value also used for SSR; formatter is applied once. | InputOTPProps['defaultValue'] | "" |
value | Changing prop synchronizes cells after mount. bind:value not provided; use onInput and onChange. | InputOTPProps['value'] | — |
formatter | Converts the entire string with spaces in place of empty cells before the length limit. | InputOTPProps['formatter'] | — |
mask | true hides symbols with dots; the line specifies its own mask. The original value is retained. | InputOTPProps['mask'] | false |
separator | Contents between cells or a function of the index. For rich content the function returns snippet. | InputOTPProps['separator'] | — |
onInput | Gets an array of cells on every input, including empty positions. | InputOTPProps['onInput'] | — |
onChange | Called only for changed fully filled code; incomplete input does not trigger a callback. | InputOTPProps['onChange'] | — |
inputMode | Native virtual keyboard tooltip; does not itself limit input to numbers. | InputOTPProps['inputMode'] | — |
nativeElement | bind: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
allowClearautoCompletevariantclassstyleclassNamesstylesConfigProvider.textArea
allowClearautoCompletevariantclassstyleclassNamesstylesConfigProvider.inputPassword
iconRendervariantclassstyleclassNamesstylesConfigProvider.inputSearch
searchIconvariantclassstyleclassNamesstylesConfigProvider.otp
variantclassstyleclassNamesstylesFor 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.
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>
| 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 | Background of external additions. |
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. |
Common tokens of the current topic
Values obtained via theme.useToken() and are updated 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
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.