Skip to content

Repository files navigation

@rc-component/input

Ant Design Part of the Ant Design ecosystem.

📦 ⌨️ Low-level React input primitives for building polished text fields and textareas.

NPM versionnpm downloadsbuild statusCodecovbundle sizedumi

English | 简体中文

Highlights

  • Composable Input, TextArea, and BaseInput primitives.
  • Affix, addon, clear icon, prefix, suffix, and character count support.
  • Autosizing textarea with resize callbacks and imperative refs.
  • TypeScript definitions and semantic classNames / styles slots.
  • Used by Ant Design as the shared input foundation.

Install

npm install @rc-component/input

Usage

importInputfrom'@rc-component/input';exportdefault()=><InputallowClearplaceholder="Type something"/>;
import{TextArea}from'@rc-component/input';exportdefault()=><TextAreaautoSizeshowCountmaxLength={100}/>;

Examples

Run the local dumi site:

npm install
npm start

Then open http://localhost:8000.

API

Input

PropertyTypeDefaultDescription
addonAfterReactNode-Element displayed after the input.
addonBeforeReactNode-Element displayed before the input.
allowClearboolean | { disabled?: boolean; clearIcon?: ReactNode }falseShow a clear button for the current value.
classNamestring-Class name for the input element.
classNamesInputProps['classNames']-Semantic class names for input slots.
countCountConfig-Custom count strategy, limit, visibility, and exceed formatter.
defaultValuestring | number | readonly string[] | bigint-Initial input value.
disabledbooleanfalseDisable the input.
htmlSizenumber-Native input size attribute.
maxLengthnumber-Native input maxLength attribute.
prefixReactNode-Prefix content inside the input wrapper.
prefixClsstringrc-inputClass name prefix.
showCountboolean | { formatter: ShowCountFormatter }falseShow character count. Prefer count.show for new code.
stylesInputProps['styles']-Semantic styles for input slots.
suffixReactNode-Suffix content inside the input wrapper.
typeInputProps['type']textNative input type. Use TextArea for textarea behavior.
valuestring | number | readonly string[] | bigint-Controlled input value.
onChangeReact.ChangeEventHandler<HTMLInputElement>-Triggered when the value changes.
onClear() => void-Triggered when the clear button is clicked.
onPressEnterReact.KeyboardEventHandler<HTMLInputElement>-Triggered when Enter is pressed.

TextArea

PropertyTypeDefaultDescription
allowClearboolean | { disabled?: boolean; clearIcon?: ReactNode }falseShow a clear button for the current value.
autoSizeboolean | { minRows?: number; maxRows?: number }falseAuto resize height by content.
classNamestring-Class name for the textarea.
classNamesTextAreaProps['classNames']-Semantic class names for textarea slots.
countCountConfig-Custom count strategy, limit, visibility, and exceed formatter.
defaultValuestring | number | readonly string[] | bigint-Initial textarea value.
maxLengthnumber-Native textarea maxLength attribute.
prefixClsstringrc-textareaClass name prefix.
showCountboolean | { formatter: ShowCountFormatter }falseShow character count. Prefer count.show for new code.
styleReact.CSSProperties-Inline styles for the textarea.
stylesTextAreaProps['styles']-Semantic styles for textarea slots.
suffixReactNode-Suffix content inside the textarea wrapper.
valuestring | number | readonly string[] | bigint-Controlled textarea value.
onChangeReact.ChangeEventHandler<HTMLTextAreaElement>-Triggered when the value changes.
onClear() => void-Triggered when the clear button is clicked.
onPressEnterReact.KeyboardEventHandler<HTMLTextAreaElement>-Triggered when Enter is pressed.
onResize(size: { width: number; height: number }) => void-Triggered when textarea size changes.

Refs

importtype{InputRef,TextAreaRef}from'@rc-component/input';functionfocusInput(inputRef: InputRef|null){inputRef?.focus();}functionblurTextArea(textareaRef: TextAreaRef|null){textareaRef?.blur();}
RefMethods
InputReffocus(options), blur(), select(), setSelectionRange(), input, nativeElement
TextAreaReffocus(), blur(), resizableTextArea, nativeElement

Development

npm install
npm start
npm test
npm run tsc
npm run compile
npm run build

The dumi site runs at http://localhost:8000 by default.

Release

npm run prepublishOnly

The release flow is handled by @rc-component/np through the rc-np command after the package build.

License

@rc-component/input is released under the MIT license.

About

📦 ⌨️ Low-level React input primitives for building polished text fields and textareas.

Topics

Resources

Stars

44 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages

Generated from react-component/footer