Skip to content

fix(button): prevent rendering navigable anchors when href is used with loading or disabled - #4493

Merged
uyarn merged 5 commits into
Tencent:developfrom
lnuxe:fix/button-href-non-navigable-4490
Nov 25, 2026
Merged

uyarn merged 5 commits into
Tencent:developfrom
lnuxe:fix/button-href-non-navigable-4490

Conversation

@lnuxe

@lnuxe lnuxe commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🤔 这个 PR 的性质

  • 日常 bug 修复
  • 新特性提交
  • 文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • CI/CD 改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他

🔗 相关 Issue

fix #4490

💡 需求背景和解决方案

📝 更新日志

tdesign-react

  • fix(Button): 修复 href / tag="a" 与 loading / disabled 同时使用时,仍渲染可导航锚点的问题

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项。⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • Changelog 已提供或无须提供

锚点元素不识别 disabled 属性,此前的实现仅移除 onClick,href 仍生效可导航。现调整 renderTag:1) href + loading 时回退 div(此前仅 disabled 生效);2) 显式 tag='a' 且 disabled/loading 时回退 div。普通 button 的既有渲染完全不变(35/35 快照与用例全绿)。新增 4 例回归测试。
@RylanBot
RylanBot force-pushed the fix/button-href-non-navigable-4490 branch from 4655382 to a94f42e Compare November 19, 2026 08:20
@RylanBot RylanBot added 🐞 bug Something isn't working easy to be published fixed, not be published and removed 🐞 bug Something isn't working labels Nov 19, 2026
@tdesign-bot

tdesign-bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

TDesign Component Site Preview Open

Component Preview
tdesign-react 完成
@tdesign-react/chat 完成

@pkg-pr-new

pkg-pr-new Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
  • tdesign-react-demo

    npm i https://pkg.pr.new/tdesign-react@4493
    
    npm i https://pkg.pr.new/@tdesign-react/chat@4493
    

commit: 45f5823

@uyarn

uyarn commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

https://stackblitz.com/edit/9zomqeqz-1whaad5h?file=src%2FDemo.tsx
在tag=button的场景有问题 设置disabled会强制渲染为div标签,与预期不符
image

对比目前develop的效果 https://stackblitz.com/edit/e9kanehy-ncmwaunr?file=src%2Fdemo.tsx
image

tag=button / tag=div 时 disabled、loading 仍保留调用方指定的标签,
只有不可交互的 a(含 href 降级出的 a)才退回 div。
@lnuxe

lnuxe commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

已修,commit edcf8766。

根因:上一版 renderTag 是 if (disabled || (nonInteractive && (href || tag === 'a'))) return 'div' —— disabled 排在 tag 判断之前,所以只要 disabled 就无条件返回 div,tag="button" 也被吃掉。

改法(packages/components/button/Button.tsx:58-64):显式 tag 优先,只有不可交互的 a 才降级成 div。

const nonInteractive = disabled || loading;
if (tag) return nonInteractive && tag === 'a' ? 'div' : tag;   // tag="button" + disabled → button
if (href) return nonInteractive ? 'div' : 'a';                 // href + disabled/loading → div(#4490 原问题)
return disabled ? 'div' : 'button';

其余行为与 develop 一致,未改动:无 tag + href + 正常 = a;无 tag + 无 href + disabled = div;无 tag + 无 href + 正常/loading = button。

验证:新增 3 个用例(tag=button+disabled / tag=button+loading / tag=div+disabled 保留原标签)以及 tag="button"+disabled 保留 disabled 属性;vitest run packages/components/button → 39 passed,快照未变动。

麻烦再看一眼 stackblitz 那个 tag="button" 场景。

@uyarn uyarn changed the title fix(button): href 与 loading/disabled 同时使用时不再渲染可导航锚点 fix(button): prevent rendering navigable anchors when href is used with loading or disabled Nov 25, 2026
@uyarn
uyarn merged commit c7f5468 into Tencent:develop Nov 25, 2026
1 check passed
@tdesign-bot tdesign-bot mentioned this pull request Nov 26, 2026
6 of 16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

easy to be published fixed, not be published

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Button] href 与 loading/disabled 同时使用时仍可导航跳转

4 participants