Part of the Ant Design ecosystem.
📦 ⌨️ Low-level React input primitives for building polished text fields and textareas.
English | 简体中文
- Composable
Input,TextArea, andBaseInputprimitives. - Affix, addon, clear icon, prefix, suffix, and character count support.
- Autosizing textarea with resize callbacks and imperative refs.
- TypeScript definitions and semantic
classNames/stylesslots. - Used by Ant Design as the shared input foundation.
npm install @rc-component/inputimport Input from '@rc-component/input';
export default () => <Input allowClear placeholder="Type something" />;import { TextArea } from '@rc-component/input';
export default () => <TextArea autoSize showCount maxLength={100} />;Run the local dumi site:
npm install
npm startThen open http://localhost:8000.
| Property | Type | Default | Description |
|---|---|---|---|
| addonAfter | ReactNode |
- | Element displayed after the input. |
| addonBefore | ReactNode |
- | Element displayed before the input. |
| allowClear | boolean | { disabled?: boolean; clearIcon?: ReactNode } |
false |
Show a clear button for the current value. |
| className | string |
- | Class name for the input element. |
| classNames | InputProps['classNames'] |
- | Semantic class names for input slots. |
| count | CountConfig |
- | Custom count strategy, limit, visibility, and exceed formatter. |
| defaultValue | string | number | readonly string[] | bigint |
- | Initial input value. |
| disabled | boolean |
false |
Disable the input. |
| htmlSize | number |
- | Native input size attribute. |
| maxLength | number |
- | Native input maxLength attribute. |
| prefix | ReactNode |
- | Prefix content inside the input wrapper. |
| prefixCls | string |
rc-input |
Class name prefix. |
| showCount | boolean | { formatter: ShowCountFormatter } |
false |
Show character count. Prefer count.show for new code. |
| styles | InputProps['styles'] |
- | Semantic styles for input slots. |
| suffix | ReactNode |
- | Suffix content inside the input wrapper. |
| type | InputProps['type'] |
text |
Native input type. Use TextArea for textarea behavior. |
| value | string | number | readonly string[] | bigint |
- | Controlled input value. |
| onChange | React.ChangeEventHandler<HTMLInputElement> |
- | Triggered when the value changes. |
| onClear | () => void |
- | Triggered when the clear button is clicked. |
| onPressEnter | React.KeyboardEventHandler<HTMLInputElement> |
- | Triggered when Enter is pressed. |
| Property | Type | Default | Description |
|---|---|---|---|
| allowClear | boolean | { disabled?: boolean; clearIcon?: ReactNode } |
false |
Show a clear button for the current value. |
| autoSize | boolean | { minRows?: number; maxRows?: number } |
false |
Auto resize height by content. |
| className | string |
- | Class name for the textarea. |
| classNames | TextAreaProps['classNames'] |
- | Semantic class names for textarea slots. |
| count | CountConfig |
- | Custom count strategy, limit, visibility, and exceed formatter. |
| defaultValue | string | number | readonly string[] | bigint |
- | Initial textarea value. |
| maxLength | number |
- | Native textarea maxLength attribute. |
| prefixCls | string |
rc-textarea |
Class name prefix. |
| showCount | boolean | { formatter: ShowCountFormatter } |
false |
Show character count. Prefer count.show for new code. |
| style | React.CSSProperties |
- | Inline styles for the textarea. |
| styles | TextAreaProps['styles'] |
- | Semantic styles for textarea slots. |
| suffix | ReactNode |
- | Suffix content inside the textarea wrapper. |
| value | string | number | readonly string[] | bigint |
- | Controlled textarea value. |
| onChange | React.ChangeEventHandler<HTMLTextAreaElement> |
- | Triggered when the value changes. |
| onClear | () => void |
- | Triggered when the clear button is clicked. |
| onPressEnter | React.KeyboardEventHandler<HTMLTextAreaElement> |
- | Triggered when Enter is pressed. |
| onResize | (size: { width: number; height: number }) => void |
- | Triggered when textarea size changes. |
import type { InputRef, TextAreaRef } from '@rc-component/input';
function focusInput(inputRef: InputRef | null) {
inputRef?.focus();
}
function blurTextArea(textareaRef: TextAreaRef | null) {
textareaRef?.blur();
}| Ref | Methods |
|---|---|
InputRef |
focus(options), blur(), select(), setSelectionRange(), input, nativeElement |
TextAreaRef |
focus(), blur(), resizableTextArea, nativeElement |
npm install
npm start
npm test
npm run tsc
npm run compile
npm run buildThe dumi site runs at http://localhost:8000 by default.
npm run prepublishOnlyThe release flow is handled by @rc-component/np through the rc-np command after the package build.
@rc-component/input is released under the MIT license.