Skip to content

Commit 57291c8

Browse files
feat: Add onCanceled event for action sheet (#138)
1 parent 4e8674a commit 57291c8

3 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ declare namespace LocalJSX {
9393
interface PwaActionSheet {
9494
"cancelable"?: boolean;
9595
"header"?: string;
96+
"onOnCanceled"?: (event: PwaActionSheetCustomEvent<any>) => void;
9697
"onOnSelection"?: (event: PwaActionSheetCustomEvent<any>) => void;
9798
"options"?: ActionSheetOption[];
9899
}

src/components/action-sheet/action-sheet.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export class PWAActionSheet {
1818

1919
@Event() onSelection: EventEmitter;
2020

21+
@Event() onCanceled: EventEmitter;
22+
2123
@State() open = false;
2224

2325
componentDidLoad() {
@@ -28,6 +30,7 @@ export class PWAActionSheet {
2830

2931
dismiss() {
3032
if (this.cancelable) {
33+
this.onCanceled.emit();
3134
this.close();
3235
}
3336
}

src/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,16 @@
7575
b.addEventListener('click', async (ev) => {
7676
const actionSheet = document.createElement('pwa-action-sheet');
7777
actionSheet.header = 'choose option';
78-
actionSheet.cancelable = false;
78+
actionSheet.cancelable = true;
7979
actionSheet.options = [{title: 'hi'},{title: 'bye', style: "DESTRUCTIVE"},{title: 'cancel', style: "CANCEL"}]
8080
document.body.appendChild(actionSheet);
8181
actionSheet.addEventListener('onSelection', async (e) => {
8282
const selection = e.detail;
8383
console.log('selected', selection);
8484
})
85+
actionSheet.addEventListener('onCanceled', async () => {
86+
console.log('sheet was canceled');
87+
})
8588
});
8689
</script>
8790

0 commit comments

Comments
 (0)