feat(textarea): add clearable support#4319
Open
Phoen1xCode wants to merge 5 commits into
Open
Conversation
16 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤔 这个 PR 的性质是?
🔗 相关 Issue
Closes Tencent/tdesign-common#2566
💡 需求背景和解决方案
Textarea 组件目前不支持与 Input 一致的
clearable清空能力。该 PR 为 React Textarea 新增clearable属性和onClear事件,支持用户 hover 到多行文本框时点击清空图标快速清空内容。实现内容:
clearable?: boolean,默认值为falseonClear?: (context: { e: MouseEvent }) => voidonChangecontext,支持trigger?: 'input' | 'initial' | 'clear'Textarea.tsx中接入 hover 状态、清空图标展示和清空逻辑useControlledsetter 将值更新为'',并触发onChange('', { trigger: 'clear' })和onClear注意:
packages/components/textarea/type.ts和defaultProps.ts为生成文件,本 PR 已按本地开发流程手动补充;后续需要同步在 https://github.com/tdesignoteam/tdesign-api 提交对应 API 变更。验证:
pnpm vitest run packages/components/textarea/__tests__/textarea.test.tsxpnpm vitest runpnpm eslint packages/components/textarea --ext .ts,.tsx效果展示:
2026-07-02.03-32-28.mov
📝 更新日志
tdesign-react
clearable清空功能和onClear事件@tdesign-react/chat
☑️ 请求合并前的自查清单