[Dialog] cancelBtn 传空字符串会渲染空按钮,Dialog.alert() 会带出取消按钮

オープン
#4,738 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@lnuxe がすでに取り組んでいます。

2026年11月23日 から。

  • #4739 @lnuxe による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
javascript, typescript
領域
frontend

調査の方向性

The empty-button bug sits in the confirmBtn, cancelBtn observer in dialog.ts, where typeof btn === 'string' lets an empty string through, and in alert() in index.ts, where cancelBtn: '' is set before ...mergedOptions and gets overridden. Read both spots, then run the jest reproduction with cancelBtn="" and check that no .t-dialog__button--cancel node renders. Done means empty or null cancel buttons are not rendered and Dialog.alert() shows only the confirm button. Note that PR #4739 is already open against this issue.

索引モデルが issue の本文から書いたものです。

説明

现象

命令调用 Dialog 时,cancelBtn 传空字符串本来是想「不显示取消按钮」,实际会渲染出一个空的取消按钮(占位、可点击)。

// 期望:只有确定按钮
// 实际:多一个空白按钮
Dialog.alert({ confirmBtn: 'ok' });

同样地,页面里写过 cancel-btn 的 <t-dialog> 实例被 Dialog.alert() 复用时,取消按钮会带着页面上的文案冒出来 —— alert() 本来只该有确定按钮。

根因

  1. dialog.ts 的 confirmBtn, cancelBtn observer 用 typeof btn === 'string' 判断「有文案」,而 typeof '' === 'string' 也为真,所以空字符串走进了渲染分支:
if (typeof btn === 'string') {
  rect[`_${key}`] = { ...base, content: btn }; // content: '',照样渲染
}

wx:if="{{_cancel}}" 拿到的是一个对象,恒为真,空按钮就出来了。

  1. index.ts 的 alert() 里 cancelBtn: '' 写在 ...mergedOptions 之前,会被实例上的 cancelBtn 覆盖掉:
instance.setData({
  cancelBtn: '',
  ...mergedOptions, // 这里的 cancelBtn 才是最终值
  visible: true,
});

期望

  • cancelBtn: ''(或 null / undefined)表示不渲染该按钮;
  • Dialog.alert() 无论实例上有没有 cancel-btn,都只显示确定按钮。

复现(jest + miniprogram-simulate)

const comp = await setup(`<t-dialog id="dialog" visible cancelBtn="" />`);
expect(comp.querySelectorAll('#dialog >>> .t-dialog__button--cancel').length).toBe(0);
// 当前得到 1
主要言語
Vue
スター
1.8k
フォーク
351
平均マージ
22時間 9分
マージ済み PR(30日)
17

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Tencent/tdesign-miniprogram のほかの issue

Tencent/tdesign-miniprogram の issue をすべて見る

似ている issue

Web Dev の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。