From ee379144502738eaec28ec29354acc3c386ee049 Mon Sep 17 00:00:00 2001 From: Rylan Date: Mon, 9 Nov 2026 17:24:50 +0800 Subject: [PATCH 01/13] feat(Textarea): support `clearable` --- packages/common | 2 +- .../config-provider/config-provider.en-US.md | 134 ++++++++++-------- .../config-provider/config-provider.md | 14 +- packages/components/config-provider/type.ts | 41 ++++-- packages/components/textarea/Textarea.tsx | 72 +++++++++- .../textarea/__tests__/textarea.test.tsx | 72 ++++++++++ .../textarea/_example/clearable.tsx | 38 +++++ packages/components/textarea/defaultProps.ts | 1 + .../components/textarea/textarea.en-US.md | 1 + packages/components/textarea/textarea.md | 1 + packages/components/textarea/type.ts | 10 ++ 11 files changed, 302 insertions(+), 84 deletions(-) create mode 100644 packages/components/textarea/_example/clearable.tsx diff --git a/packages/common b/packages/common index a338eec873..791aedfa61 160000 --- a/packages/common +++ b/packages/common @@ -1 +1 @@ -Subproject commit a338eec8732d2fe9cb200007d482de5dde844597 +Subproject commit 791aedfa6188cd6ac3744654107bbbaab79ada16 diff --git a/packages/components/config-provider/config-provider.en-US.md b/packages/components/config-provider/config-provider.en-US.md index 6865d89170..7b34aeffcd 100644 --- a/packages/components/config-provider/config-provider.en-US.md +++ b/packages/components/config-provider/config-provider.en-US.md @@ -58,50 +58,51 @@ const globalConfig: GlobalConfigProvider = { name | type | default | description | required -- | -- | -- | -- | -- -globalConfig | Object | - | global config。Typescript: `GlobalConfigProvider` | N +globalConfig | Object | - | global config. Typescript: `GlobalConfigProvider` | N ### GlobalConfigProvider name | type | default | description | required -- | -- | -- | -- | -- -alert | Object | - | Alert global configs。Typescript: `AlertConfig` | N -anchor | Object | - | Anchor global configs。Typescript: `AnchorConfig` | N -animation | Object | - | Typescript: `Partial>>` `type AnimationType = 'ripple' \| 'expand' \| 'fade'`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N -attach | String / Object / Function | - | Typescript: `AttachNode \| { imageViewer?: AttachNode; popup?: AttachNode; dialog?: AttachNode; drawer?: AttachNode; }`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N -autoComplete | Object | - | AutoComplete global configs。Typescript: `AutoCompleteConfig` | N -calendar | Object | - | Calendar global configs。Typescript: `CalendarConfig` | N -cascader | Object | - | Cascader global configs。Typescript: `CascaderConfig` | N +alert | Object | - | Alert global configs. Typescript: `AlertConfig` | N +anchor | Object | - | Anchor global configs. Typescript: `AnchorConfig` | N +animation | Object | - | Typescript: `Partial>>` `type AnimationType = 'ripple' \| 'expand' \| 'fade'`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N +attach | String / Object / Function | - | Popup container, configured for all overlays or separately for imageViewer, popup, dialog and drawer. The component attach prop takes precedence. Unconfigured components retain their default mounting behavior. Typescript: `AttachNode \| { imageViewer?: AttachNode; popup?: AttachNode; dialog?: AttachNode; drawer?: AttachNode; }`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +autoComplete | Object | - | AutoComplete global configs. Typescript: `AutoCompleteConfig` | N +calendar | Object | - | Calendar global configs. Typescript: `CalendarConfig` | N +cascader | Object | - | Cascader global configs. Typescript: `CascaderConfig` | N classPrefix | String | t | \- | N -colorPicker | Object | - | ColorPicker global configs。Typescript: `ColorPickerConfig` | N -datePicker | Object | - | DatePicker global configs。Typescript: `DatePickerConfig` | N -descriptions | Object | - | Descriptions global configs。Typescript: `DescriptionsConfig` | N -dialog | Object | - | Dialog global configs。Typescript: `DialogConfig` | N -drawer | Object | - | Drawer global configs。Typescript: `DrawerConfig` | N -empty | Object | - | Empty global configs。Typescript: `EmptyConfig` | N -form | Object | - | Form global configs。Typescript: `FormConfig` | N -guide | Object | - | Guide global configs。Typescript: `GuideConfig` | N -icon | Object | - | icon config。Typescript: `IconConfig` `type IconConfig = GlobalIconConfig` `import { GlobalIconConfig } from '@icon'`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N -image | Object | - | image global configs。Typescript: `ImageConfig` | N -imageViewer | Object | - | imageViewer global configs。Typescript: `ImageViewerConfig` | N -input | Object | - | Input global configs。Typescript: `InputConfig` | N +colorPicker | Object | - | ColorPicker global configs. Typescript: `ColorPickerConfig` | N +datePicker | Object | - | DatePicker global configs. Typescript: `DatePickerConfig` | N +descriptions | Object | - | Descriptions global configs. Typescript: `DescriptionsConfig` | N +dialog | Object | - | Dialog global configs. Typescript: `DialogConfig` | N +drawer | Object | - | Drawer global configs. Typescript: `DrawerConfig` | N +empty | Object | - | Empty global configs. Typescript: `EmptyConfig` | N +form | Object | - | Form global configs. Typescript: `FormConfig` | N +guide | Object | - | Guide global configs. Typescript: `GuideConfig` | N +icon | Object | - | icon config. Typescript: `IconConfig` `type IconConfig = GlobalIconConfig` `import { GlobalIconConfig } from '@icon'`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N +image | Object | - | image global configs. Typescript: `ImageConfig` | N +imageViewer | Object | - | imageViewer global configs. Typescript: `ImageViewerConfig` | N +input | Object | - | Input global configs. Typescript: `InputConfig` | N isContextEffectPlugin | Boolean | false | Whether the global configuration affects the components used by the functional invocation method | N -list | Object | - | List global configs。Typescript: `ListConfig` | N -loading | Object | - | Loading global configs。Typescript: `LoadingConfig` | N -message | Object | - | Message Component global configs。Typescript: `MessageConfig` | N -pagination | Object | - | Pagination global configs。Typescript: `PaginationConfig` | N -popconfirm | Object | - | Popconfirm global configs。Typescript: `PopconfirmConfig` | N -qrcode | Object | - | QRCode global configs。Typescript: `QRCodeConfig` | N -rate | Object | - | Rate global configs。Typescript: `RateConfig` | N -select | Object | - | Select global configs。Typescript: `SelectConfig` | N -steps | Object | - | Steps global configs。Typescript: `StepsConfig` | N -table | Object | - | Table global configs。Typescript: `TableConfig` | N -tag | Object | - | Tag global configs。Typescript: `TagConfig` | N -timePicker | Object | - | TimePicker global configs。Typescript: `TimePickerConfig` | N -transfer | Object | - | Transfer global configs。Typescript: `TransferConfig` | N -tree | Object | - | Tree global configs。Typescript: `TreeConfig` | N -treeSelect | Object | - | TreeSelect global configs。Typescript: `TreeSelectConfig` | N -typography | Object | - | Typography global configs。Typescript: `TypographyConfig` | N -upload | Object | - | Upload global configs。Typescript: `UploadConfig` | N +list | Object | - | List global configs. Typescript: `ListConfig` | N +loading | Object | - | Loading global configs. Typescript: `LoadingConfig` | N +message | Object | - | Message Component global configs. Typescript: `MessageConfig` | N +pagination | Object | - | Pagination global configs. Typescript: `PaginationConfig` | N +popconfirm | Object | - | Popconfirm global configs. Typescript: `PopconfirmConfig` | N +qrcode | Object | - | QRCode global configs. Typescript: `QRCodeConfig` | N +rate | Object | - | Rate global configs. Typescript: `RateConfig` | N +select | Object | - | Select global configs. Typescript: `SelectConfig` | N +steps | Object | - | Steps global configs. Typescript: `StepsConfig` | N +table | Object | - | Table global configs. Typescript: `TableConfig` | N +tag | Object | - | Tag global configs. Typescript: `TagConfig` | N +textarea | Object | - | Textarea global configs. Typescript: `TextareaConfig` | N +timePicker | Object | - | TimePicker global configs. Typescript: `TimePickerConfig` | N +transfer | Object | - | Transfer global configs. Typescript: `TransferConfig` | N +tree | Object | - | Tree global configs. Typescript: `TreeConfig` | N +treeSelect | Object | - | TreeSelect global configs. Typescript: `TreeSelectConfig` | N +typography | Object | - | Typography global configs. Typescript: `TypographyConfig` | N +upload | Object | - | Upload global configs. Typescript: `UploadConfig` | N ### AlertConfig @@ -128,7 +129,7 @@ empty | String | - | \- | N name | type | default | description | required -- | -- | -- | -- | -- cellMonth | String | - | \- | N -controllerConfig | Object | - | Typescript: `CalendarController`,[Calendar API Documents](./calendar?tab=api)。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N +controllerConfig | Object | - | Typescript: `CalendarController`,[Calendar API Documents](./calendar?tab=api). [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N fillWithZero | Boolean | true | \- | N firstDayOfWeek | Number | 1 | options: 1/2/3/4/5/6/7 | N hideWeekend | String | - | \- | N @@ -176,8 +177,8 @@ now | String | - | now text | N placeholder | Object | - | Typescript: `{ date?: string; month?: string; year?: string }` | N preDecade | String | - | pre decade text | N preMonth | String | - | pre month text | N +presets | Object | - | Typescript: `ConfigPresetDate` `interface ConfigPresetDate { [name: string]: DateConfigValue \| (() => DateConfigValue) }` `type DateConfigValue = string \| Date \| Array`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N preYear | String | - | pre year text | N -presets | Object | - | Typescript: `ConfigPresetDate` `interface ConfigPresetDate { [name: string]: DateConfigValue \| (() => DateConfigValue) }` `type DateConfigValue = string \| Date \| Array`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N quarters | Array | - | Typescript: `string[]` | N rangeSeparator | String | - | range separator text | N selectDate | String | - | select date text | N @@ -196,7 +197,7 @@ colonText | String | - | colon on the right of label, ":" | N name | type | default | description | required -- | -- | -- | -- | -- -cancel | Object | - | Typescript: `string \| ButtonProps`,[Button API Documents](./button?tab=api)。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N +cancel | Object | - | Typescript: `string \| ButtonProps`,[Button API Documents](./button?tab=api). [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N closeOnEscKeydown | Boolean | true | trigger dialog close on `ESC` keydown | N closeOnOverlayClick | Boolean | true | \- | N confirm | Object | - | Typescript: `string \| ButtonProps` | N @@ -218,7 +219,7 @@ size | String | 'small' | \- | N name | type | default | description | required -- | -- | -- | -- | -- -image | Object | - | Typescript: `{ maintenance: TNode; success: TNode; fail: TNode; empty: TNode; networkError: TNode; }`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +image | Object | - | Typescript: `{ maintenance: TNode; success: TNode; fail: TNode; empty: TNode; networkError: TNode; }`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N titleText | Object | - | Typescript: `{ maintenance: string; success: string; fail: string; empty: string; networkError: string; }` | N ### FormConfig @@ -226,18 +227,18 @@ titleText | Object | - | Typescript: `{ maintenance: string; success: string; fa name | type | default | description | required -- | -- | -- | -- | -- colonText | String | - | colon on the right of label ":" | N -errorMessage | Object | - | Typescript: `FormErrorMessage`,[Form API Documents](./form?tab=api)。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N +errorMessage | Object | - | Typescript: `FormErrorMessage`,[Form API Documents](./form?tab=api). [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N requiredMark | Boolean | true | \- | N -requiredMarkPosition | String | left | Display position of required symbols。options: left/right | N +requiredMarkPosition | String | left | Display position of required symbols. options: left/right | N ### GuideConfig name | type | default | description | required -- | -- | -- | -- | -- -finishButtonProps | Object | - | finish button in last step. `{ content: 'Finish', theme: 'primary' }`。Typescript: `ButtonProps` | N -nextButtonProps | Object | - | next step button. `{ content: 'Next Button', theme: 'primary' }`。Typescript: `ButtonProps` | N -prevButtonProps | Object | - | previous step button. `{ content: 'Previous Step', theme: 'default' }`。Typescript: `ButtonProps` | N -skipButtonProps | Object | - | skip button. `{ content: 'Skip', theme: 'default' }`。Typescript: `ButtonProps` | N +finishButtonProps | Object | - | finish button in last step. `{ content: 'Finish', theme: 'primary' }`. Typescript: `ButtonProps` | N +nextButtonProps | Object | - | next step button. `{ content: 'Next Button', theme: 'primary' }`. Typescript: `ButtonProps` | N +prevButtonProps | Object | - | previous step button. `{ content: 'Previous Step', theme: 'default' }`. Typescript: `ButtonProps` | N +skipButtonProps | Object | - | skip button. `{ content: 'Skip', theme: 'default' }`. Typescript: `ButtonProps` | N ### ImageConfig @@ -245,7 +246,7 @@ name | type | default | description | required -- | -- | -- | -- | -- errorText | String | - | loading text, default value is "Error" | N loadingText | String | - | loading text, default value is "loading" | N -replaceImageSrc | Function | - | replace all `src` attribute of images。Typescript: `(params: ImageProps) => string`,[Image API Documents](./image?tab=api)。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N +replaceImageSrc | Function | - | replace all `src` attribute of images. Typescript: `(params: ImageProps) => string`,[Image API Documents](./image?tab=api). [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N ### ImageViewerConfig @@ -262,7 +263,7 @@ rotateTipText | String | - | rotate operation text | N name | type | default | description | required -- | -- | -- | -- | -- autocomplete | String | - | \- | N -clearTrigger | String | focus | Trigger to show a clear icon, valid when the input has a value。options: always / focus | N +clearTrigger | String | focus | Trigger to show a clear icon, valid when the input has a value. options: always / focus | N placeholder | String | - | \- | N ### ListConfig @@ -296,13 +297,13 @@ total | String | - | \- | N name | params | return | description -- | -- | -- | -- -jumper | `(jumperProps: JumperProps)` | `TNode` | [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts)。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts)。
`interface JumperProps { current: number; pageCount: number; onChange: (current: number) => void; }`
+jumper | `(jumperProps: JumperProps)` | `TNode` | [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts). [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts).
`interface JumperProps { current: number; pageCount: number; onChange: (current: number) => void; }`
### PopconfirmConfig name | type | default | description | required -- | -- | -- | -- | -- -cancel | String / Object | - | Typescript: `string \| ButtonProps`,[Button API Documents](./button?tab=api)。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N +cancel | String / Object | - | Typescript: `string \| ButtonProps`,[Button API Documents](./button?tab=api). [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N confirm | String / Object | - | Typescript: `string \| ButtonProps` | N confirmBtnTheme | Object | - | Typescript: `{ default: string; warning: string; danger: string; }` | N @@ -324,7 +325,7 @@ rateText | Array | - | Typescript: `string[]` | N name | type | default | description | required -- | -- | -- | -- | -- -clearIcon | Function | - | Typescript: `TNode`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +clearIcon | Function | - | Typescript: `TNode`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N empty | String | - | \- | N filterable | Boolean | false | \- | N loadingText | String | - | \- | N @@ -334,8 +335,8 @@ placeholder | String | - | placeholder text | N name | type | default | description | required -- | -- | -- | -- | -- -checkIcon | TElement | - | Typescript: `TNode`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N -errorIcon | TElement | - | Typescript: `TNode`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +checkIcon | TElement | - | Typescript: `TNode`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +errorIcon | TElement | - | Typescript: `TNode`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N ### TableConfig @@ -347,27 +348,34 @@ columnConfigButtonText | String | - | \- | N columnConfigDescriptionText | String | - | \- | N columnConfigTitleText | String | - | \- | N confirmText | String | - | \- | N -empty | TNode | - | Typescript: `string \| TNode`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N -expandIcon | TElement | undefined | Typescript: `TNode`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N -filterIcon | TElement | undefined | Typescript: `TNode`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +empty | TNode | - | Typescript: `string \| TNode`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +expandIcon | TElement | undefined | Typescript: `TNode`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +filterIcon | TElement | undefined | Typescript: `TNode`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N hideSortTips | Boolean | false | hide sort tips | N loadingMoreText | String | - | \- | N loadingText | String | - | \- | N resetText | String | - | \- | N searchResultText | String | - | \- | N selectAllText | String | - | \- | N -size | String | medium | options: small/medium/large。Typescript: `SizeEnum`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +size | String | medium | options: small/medium/large. Typescript: `SizeEnum`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N sortAscendingOperationText | String | - | \- | N sortCancelOperationText | String | - | \- | N sortDescendingOperationText | String | - | \- | N -sortIcon | TElement | undefined | Typescript: `TNode`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N -treeExpandAndFoldIcon | Function | undefined | Typescript: `TNode<{ type: 'expand' \| 'fold' }>`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +sortIcon | TElement | undefined | Typescript: `TNode`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +treeExpandAndFoldIcon | Function | undefined | Typescript: `TNode<{ type: 'expand' \| 'fold' }>`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N ### TagConfig name | type | default | description | required -- | -- | -- | -- | -- -closeIcon | Function | - | Typescript: `TNode`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +closeIcon | Function | - | Typescript: `TNode`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N + +### TextareaConfig + +name | type | default | description | required +-- | -- | -- | -- | -- +clearText | String | - | Clear button text | N +clearTrigger | String | focus | Trigger to show the clear button, valid when the textarea has a value. options: always/focus | N ### TimePickerConfig @@ -392,7 +400,7 @@ title | String | - | \- | N name | type | default | description | required -- | -- | -- | -- | -- empty | String | - | \- | N -folderIcon | Function | - | Typescript: `TNode`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +folderIcon | Function | - | Typescript: `TNode`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N ### TreeSelectConfig @@ -419,7 +427,7 @@ dragger | Object | - | Typescript: `UploadConfigDragger` | N file | Object | - | Typescript: `UploadConfigFileList` | N progress | Object | - | Typescript: `UploadConfigProgress` | N sizeLimitMessage | String | - | \- | N -triggerUploadText | Object | - | Typescript: `UploadTriggerUploadText` `interface UploadTriggerUploadText { image?: string, normal?: string, fileInput?: string, reupload?: string, continueUpload?: string, delete?: string }`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N +triggerUploadText | Object | - | Typescript: `UploadTriggerUploadText` `interface UploadTriggerUploadText { image?: string, normal?: string, fileInput?: string, reupload?: string, continueUpload?: string, delete?: string }`. [see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N ### UploadConfigDragger diff --git a/packages/components/config-provider/config-provider.md b/packages/components/config-provider/config-provider.md index 0d41645bca..e572c74e09 100644 --- a/packages/components/config-provider/config-provider.md +++ b/packages/components/config-provider/config-provider.md @@ -67,7 +67,7 @@ globalConfig | Object | - | 全局配置。TS 类型:`GlobalConfigProvider` | alert | Object | - | 警告全局配置。TS 类型:`AlertConfig` | N anchor | Object | - | 锚点全局配置。TS 类型:`AnchorConfig` | N animation | Object | - | 动画效果控制,`ripple` 指波纹动画, `expand` 指展开动画,`fade` 指渐变动画。默认为 `{ include: ['ripple','expand','fade'], exclude: [] }`。TS 类型:`Partial>>` `type AnimationType = 'ripple' \| 'expand' \| 'fade'`。[详细类型定义](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N -attach | String / Object / Function | - | TS 类型:`AttachNode \| { imageViewer?: AttachNode; popup?: AttachNode; dialog?: AttachNode; drawer?: AttachNode; }`。[通用类型定义](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +attach | String / Object / Function | - | 浮层挂载节点,可统一设置或按 imageViewer、popup、dialog、drawer 分别设置。组件的 attach 属性优先于全局配置;未配置时保持各组件原有的默认挂载行为。TS 类型:`AttachNode \| { imageViewer?: AttachNode; popup?: AttachNode; dialog?: AttachNode; drawer?: AttachNode; }`。[通用类型定义](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N autoComplete | Object | - | 自动填充组件全局配置。TS 类型:`AutoCompleteConfig` | N calendar | Object | - | 日历组件全局配置。TS 类型:`CalendarConfig` | N cascader | Object | - | 级联选择器全局配置。TS 类型:`CascaderConfig` | N @@ -96,6 +96,7 @@ select | Object | - | 选择器组件全局配置。TS 类型:`SelectConfig` | steps | Object | - | 步骤条组件全局配置。TS 类型:`StepsConfig` | N table | Object | - | 表格组件全局配置。TS 类型:`TableConfig` | N tag | Object | - | 标签全局配置。TS 类型:`TagConfig` | N +textarea | Object | - | 多行文本框组件全局配置。TS 类型:`TextareaConfig` | N timePicker | Object | - | 时间选择器全局配置。TS 类型:`TimePickerConfig` | N transfer | Object | - | 穿梭框全局配置。TS 类型:`TransferConfig` | N tree | Object | - | 树组件全局配置。TS 类型:`TreeConfig` | N @@ -176,8 +177,8 @@ now | String | - | 语言配置,“此刻” 描述文本 | N placeholder | Object | - | 占位符文本提示,默认值:`{ date: '请选择日期', month: '请选择月份', year: '请选择年份' }`。TS 类型:`{ date?: string; month?: string; year?: string }` | N preDecade | String | - | 语言配置,“上个十年” 描述文本 | N preMonth | String | - | 语言配置,“上个月” 描述文本 | N -preYear | String | - | 语言配置,“上一年” 描述文本 | N presets | Object | - | 【暂不支持,讨论确认中】预设快捷日期选择,示例:`{ '元旦': '2021-01-01', '昨天': dayjs().subtract(1, 'day').format('YYYY-MM-DD'), '特定日期': () => ['2021-02-01'] }`。TS 类型:`ConfigPresetDate` `interface ConfigPresetDate { [name: string]: DateConfigValue \| (() => DateConfigValue) }` `type DateConfigValue = string \| Date \| Array`。[详细类型定义](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N +preYear | String | - | 语言配置,“上一年” 描述文本 | N quarters | Array | - | 季度文本描述,默认值:['1 季度', '2 季度', '3 季度', '4 季度']。TS 类型:`string[]` | N rangeSeparator | String | - | 语言配置,“ 至 ” 范围分隔符描述文本,示例:' ~ ' | N selectDate | String | - | 语言配置,“选择日期” 描述文本 | N @@ -369,6 +370,13 @@ treeExpandAndFoldIcon | Function | undefined | 树形结构,展开和折叠图 -- | -- | -- | -- | -- closeIcon | Function | - | 关闭图标,【注意】使用渲染函数输出图标组件。TS 类型:`TNode`。[通用类型定义](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/common.ts) | N +### TextareaConfig + +名称 | 类型 | 默认值 | 描述 | 必传 +-- | -- | -- | -- | -- +clearText | String | - | 语言配置,“清空”清空按钮文案 | N +clearTrigger | String | focus | 清空按钮触发方式,仅在文本框有值时有效。可选项:always/focus | N + ### TimePickerConfig 名称 | 类型 | 默认值 | 描述 | 必传 @@ -419,7 +427,7 @@ dragger | Object | - | 语言配置,拖拽相关。示例:{ dragDropText: ' file | Object | - | 语言配置,文件信息相关。示例:{ fileNameText: '文件名', fileSizeText: '文件尺寸', fileStatusText: '状态', fileOperationText: '操作', fileOperationDateText: '上传日期' }。TS 类型:`UploadConfigFileList` | N progress | Object | - | 语言配置,上传进度相关。示例:{ uploadText: '上传中', waitingText: '待上传', 'failText': '上传失败', successText: '上传成功' }。TS 类型:`UploadConfigProgress` | N sizeLimitMessage | String | - | 语言配置,文件大小超出限制时提醒文本。示例:`'文件大小不能超过 {sizeLimit}'` | N -triggerUploadText | Object | - | 语言配置,上传功能触发文案。示例:{ image: '点击上传图片', normal: '点击上传', fileInput: '选择文件', reupload: '重新上传', delete: '删除', continueUpload?: '继续选择' }。TS 类型:`UploadTriggerUploadText` `interface UploadTriggerUploadText { image?: string, normal?: string, fileInput?: string, reupload?: string, continueUpload?: string, delete?: string }`。[详细类型定义](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N +triggerUploadText | Object | - | 语言配置,上传功能触发文案。示例:{ image: '点击上传图片', normal: '点击上传', fileInput: '选择文件', reupload: '重新上传', delete: '删除', continueUpload?: '继续选择' }。TS 类型:`UploadTriggerUploadText` `interface UploadTriggerUploadText { image?: string, normal?: string, fileInput?: string, reupload?: string, continueUpload?: string, delete?: string }`。[详细类型定义](https://github.com/Tencent/tdesign-react/blob/develop/packages/components/config-provider/type.ts) | N ### UploadConfigDragger diff --git a/packages/components/config-provider/type.ts b/packages/components/config-provider/type.ts index 4227f35ed9..44f5ea35b3 100644 --- a/packages/components/config-provider/type.ts +++ b/packages/components/config-provider/type.ts @@ -4,13 +4,13 @@ * 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC * */ -import { GlobalIconConfig } from 'tdesign-icons-react'; -import { CalendarController } from '../calendar'; -import { ButtonProps } from '../button'; -import { FormErrorMessage } from '../form'; -import { ImageProps } from '../image'; -import { LoadingProps } from '../loading'; -import { MessageOptions } from '../message'; +import type { GlobalIconConfig } from 'tdesign-icons-react'; +import type { CalendarController } from '../calendar'; +import type { ButtonProps } from '../button'; +import type { FormErrorMessage } from '../form'; +import type { ImageProps } from '../image'; +import type { LoadingProps } from '../loading'; +import type { MessageOptions } from '../message'; import type { TNode, TElement, SizeEnum, AttachNode } from '../common'; export interface TdConfigProviderProps { @@ -34,7 +34,7 @@ export interface GlobalConfigProvider { */ animation?: Partial>>; /** - * null + * 浮层挂载节点,可统一设置或按 imageViewer、popup、dialog、drawer 分别设置。组件的 attach 属性优先于全局配置;未配置时保持各组件原有的默认挂载行为 */ attach?: AttachNode | { imageViewer?: AttachNode; popup?: AttachNode; dialog?: AttachNode; drawer?: AttachNode }; /** @@ -151,6 +151,10 @@ export interface GlobalConfigProvider { * 标签全局配置 */ tag?: TagConfig; + /** + * 多行文本框组件全局配置 + */ + textarea?: TextareaConfig; /** * 时间选择器全局配置 */ @@ -387,15 +391,15 @@ export interface DatePickerConfig { * @default '' */ preMonth?: string; + /** + * 【暂不支持,讨论确认中】预设快捷日期选择,示例:`{ '元旦': '2021-01-01', '昨天': dayjs().subtract(1, 'day').format('YYYY-MM-DD'), '特定日期': () => ['2021-02-01'] }` + */ + presets?: ConfigPresetDate; /** * 语言配置,“上一年” 描述文本 * @default '' */ preYear?: string; - /** - * 【暂不支持,讨论确认中】预设快捷日期选择,示例:`{ '元旦': '2021-01-01', '昨天': dayjs().subtract(1, 'day').format('YYYY-MM-DD'), '特定日期': () => ['2021-02-01'] }` - */ - presets?: ConfigPresetDate; /** * 季度文本描述,默认值:['1 季度', '2 季度', '3 季度', '4 季度'] */ @@ -848,6 +852,19 @@ export interface TagConfig { closeIcon?: TNode; } +export interface TextareaConfig { + /** + * 语言配置,“清空”清空按钮文案 + * @default '' + */ + clearText?: string; + /** + * 清空按钮触发方式,仅在文本框有值时有效 + * @default focus + */ + clearTrigger?: 'always' | 'focus'; +} + export interface TimePickerConfig { /** * 语言配置,“上午”描述文本 diff --git a/packages/components/textarea/Textarea.tsx b/packages/components/textarea/Textarea.tsx index 86f5d33c58..663cc878a5 100644 --- a/packages/components/textarea/Textarea.tsx +++ b/packages/components/textarea/Textarea.tsx @@ -1,5 +1,6 @@ import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react'; import classNames from 'classnames'; +import { CloseCircleFilledIcon as TdCloseCircleFilledIcon } from 'tdesign-icons-react'; import calcTextareaHeight from '@tdesign/common-js/utils/calcTextareaHeight'; import { getCharacterLength, getUnicodeLength, limitUnicodeMaxLength } from '@tdesign/common-js/utils/helper'; @@ -9,15 +10,26 @@ import useConfig from '../hooks/useConfig'; import useControlled from '../hooks/useControlled'; import useDefaultProps from '../hooks/useDefaultProps'; import useEventCallback from '../hooks/useEventCallback'; +import useGlobalIcon from '../hooks/useGlobalIcon'; import useIsomorphicLayoutEffect from '../hooks/useLayoutEffect'; import useResizeObserver from '../hooks/useResizeObserver'; +import { useLocaleReceiver } from '../locale/LocalReceiver'; import { textareaDefaultProps } from './defaultProps'; import type { StyledProps } from '../common'; -import type { TdTextareaProps } from './type'; +import type { TdTextareaProps, TextareaClearable } from './type'; const DEFAULT_TEXTAREA_STYLE = { height: 'auto', minHeight: 'auto' }; -const OMIT_PROPS = ['defaultValue', 'readonly']; +const OMIT_PROPS = ['defaultValue', 'readonly', 'clearable']; + +function resolveClearable(clearable?: boolean | TextareaClearable) { + if (!clearable) return null; + if (clearable === true) return { position: 'top' as const, type: 'icon' as const }; + return { + position: clearable.position ?? 'top', + type: clearable.type ?? 'icon', + }; +} export interface TextareaProps extends @@ -33,6 +45,12 @@ export interface TextareaRefInterface { } const Textarea = forwardRef((originalProps, ref) => { + const { classPrefix } = useConfig(); + const [locale, t] = useLocaleReceiver('textarea'); + const { CloseCircleFilledIcon } = useGlobalIcon({ + CloseCircleFilledIcon: TdCloseCircleFilledIcon, + }); + const props = useDefaultProps(originalProps, textareaDefaultProps); const { count, @@ -50,6 +68,7 @@ const Textarea = forwardRef((originalProps, tips, allowInputOverMax, rows, + clearable, ...otherProps } = props; @@ -58,6 +77,7 @@ const Textarea = forwardRef((originalProps, const [value = '', setValue] = useControlled(props, 'value', props.onChange); + const [isHover, setIsHover] = useState(false); const [isFocused, setIsFocused] = useState(false); const [isOvermax, setIsOvermax] = useState(false); const [textareaStyle, setTextareaStyle] = useState>(DEFAULT_TEXTAREA_STYLE); @@ -75,7 +95,10 @@ const Textarea = forwardRef((originalProps, return characterInfo; }, [value, allowInputOverMax, maxcharacter]); - const { classPrefix } = useConfig(); + const clearConfig = resolveClearable(clearable); + const readOnly = Boolean(props.readOnly || props.readonly); + const canClear = Boolean(clearConfig) && String(value ?? '') !== '' && !disabled && !readOnly; + const showClear = canClear && (locale.clearTrigger === 'always' || isHover); const textareaPropsNames = Object.keys(otherProps).filter( (key) => !/^on[A-Z]/.test(key) && !OMIT_PROPS.includes(key), @@ -167,6 +190,16 @@ const Textarea = forwardRef((originalProps, } } + const handleClear = useEventCallback((event: React.MouseEvent) => { + event.preventDefault(); + event.stopPropagation(); + if (disabled || readOnly) return; + composingRef.current = false; + setComposingValue(''); + setValue(''); + textareaRef.current?.focus(); + }); + const renderLimitText = (current: number, max: number) => { if (count === false) return null; @@ -242,8 +275,36 @@ const Textarea = forwardRef((originalProps, hasMaxcharacter ? maxcharacter : maxlength, ); + const clearNode = + showClear && clearConfig ? ( + event.preventDefault()} + > + {clearConfig.type === 'text' ? ( + + {t(locale.clearText)} + + ) : ( + + )} + + ) : null; + return ( -
+
{ + if (!disabled && !readOnly) setIsHover(true); + }} + onMouseLeave={() => setIsHover(false)} + > +
+ + + + + text + + +
+ +
+ + + + +
+ + + +`; + exports[`csr snapshot test > csr test packages/components/textarea/_example/events.tsx 1`] = `
ssr test packages/components/tag-input/_example/the exports[`ssr snapshot test > ssr test packages/components/textarea/_example/base.tsx 1`] = `"
"`; +exports[`ssr snapshot test > ssr test packages/components/textarea/_example/clearable.tsx 1`] = `"
icon
text
"`; + exports[`ssr snapshot test > ssr test packages/components/textarea/_example/events.tsx 1`] = `"
"`; exports[`ssr snapshot test > ssr test packages/components/textarea/_example/maxlength.tsx 1`] = `"
这里可以放一些提示文字
0/20
0/20
0/20
0/20
0/20
"`; diff --git a/test/snap/__snapshots__/ssr.test.jsx.snap b/test/snap/__snapshots__/ssr.test.jsx.snap index a21939ddd6..e44aeb0adb 100644 --- a/test/snap/__snapshots__/ssr.test.jsx.snap +++ b/test/snap/__snapshots__/ssr.test.jsx.snap @@ -1118,6 +1118,8 @@ exports[`ssr snapshot test > ssr test packages/components/tag-input/_example/the exports[`ssr snapshot test > ssr test packages/components/textarea/_example/base.tsx 1`] = `"
"`; +exports[`ssr snapshot test > ssr test packages/components/textarea/_example/clearable.tsx 1`] = `"
icon
text
"`; + exports[`ssr snapshot test > ssr test packages/components/textarea/_example/events.tsx 1`] = `"
"`; exports[`ssr snapshot test > ssr test packages/components/textarea/_example/maxlength.tsx 1`] = `"
这里可以放一些提示文字
0/20
0/20
0/20
0/20
0/20
"`; From 7f5a0e0cc5fe4342c4be172899fe461849016c94 Mon Sep 17 00:00:00 2001 From: Rylan Date: Thu, 12 Nov 2026 12:29:42 +0800 Subject: [PATCH 09/13] fix: adjust style --- packages/components/textarea/Textarea.tsx | 1 + packages/components/textarea/__tests__/textarea.test.tsx | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/packages/components/textarea/Textarea.tsx b/packages/components/textarea/Textarea.tsx index 82a50fe4d3..103197b7eb 100644 --- a/packages/components/textarea/Textarea.tsx +++ b/packages/components/textarea/Textarea.tsx @@ -124,6 +124,7 @@ const Textarea = forwardRef((originalProps, }, {}); const textareaClassNames = classNames(`${classPrefix}-textarea__inner`, className, { + [`${classPrefix}-textarea__inner--clear`]: canClear, [`${classPrefix}-is-${status}`]: status, [`${classPrefix}-is-disabled`]: disabled, [`${classPrefix}-is-focused`]: isFocused, diff --git a/packages/components/textarea/__tests__/textarea.test.tsx b/packages/components/textarea/__tests__/textarea.test.tsx index f45573a2e9..efcb607c32 100644 --- a/packages/components/textarea/__tests__/textarea.test.tsx +++ b/packages/components/textarea/__tests__/textarea.test.tsx @@ -53,6 +53,8 @@ describe('Textarea', () => { test('true equals top icon and clears the value', async () => { const onChange = vi.fn(); const { container } = render(
"`; -exports[`ssr snapshot test > ssr test packages/components/textarea/_example/clearable.tsx 1`] = `"
icon
text
"`; +exports[`ssr snapshot test > ssr test packages/components/textarea/_example/clearable.tsx 1`] = `"
icon
text
"`; exports[`ssr snapshot test > ssr test packages/components/textarea/_example/events.tsx 1`] = `"
"`; diff --git a/test/snap/__snapshots__/ssr.test.jsx.snap b/test/snap/__snapshots__/ssr.test.jsx.snap index e44aeb0adb..c32bce8539 100644 --- a/test/snap/__snapshots__/ssr.test.jsx.snap +++ b/test/snap/__snapshots__/ssr.test.jsx.snap @@ -1118,7 +1118,7 @@ exports[`ssr snapshot test > ssr test packages/components/tag-input/_example/the exports[`ssr snapshot test > ssr test packages/components/textarea/_example/base.tsx 1`] = `"
"`; -exports[`ssr snapshot test > ssr test packages/components/textarea/_example/clearable.tsx 1`] = `"
icon
text
"`; +exports[`ssr snapshot test > ssr test packages/components/textarea/_example/clearable.tsx 1`] = `"
icon
text
"`; exports[`ssr snapshot test > ssr test packages/components/textarea/_example/events.tsx 1`] = `"
"`; From 42c355f47dff048706d590018c6bcbbcd9d73cfd Mon Sep 17 00:00:00 2001 From: Rylan Date: Thu, 12 Nov 2026 16:13:49 +0800 Subject: [PATCH 11/13] chore: sync common --- packages/common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/common b/packages/common index 1482aed1ff..e1a2202633 160000 --- a/packages/common +++ b/packages/common @@ -1 +1 @@ -Subproject commit 1482aed1ffdc9a4e9a23c2b0fcf9857d0cdbb36c +Subproject commit e1a2202633667b6a302d9a72945ad4e4b79e9ed8 From d0a7dc95118d921e85e6b770058a4b79a54885f9 Mon Sep 17 00:00:00 2001 From: tdesign-bot Date: Wed, 25 Nov 2026 13:44:03 +0000 Subject: [PATCH 12/13] chore: update common --- packages/ai-core | 2 +- packages/common | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ai-core b/packages/ai-core index f53f5abfd6..252a56f581 160000 --- a/packages/ai-core +++ b/packages/ai-core @@ -1 +1 @@ -Subproject commit f53f5abfd6ec47a7cbe209fb53f072982e28957d +Subproject commit 252a56f581dbd008d6e48365df54ad6258c69539 diff --git a/packages/common b/packages/common index e1a2202633..246d6814b5 160000 --- a/packages/common +++ b/packages/common @@ -1 +1 @@ -Subproject commit e1a2202633667b6a302d9a72945ad4e4b79e9ed8 +Subproject commit 246d6814b563b187ff5c2e3e29cca3c2ce0c448d From c37b947c665f3926acc5c275c9fd9ea95227071d Mon Sep 17 00:00:00 2001 From: tdesign-bot Date: Wed, 25 Nov 2026 14:12:26 +0000 Subject: [PATCH 13/13] chore: stash changelog [ci skip] --- packages/tdesign-react/.changelog/pr-4475.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 packages/tdesign-react/.changelog/pr-4475.md diff --git a/packages/tdesign-react/.changelog/pr-4475.md b/packages/tdesign-react/.changelog/pr-4475.md new file mode 100644 index 0000000000..d66570b362 --- /dev/null +++ b/packages/tdesign-react/.changelog/pr-4475.md @@ -0,0 +1,6 @@ +--- +pr_number: 4475 +contributor: RylanBot +--- + +- feat(Textarea): 支持 `clearable` and `onValidate` API @RylanBot ([#4475](https://github.com/Tencent/tdesign-react/pull/4475))