ionic-team / ionic-team/ionic-framework

feat: dismiss data in overlay button handler return

オープン
#26,013 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
package: core type: feature request
主要言語
TypeScript
スター
52.7k
フォーク
13.3k
平均マージ
1日 15時間
マージ済み PR(30日)
51

説明

### Prerequisites

- [X] I have read the [Contributing Guidelines](https://github.com/ionic-team/ionic-framework/blob/main/.github/CONTRIBUTING.md#creating-an-issue).
- [X] I agree to follow the [Code of Conduct](https://ionicframework.com/code-of-conduct).
- [X] I have searched for [existing issues](https://github.com/ionic-team/ionic-framework/issues) that already include this feature request, without success.

### Describe the Feature Request

It would be great if the `handler` function of an overlay button (e.g. `IonActionSheetButton`) would allow overlay data as a return value.

### Describe the Use Case

I have an `IonActionSheet` with three buttons that resolve some data from a promise. When the data is resolved and is not null, the IonActionSheet should dismiss with given data in the `OverlayEventDetail`. If the data is null, I do not want to close the ActionSheet by returning false in the handler method.

At the moment I can not return data inside the handler value except by using the dismiss method of the created action sheet itself.

### Describe Preferred Solution

The `handler()` method on an `IonActionSheetButton` should accept OverlayEventDetail object as return value

```
public async browseFile(): Promise {
const actionSheet = await this.actionSheetController.create({
buttons: [
{
text: 'Scan Document',
role: 'scanner',
handler: async () => {
const file = await this.browseScanner();
return file ? {file} : false;
}
},
{
text: 'Cancel',
role: 'cancel'
}
]
});
await actionSheet.present();
const {data, role} = await actionSheet.onWillDismiss<{file: SandboxFile}>();
return data?.file || null;
}
```

### Describe Alternatives

_No response_

### Related Code
At the moment I have to solve the problem with using the `dismiss()` method of the action sheet element. But this results in the buttons role attribute being ignored because the dismiss is triggered by the `dismiss()` method and not via the handler default.

```
public async browseFile(): Promise {
const actionSheet = await this.actionSheetController.create({
buttons: [
{
text: 'Scan Document',
role: 'scanner',
handler: async () => {
const file = await this.browseScanner();
if (!file) {
// if file is null or undefined, I do not want to close the action sheet
return false;
}
// dismissing in handler needs to be done with via the action sheet object
await actionSheet.dismiss({file});
}
},
{
text: 'Camera',
role: 'camera',
handler: async () => {
const file = await this.browseCamera();
if (!file) {
return false;
}
await actionSheet.dismiss({file});
}
},
{
text: 'Cancel',
role: 'cancel'
}
]
});
await actionSheet.present();
const {data, role} = await actionSheet.onWillDismiss<{file: SandboxFile}>();
return data?.file || null;
}
```

### Additional Information

_No response_

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

Start by tracing the IonActionSheetButton handler and the overlay dismissal flow described in the issue. Determine how handler return values currently control dismissal and roles, then verify that returning overlay data dismisses with that data while returning false keeps the overlay open.

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

評価

技術スタック
typescript
領域
frontend
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
42/100

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

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