Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(select): add event for when overlay is dismissed #24099

Merged
merged 5 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion angular/src/directives/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,10 @@ export declare interface IonSelect extends Components.IonSelect {
* Emitted when the selection is cancelled.
*/
ionCancel: EventEmitter<CustomEvent<void>>;
/**
* Emitted when the overlay is dismissed.
*/
ionDismiss: EventEmitter<CustomEvent<void>>;
/**
* Emitted when the select has focus.
*/
Expand Down Expand Up @@ -1595,7 +1599,7 @@ export class IonSelect {
constructor(c: ChangeDetectorRef, r: ElementRef, protected z: NgZone) {
c.detach();
this.el = r.nativeElement;
proxyOutputs(this, this.el, ['ionChange', 'ionCancel', 'ionFocus', 'ionBlur']);
proxyOutputs(this, this.el, ["ionChange", "ionCancel", "ionDismiss", "ionFocus", "ionBlur"]);
}
}

Expand Down
1 change: 1 addition & 0 deletions core/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,7 @@ ion-select,method,open,open(event?: UIEvent | undefined) => Promise<any>
ion-select,event,ionBlur,void,true
ion-select,event,ionCancel,void,true
ion-select,event,ionChange,SelectChangeEventDetail<any>,true
ion-select,event,ionDismiss,void,true
ion-select,event,ionFocus,void,true
ion-select,css-prop,--padding-bottom
ion-select,css-prop,--padding-end
Expand Down
4 changes: 4 additions & 0 deletions core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6147,6 +6147,10 @@ declare namespace LocalJSX {
* Emitted when the value has changed.
*/
"onIonChange"?: (event: CustomEvent<SelectChangeEventDetail>) => void;
/**
* Emitted when the overlay is dismissed.
*/
"onIonDismiss"?: (event: CustomEvent<void>) => void;
/**
* Emitted when the select has focus.
*/
Expand Down
13 changes: 7 additions & 6 deletions core/src/components/select/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -1385,12 +1385,13 @@ export default defineComponent({

## Events

| Event | Description | Type |
| ----------- | ---------------------------------------- | ------------------------------------------- |
| `ionBlur` | Emitted when the select loses focus. | `CustomEvent<void>` |
| `ionCancel` | Emitted when the selection is cancelled. | `CustomEvent<void>` |
| `ionChange` | Emitted when the value has changed. | `CustomEvent<SelectChangeEventDetail<any>>` |
| `ionFocus` | Emitted when the select has focus. | `CustomEvent<void>` |
| Event | Description | Type |
| ------------ | ---------------------------------------- | ------------------------------------------- |
| `ionBlur` | Emitted when the select loses focus. | `CustomEvent<void>` |
| `ionCancel` | Emitted when the selection is cancelled. | `CustomEvent<void>` |
| `ionChange` | Emitted when the value has changed. | `CustomEvent<SelectChangeEventDetail<any>>` |
| `ionDismiss` | Emitted when the overlay is dismissed. | `CustomEvent<void>` |
| `ionFocus` | Emitted when the select has focus. | `CustomEvent<void>` |


## Methods
Expand Down
6 changes: 6 additions & 0 deletions core/src/components/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ export class Select implements ComponentInterface {
*/
@Event() ionCancel!: EventEmitter<void>;

/**
* Emitted when the overlay is dismissed.
*/
@Event() ionDismiss!: EventEmitter<void>;

/**
* Emitted when the select has focus.
*/
Expand Down Expand Up @@ -176,6 +181,7 @@ export class Select implements ComponentInterface {
overlay.onDidDismiss().then(() => {
this.overlay = undefined;
this.isExpanded = false;
this.ionDismiss.emit();
this.setFocus();
});

Expand Down
14 changes: 14 additions & 0 deletions core/src/components/select/test/basic/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ test('select: basic', async () => {

// Gender Alert Select
let select = await page.find('#gender');

// add an event spy to the select
const ionDismiss = await select.spyOnEvent('ionDismiss');

await select.click();

let alert = await page.find('ion-alert');
Expand All @@ -20,6 +24,8 @@ test('select: basic', async () => {

await alert.callMethod('dismiss');

expect(ionDismiss).toHaveReceivedEvent();

// Skittles Action Sheet Select
select = await page.find('#skittles');
await select.click();
Expand All @@ -32,6 +38,8 @@ test('select: basic', async () => {

await actionSheet.callMethod('dismiss');

expect(ionDismiss).toHaveReceivedEvent();

// Custom Alert Select
select = await page.find('#customAlertSelect');
await select.click();
Expand All @@ -44,6 +52,8 @@ test('select: basic', async () => {

await alert.callMethod('dismiss');

expect(ionDismiss).toHaveReceivedEvent();

// Custom Popover Select
select = await page.find('#customPopoverSelect');
await select.click();
Expand Down Expand Up @@ -72,6 +82,8 @@ test('select: basic', async () => {

await popover.callMethod('dismiss');

expect(ionDismiss).toHaveReceivedEvent();

// Custom Action Sheet Select
select = await page.find('#customActionSheetSelect');
await select.click();
Expand All @@ -84,6 +96,8 @@ test('select: basic', async () => {

await actionSheet.callMethod('dismiss');

expect(ionDismiss).toHaveReceivedEvent();

for (const compare of compares) {
expect(compare).toMatchScreenshot();
}
Expand Down
1 change: 1 addition & 0 deletions packages/vue/src/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ export const IonSelect = /*@__PURE__*/ defineContainer<JSX.IonSelect>('ion-selec
'value',
'ionChange',
'ionCancel',
'ionDismiss',
'ionFocus',
'ionBlur',
'ionStyle'
Expand Down