ionic-team / ionic-team/ionic-framework

bug: adding buttons to alert with the same role causes the first handler to always be fired

未关闭
#23,037 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
package: core type: bug
主要语言
TypeScript
星标
52.7k
派生
13.3k
平均合并
1 天 15 小时
30 天内合并 PR
51

描述

# Bug Report

**Ionic version:**

[ ] **4.x**
[x] **5.x**

**Current behavior:**
If two buttons in an alert both have the `cancel` role, only the first handler will ever be called, regardless of which button is pressed. Changing the roles to be different will result in expected behavior.

**Expected behavior:**
The handler for the pressed button should be called, regardless of its 'role'.

**Steps to reproduce:**
1. See code below.
2. Click "BUTTON 2"
3. Observe that the handler for "BUTTON 1" will have been called.

**Related code:**

```
const alert = await this.alertCtrl.create({
header: 'Header',
message:'Some message here',
buttons:[{
text: 'BUTTON 1',
role: 'cancel',
handler: () => {
console.log('BUTTON 1');
}
}, {
text: 'BUTTON 2',
role: 'cancel',
handler: () => {
console.log('BUTTON 2');
}
}]
});
alert.present();
```

Aside... can we get an updated StackBlitz/Plunkr for the latest version of Ionic Angular, etc? :) They are still on 3 & 4.

**Other information:**

**Ionic info:**

```
sharktop:topdecked-unified lincoln$ ionic info

Ionic:

Ionic CLI : 6.12.4 (/usr/local/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 5.6.0
@angular-devkit/build-angular : 0.1200.0-next.3
@angular-devkit/schematics : 12.0.0-next.3
@angular/cli : 12.0.0-next.3
@ionic/angular-toolkit : 3.1.0

Capacitor:

Capacitor CLI : 3.0.0-beta.6
@capacitor/core : 3.0.0-beta.6

Utility:

cordova-res : 0.15.3
native-run : 1.3.0

System:

NodeJS : v14.15.0 (/usr/local/bin/node)
npm : 6.14.9
OS : macOS Catalina

```

贡献指南

打开贡献指南

调研方向

Start from the alertCtrl.create entry point and reproduce the two-button example in an Ionic 5 environment. Trace how button roles and handlers are selected, then verify that pressing each button invokes its own handler, ideally adding coverage for duplicate cancel roles.

由索引模型根据 Issue 内容生成。

评估

技术栈
typescript
领域
frontend
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。