From a1a907dcb2e797baded671fe5d3d48a9a55bcf21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E8=89=B3=E5=85=B5?= Date: Wed, 18 Mar 2026 09:31:07 +0800 Subject: [PATCH 01/10] feat: migrate textarea implementation into rc-input --- README.md | 103 +++- assets/index.less | 22 + docs/demo/textarea.md | 22 + docs/examples/textarea-allow-clear.tsx | 25 + docs/examples/textarea-auto-size.tsx | 39 ++ docs/examples/textarea-basic.tsx | 40 ++ docs/examples/textarea-show-count.tsx | 57 ++ package.json | 1 + src/ResizableTextArea.tsx | 166 ++++++ src/TextArea.tsx | 273 ++++++++++ src/calculateNodeHeight.tsx | 185 +++++++ src/index.tsx | 23 +- src/interface.ts | 44 ++ tests/ResizableTextArea.test.tsx | 23 + tests/TextArea.allowClear.test.tsx | 143 +++++ tests/TextArea.count.test.tsx | 152 ++++++ tests/TextArea.focus.test.tsx | 96 ++++ tests/TextArea.showCount.test.tsx | 79 +++ tests/TextArea.test.tsx | 487 ++++++++++++++++++ .../TextArea.allowClear.test.tsx.snap | 127 +++++ tests/__snapshots__/TextArea.test.tsx.snap | 72 +++ tests/setupFilesAfterEnv.js | 9 + tests/utils.ts | 32 ++ 23 files changed, 2192 insertions(+), 28 deletions(-) create mode 100644 docs/demo/textarea.md create mode 100644 docs/examples/textarea-allow-clear.tsx create mode 100644 docs/examples/textarea-auto-size.tsx create mode 100644 docs/examples/textarea-basic.tsx create mode 100644 docs/examples/textarea-show-count.tsx create mode 100644 src/ResizableTextArea.tsx create mode 100644 src/TextArea.tsx create mode 100644 src/calculateNodeHeight.tsx create mode 100644 tests/ResizableTextArea.test.tsx create mode 100644 tests/TextArea.allowClear.test.tsx create mode 100644 tests/TextArea.count.test.tsx create mode 100644 tests/TextArea.focus.test.tsx create mode 100644 tests/TextArea.showCount.test.tsx create mode 100644 tests/TextArea.test.tsx create mode 100644 tests/__snapshots__/TextArea.allowClear.test.tsx.snap create mode 100644 tests/__snapshots__/TextArea.test.tsx.snap create mode 100644 tests/utils.ts diff --git a/README.md b/README.md index 6200c41..5f44699 100644 --- a/README.md +++ b/README.md @@ -39,31 +39,61 @@ import { render } from 'react-dom'; render(, mountNode); ``` +```js +import Input from '@rc-component/input'; +import { render } from 'react-dom'; + +render(, mountNode); +``` + ## API -| Property | Type | Default | Description | -| --------------------- | ---------------------------------------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| prefixCls | string | rc-input | | -| className | string | '' | additional class name of input | -| style | React.CSSProperties | | style properties of input | -| affixWrapperClassName | string | - | className with '@rc-component/input-affix-wrapper' | -| groupClassName | string | - | className with '@rc-component/input-group-wrapper' | -| wrapperClassName | string | - | className with '@rc-component/input-wrapper' | -| addonAfter | ReactNode | - | The label text displayed after (on the right side of) the input field | -| addonBefore | ReactNode | - | The label text displayed before (on the left side of) the input field | -| allowClear | boolean | { clearIcon: ReactNode } | false | If allow to remove input content with clear icon | -| bordered | boolean | true | Whether has border style | -| defaultValue | string | - | The initial input content | -| disabled | boolean | false | Whether the input is disabled | -| id | string | - | The ID for input | -| maxLength | number | - | The max length | +| Property | Type | Default | Description | +| --------------------- | ------------------------------------------------------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| prefixCls | string | rc-input | | +| className | string | '' | additional class name of input | +| style | React.CSSProperties | | style properties of input | +| affixWrapperClassName | string | - | className with '@rc-component/input-affix-wrapper' | +| groupClassName | string | - | className with '@rc-component/input-group-wrapper' | +| wrapperClassName | string | - | className with '@rc-component/input-wrapper' | +| addonAfter | ReactNode | - | The label text displayed after (on the right side of) the input field | +| addonBefore | ReactNode | - | The label text displayed before (on the left side of) the input field | +| allowClear | boolean | { clearIcon: ReactNode } | false | If allow to remove input content with clear icon | +| bordered | boolean | true | Whether has border style | +| defaultValue | string | - | The initial input content | +| disabled | boolean | false | Whether the input is disabled | +| id | string | - | The ID for input | +| maxLength | number | - | The max length | | showCount | boolean | { formatter: ({ value: string, count: number, maxLength?: number }) => ReactNode } | false | Whether show text count | -| prefix | ReactNode | - | The prefix icon for the Input | -| suffix | ReactNode | - | The suffix icon for the Input | -| type | string | `text` | The type of input, see: [MDN](https://developer.mozilla.org/docs/Web/HTML/Element/input#Form_%3Cinput%3E_types)( use `Input.TextArea` instead of `type="textarea"`) | -| value | string | - | The input content value | -| onChange | function(e) | - | Callback when user input | -| onPressEnter | function(e) | - | The callback function that is triggered when Enter key is pressed | +| prefix | ReactNode | - | The prefix icon for the Input | +| suffix | ReactNode | - | The suffix icon for the Input | +| type | string | `text` | The type of input, see: [MDN](https://developer.mozilla.org/docs/Web/HTML/Element/input#Form_%3Cinput%3E_types)( use `Input.TextArea` instead of `type="textarea"`) | +| value | string | - | The input content value | +| onChange | function(e) | - | Callback when user input | +| onPressEnter | function(e) | - | The callback function that is triggered when Enter key is pressed | + +## TextArea + +`rc-textarea` has been migrated into `@rc-component/input`. Use `Input.TextArea` or the named `TextArea` export for all textarea-related features. + +```js +import Input, { TextArea } from '@rc-component/input'; + +; + + + + suffix + + 3 + + + + +