Skip to content

feat(textarea): add clearable icon styles and docs#2598

Open
ceilf6 wants to merge 3 commits into
Tencent:developfrom
ceilf6:feature/issue-2566
Open

feat(textarea): add clearable icon styles and docs#2598
ceilf6 wants to merge 3 commits into
Tencent:developfrom
ceilf6:feature/issue-2566

Conversation

@ceilf6

@ceilf6 ceilf6 commented Jul 2, 2026

Copy link
Copy Markdown

📌 Issue

Closes #2566 — [Textarea] 增加可清空内容

📝 背景

多行文本框(Textarea)目前不具备与 Input 一致的清空能力,用户需要手动全选并删除才能清空已输入的内容,交互效率较低。本 PR 在共享样式层补齐 Textarea 的 clearable 视觉与交互,使两端体验对齐。

🔨 方案

tdesign-common 共享样式层新增 Textarea 清空按钮样式(各框架复用):

  • 新增 .t-textarea__clear 元素类与 .t-textarea--clearable 修饰类,沿用 TDesign BEM 命名
  • 清空按钮默认 opacity: 0; visibility: hidden,在 .t-textarea--clearable:hover 时显示,与 Input 的 --suffix:hover .t-input__clear 行为一致
  • 按钮固定在右上角,刻意避开右下角 native resize 拖拽手柄,避免遮挡 / 误触
  • 通过组件级 LESS token 暴露颜色 / 字号 / 位置 / 过渡,便于主题定制:
    • @textarea-clear-icon-color / @textarea-clear-icon-color-hover(对齐 Input suffix 图标色)
    • @textarea-clear-icon-font-size(默认 @font-size-l,16px)
    • @textarea-clear-icon-top(与首行文本垂直居中:calc((@comp-size-m - icon-size) / 2),首行中心位于 @comp-size-m / 2
    • @textarea-clear-icon-right(与 __inner 水平内边距对齐)
    • @textarea-clear-icon-transition
  • 禁用态不渲染清空按钮的逻辑由各框架仓库的组件代码负责(与 Input 一致,CSS 不额外处理)

文档同步新增「可清空内容 / Clearable Content」示例小节(zh + en-US),与 Input 文档对齐。

📦 范围说明

本 PR 仅包含 tdesign-common 共享样式与文档。clearable 属性定义、模板接线与 _example/clearable 示例属于各框架仓库,将在框架侧 PR 落地(如 tdesign-react#4319)。

✅ 自测

  • npx lessc style/web/components/textarea/_index.less 编译通过
  • lint-staged(stylelint + prettier)通过
  • 各框架仓库接入后视觉 / 交互对齐(框架侧 PR 验证)

changelog

feat(textarea): 支持多行文本框清空图标样式与文档说明


🤖 Generated with Claude Code

Add shared styles for the Textarea `clearable` feature, bringing it to
parity with Input. The clear icon is anchored to the top-right corner to
avoid overlapping the native bottom-right resize drag handle, hidden by
default and revealed on hover, mirroring the Input clearable pattern
with BEM-like `.t-textarea__clear` / `--clearable` naming and
component-level LESS tokens.

Adds the "可清空内容 / Clearable Content" narrative section to the web
API docs (zh + en-US), matching the Input documentation.

Refs Tencent#2566. The `clearable` prop, template wiring and example demo live
in the per-framework repos (e.g. tdesign-react#4319).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 2, 2026 02:54
@ceilf6

ceilf6 commented Jul 2, 2026

Copy link
Copy Markdown
Author

@ceilf6/repo-guard CR

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds shared Web (LESS) styling tokens and rules for a Textarea “clearable” affordance (clear icon), and updates the Textarea API docs (zh/en) to include a clearable section, aligning Textarea documentation and styling capabilities with Input.

Changes:

  • Added Textarea clear-icon design tokens in style/web/components/textarea/_var.less.
  • Added .t-textarea--clearable + .t-textarea__clear styling in style/web/components/textarea/_index.less.
  • Added “Clearable Content / 可清空内容” documentation sections in docs/web/api/textarea(.en-US).md.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
style/web/components/textarea/_var.less Introduces LESS tokens for clear icon color/size/position/transition.
style/web/components/textarea/_index.less Adds clearable state styling and clear icon visibility/hover behavior.
docs/web/api/textarea.md Adds zh “可清空内容” docs section referencing {{ clearable }}.
docs/web/api/textarea.en-US.md Adds en-US “Clearable Content” docs section referencing {{ clearable }}.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +92 to +115
// 可清空内容:清空按钮固定在右上角,避开右下角的 native resize 拖拽手柄
&--clearable {
.@{prefix}-textarea__clear {
position: absolute;
top: @textarea-clear-icon-top;
right: @textarea-clear-icon-right;
color: @textarea-clear-icon-color;
font-size: @textarea-clear-icon-font-size;
line-height: 1;
cursor: pointer;
opacity: 0;
visibility: hidden;
transition: @textarea-clear-icon-transition;
}

&:hover .@{prefix}-textarea__clear {
opacity: 1;
visibility: visible;
}

.@{prefix}-textarea__clear:hover {
color: @textarea-clear-icon-color-hover;
}
}
@ceilf6

ceilf6 commented Jul 2, 2026

Copy link
Copy Markdown
Author

🛡️ ceilf6/repo-guard

代码评审报告: feat(textarea): add clearable icon styles and docs

风险等级:
处理建议: 请求修改
决策摘要: 共享样式本身安全、遵循既有命名和 token 惯例,但文档新增了 {{ clearable }} 示例引用,而本 PR 范围里没有任何框架侧代码提供该 demo/属性,会导致文档站点在合并后立即渲染失败或空白,需先确认框架侧 PR 落地顺序或去掉本次文档改动。

级联分析

  • 变更符号: .t-textarea__clear.t-textarea--clearable@textarea-clear-icon-* LESS token、docs/web/api/textarea(.en-US).md 中的 {{ clearable }} 占位符
  • 受影响流程: tdesign-common 样式编译产物被各框架仓库(Vue/React/Miniprogram 等)依赖引入;文档站点构建流程依赖 _example/clearable demo 文件解析 {{ clearable }} 占位符
  • 变更集外调用方: 各框架仓库的 Textarea 组件实现(clearable prop、模板接线、_example/clearable 示例文件)——PR 描述已声明这些不在本次范围内,将由 tdesign-react#4319 等后续 PR 落地
  • 置信度: medium(无代码图谱,基于 diff 与 PR 描述判断;未能验证 tdesign-common 的文档构建流程对未定义 {{ clearable }} 引用的容错行为)

问题发现

  1. [高] 文档新增 {{ clearable }} 占位符但示例文件不存在于本 PR

    • 证据: docs/web/api/textarea.mdtextarea.en-US.md 新增 {{ clearable }},但变更文件列表中没有 _example/clearable demo;PR 描述明确写明"_example/clearable 示例属于各框架仓库"
    • 受影响调用方/流程: tdesign-common 的文档站点构建(如果该仓库也生成文档站点)会在解析该占位符时报错或渲染空白;若 tdesign-common 的 docs/ 只是被下游框架仓库复制/引用模板,则该风险转移给下游,仍需确认下游是否会在对应 PR 落地前先合并本 PR 导致文档不完整
    • 最小可行修复: 确认 tdesign-common 是否独立构建文档站点。如果是,应将文档改动与框架侧 _example/clearable 一并合并,或本 PR 暂缓新增文档小节,改为等框架侧 PR 落地后再补充;如果 docs/ 仅作为跨框架共享模板、由各框架自行拼装且能容忍缺失 demo,则在 PR 描述中补充这一事实作为证据,降低本项风险等级
  2. [中] 禁用态清空按钮完全依赖框架层控制,共享样式层没有防御性兜底

    • 证据: PR 描述称"禁用态不渲染清空按钮的逻辑由各框架仓库的组件代码负责(与 Input 一致,CSS 不额外处理)",_index.less--clearable 规则未包含任何 :disabled--disabled 修饰类的覆盖
    • 受影响调用方/流程: 若某个框架实现遗漏了禁用态判断(直接渲染 DOM 节点但未从逻辑层剔除清空按钮),CSS 层没有任何保护,清空按钮会在禁用状态下仍然可见/可点
    • 最小可行修复: 非阻塞项,但建议对齐 Input 组件在 _index.less 中的实际处理方式(若 Input 在禁用态也有 CSS 层保护,Textarea 应同样补充 &--disabled 场景下强制 display: none 的规则);如果 Input 也完全依赖框架层,则此项可降级为观察项

行级发现

  • [style/web/components/textarea/_index.less:91] --clearable 修饰类未与 resize 相关状态或 --disabled 状态组合处理,禁用态下清空按钮完全依赖框架层逻辑剔除 DOM,CSS 层无兜底(对齐 Input 现有做法即可,非本次阻塞)
  • [style/web/components/textarea/_var.less:59] @textarea-clear-icon-top 的计算注释假设 textarea 首行文本垂直居中于 @comp-size-m 高度区域内,但若用户设置了 rows > 1 或自定义 min-height 导致首行不再位于该计算基准区域,图标位置可能与首行不对齐;建议确认该 token 仅作用于默认单行高度基准,且在文档/注释中说明这一前提
  • [docs/web/api/textarea.md:24] {{ clearable }} 占位符引用的示例文件不在本 PR 变更范围内,需确认文档构建是否会因缺失 demo 报错,或明确该文档改动应随框架侧 PR 一起合并
  • [docs/web/api/textarea.en-US.md:24] 同上,{{ clearable }} 引用在英文文档中同样缺少对应示例文件

Karpathy 评审

  • 假设: PR 假设 tdesign-common 的文档新增可以独立于框架侧示例文件安全合并,这一假设未经验证;也假设 Input 组件的禁用态处理方式可以照搬到 Textarea(合理但未在 diff 中显式核对)
  • 简洁性: 样式实现简洁,token 抽象粒度与现有 Input 组件一致,没有过度设计或猜测性抽象
  • 结构质量: 新增 CSS 规则遵循既有 BEM 命名和文件组织方式,未引入特例分支或复制既有 helper;_var.less token 命名与既有变量风格一致
  • 变更范围: 变更集中在样式与文档,无关重构噪声极少;范围说明清晰但正是这份"范围说明"暴露了潜在的合并顺序问题(见问题发现 chore(deps-dev): bump @typescript-eslint/experimental-utils from 2.34.0 to 5.7.0 #1
  • 验证: 自测清单仅覆盖 LESS 编译和 lint,未包含文档构建验证;"各框架仓库接入后视觉/交互对齐"被显式标记为未完成,这是本次 PR 验证覆盖的主要缺口

缺失覆盖

  • 未验证 docs/web/api/textarea.md 中新增的 {{ clearable }} 占位符在当前 tdesign-common 文档构建流程下是否会因缺少 _example/clearable 而报错或产生空白区块
  • 未提供关于 Input 组件禁用态清空按钮实际处理方式(CSS 层是否有兜底)的对比证据,无法完全确认"与 Input 一致"这一说法
  • 未说明本 PR 与关联的框架侧 PR(如 tdesign-react#4319)之间的合并顺序或依赖关系,建议在 PR 描述或 CI 中明确,避免用户在框架侧代码落地前看到损坏的清空按钮或空文档示例

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Textarea] 增加可清空内容

3 participants