Skip to content

Conversation

@baozjj
Copy link
Contributor

@baozjj baozjj commented Jun 29, 2025

Fixes an inconsistency between Alert and Message components. In Vue, when passing a boolean prop without a value (e.g., <Comp closeBtn />), it is treated as closeBtn="", which is considered truthy. This behavior works in Alert, but not in Message due to use of || when reading props.
Empty string was treated as falsy and caused the logic to fail. Now replaced || with ?? in useTNodeJSX to preserve "".
Also updated the -is-closable class logic in Message to correctly reflect closeBtn="". Open to further suggestions on improving the class condition.

Notably, the following code snippet in useTNodeJSX 89-96:

// If the prop type is a union including Boolean and Function, handle boolean casting as per Vue rules
// https://vuejs.org/guide/components/props.html#boolean-casting
if (types?.length > 1) {
  if (types.includes(Boolean) && types.includes(Function)) {
    if (propsNode === '' && !renderSlot) return defaultNode;
  }
}

reflects an intention to align with Vue's boolean casting behavior.
However, due to the use of || when reading the prop value:

const propsNode = instance.props[camelCase(name)] || instance.props[kebabCase(name)];

the empty string '' is treated as falsy and this intended behavior is not achieved.
Replacing || with ?? fixes this and brings useTNodeJSX in line with Vue's rules.

BREAKING CHANGE: Changed behavior in useTNodeJSX when prop is passed as an empty string. Previously, empty string values (e.g., closeBtn="") were treated as falsy. Now they are preserved and considered as explicitly set, which may affect rendering in some components.

🤔 这个 PR 的性质是?

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

🔗 相关 Issue

  1. 该问题由 Alert 和 Message 组件 closeBtn 行为不一致引起。
  2. Vue 中布尔 prop 传入无值时应被视为真值。
  3. Message 组件未正确处理该情况,导致关闭按钮无法显示。

💡 需求背景和解决方案

  1. Vue 规则说明:在模板中 <Comp closeBtn /> 等价于 closeBtn="",其应视为真值。
  2. Message 组件中 useTNodeJSX 函数中,读取 prop 时使用 || 导致 "" 被视为假值,无法触发关闭按钮渲染。
  3. 解决方案是将 || 改为 ??,保持空字符串的显式性。
  4. 另外修正 Message 组件关闭按钮 CSS class 逻辑,确保 closeBtn="" 时添加可关闭样式。
  5. 保持与 Alert 组件行为一致,避免用户混淆。
  • 修复 Message 组件 closeBtn="" 时关闭按钮不显示的问题
  • 优化 useTNodeJSX 中 props 读取逻辑,正确处理空字符串值
  • 调整 Message 组件关闭按钮样式判断,兼容空字符串值
  • 统一 Alert 与 Message 组件的 closeBtn 语义行为
  • 添加相关单元测试覆盖

📝 更新日志

tdesign-vue-next

  • fix(message): 修复 closeBtn 为空字符串时关闭按钮不显示问题

@tdesign-vue-next/chat

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

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

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

Fixes an inconsistency between Alert and Message components.
In Vue, when passing a boolean prop without a value (e.g., `<Comp closeBtn />`),
it is treated as `closeBtn=""`, which is considered truthy.
This behavior works in Alert, but not in Message due to use of `

` when reading props.
Empty string was treated as falsy and caused the logic to fail.
Now replaced `

` with `?` in `useTNodeJSX` to preserve `""`.
Also updated the `-is-closable` class logic in Message to correctly reflect `closeBtn=""`.
Open to further suggestions on improving the class condition.

BREAKING CHANGE: Changed behavior in `useTNodeJSX` when prop is passed as an empty string.
Previously, empty string values (e.g., `closeBtn=""`) were treated as falsy.
Now they are preserved and considered as explicitly set, which may affect rendering in some
components.
@tdesign-bot
Copy link
Collaborator

TDesign Component Site Preview Open

Component Preview
tdesign-vue-next 完成
@tdesign-vue-next/chat 完成

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jun 29, 2025

tdesign-vue-next-demo

npm i https://pkg.pr.new/Tencent/tdesign-vue-next@5671
npm i https://pkg.pr.new/Tencent/tdesign-vue-next/@tdesign-vue-next/chat@5671

commit: 3078196

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants