@@ -7,14 +7,14 @@ import { shouldUseCloseWatcher } from '@utils/hardware-back-button';
7
7
import type { Attributes } from '@utils/helpers' ;
8
8
import { inheritAriaAttributes , assert , clamp , isEndSide as isEnd } from '@utils/helpers' ;
9
9
import { menuController } from '@utils/menu-controller' ;
10
- import { getPresentedOverlay } from '@utils/overlays' ;
10
+ import { BACKDROP , GESTURE , getPresentedOverlay } from '@utils/overlays' ;
11
11
import { hostContext } from '@utils/theme' ;
12
12
13
13
import { config } from '../../global/config' ;
14
14
import { getIonMode } from '../../global/ionic-global' ;
15
15
import type { Animation , Gesture , GestureDetail } from '../../interface' ;
16
16
17
- import type { MenuChangeEventDetail , MenuI , MenuType , Side } from './menu-interface' ;
17
+ import type { MenuChangeEventDetail , MenuCloseEventDetail , MenuI , MenuType , Side } from './menu-interface' ;
18
18
19
19
const iosEasing = 'cubic-bezier(0.32,0.72,0,1)' ;
20
20
const mdEasing = 'cubic-bezier(0.0,0.0,0.2,1)' ;
@@ -179,7 +179,7 @@ export class Menu implements ComponentInterface, MenuI {
179
179
/**
180
180
* Emitted when the menu is about to be closed.
181
181
*/
182
- @Event ( ) ionWillClose ! : EventEmitter < void > ;
182
+ @Event ( ) ionWillClose ! : EventEmitter < MenuCloseEventDetail > ;
183
183
/**
184
184
* Emitted when the menu is open.
185
185
*/
@@ -188,7 +188,7 @@ export class Menu implements ComponentInterface, MenuI {
188
188
/**
189
189
* Emitted when the menu is closed.
190
190
*/
191
- @Event ( ) ionDidClose ! : EventEmitter < void > ;
191
+ @Event ( ) ionDidClose ! : EventEmitter < MenuCloseEventDetail > ;
192
192
193
193
/**
194
194
* Emitted when the menu state is changed.
@@ -331,14 +331,14 @@ export class Menu implements ComponentInterface, MenuI {
331
331
if ( shouldClose ) {
332
332
ev . preventDefault ( ) ;
333
333
ev . stopPropagation ( ) ;
334
- this . close ( ) ;
334
+ this . close ( undefined , BACKDROP ) ;
335
335
}
336
336
}
337
337
}
338
338
339
339
onKeydown ( ev : KeyboardEvent ) {
340
340
if ( ev . key === 'Escape' ) {
341
- this . close ( ) ;
341
+ this . close ( undefined , BACKDROP ) ;
342
342
}
343
343
}
344
344
@@ -375,8 +375,8 @@ export class Menu implements ComponentInterface, MenuI {
375
375
* it returns `false`.
376
376
*/
377
377
@Method ( )
378
- close ( animated = true ) : Promise < boolean > {
379
- return this . setOpen ( false , animated ) ;
378
+ close ( animated = true , role ?: string ) : Promise < boolean > {
379
+ return this . setOpen ( false , animated , role ) ;
380
380
}
381
381
382
382
/**
@@ -393,8 +393,8 @@ export class Menu implements ComponentInterface, MenuI {
393
393
* If the operation can't be completed successfully, it returns `false`.
394
394
*/
395
395
@Method ( )
396
- setOpen ( shouldOpen : boolean , animated = true ) : Promise < boolean > {
397
- return menuController . _setOpen ( this , shouldOpen , animated ) ;
396
+ setOpen ( shouldOpen : boolean , animated = true , role ?: string ) : Promise < boolean > {
397
+ return menuController . _setOpen ( this , shouldOpen , animated , role ) ;
398
398
}
399
399
400
400
private trapKeyboardFocus ( ev : Event , doc : Document ) {
@@ -438,13 +438,13 @@ export class Menu implements ComponentInterface, MenuI {
438
438
}
439
439
}
440
440
441
- async _setOpen ( shouldOpen : boolean , animated = true ) : Promise < boolean > {
441
+ async _setOpen ( shouldOpen : boolean , animated = true , role ?: string ) : Promise < boolean > {
442
442
// If the menu is disabled or it is currently being animated, let's do nothing
443
443
if ( ! this . _isActive ( ) || this . isAnimating || shouldOpen === this . _isOpen ) {
444
444
return false ;
445
445
}
446
446
447
- this . beforeAnimation ( shouldOpen ) ;
447
+ this . beforeAnimation ( shouldOpen , role ) ;
448
448
449
449
await this . loadAnimation ( ) ;
450
450
await this . startAnimation ( shouldOpen , animated ) ;
@@ -459,7 +459,7 @@ export class Menu implements ComponentInterface, MenuI {
459
459
return false ;
460
460
}
461
461
462
- this . afterAnimation ( shouldOpen ) ;
462
+ this . afterAnimation ( shouldOpen , role ) ;
463
463
464
464
return true ;
465
465
}
@@ -542,7 +542,7 @@ export class Menu implements ComponentInterface, MenuI {
542
542
}
543
543
544
544
private onWillStart ( ) : Promise < void > {
545
- this . beforeAnimation ( ! this . _isOpen ) ;
545
+ this . beforeAnimation ( ! this . _isOpen , GESTURE ) ;
546
546
return this . loadAnimation ( ) ;
547
547
}
548
548
@@ -624,11 +624,11 @@ export class Menu implements ComponentInterface, MenuI {
624
624
625
625
this . animation
626
626
. easing ( 'cubic-bezier(0.4, 0.0, 0.6, 1)' )
627
- . onFinish ( ( ) => this . afterAnimation ( shouldOpen ) , { oneTimeCallback : true } )
627
+ . onFinish ( ( ) => this . afterAnimation ( shouldOpen , GESTURE ) , { oneTimeCallback : true } )
628
628
. progressEnd ( playTo ? 1 : 0 , this . _isOpen ? 1 - newStepValue : newStepValue , 300 ) ;
629
629
}
630
630
631
- private beforeAnimation ( shouldOpen : boolean ) {
631
+ private beforeAnimation ( shouldOpen : boolean , role ?: string ) {
632
632
assert ( ! this . isAnimating , '_before() should not be called while animating' ) ;
633
633
634
634
// this places the menu into the correct location before it animates in
@@ -671,11 +671,11 @@ export class Menu implements ComponentInterface, MenuI {
671
671
if ( shouldOpen ) {
672
672
this . ionWillOpen . emit ( ) ;
673
673
} else {
674
- this . ionWillClose . emit ( ) ;
674
+ this . ionWillClose . emit ( { role } ) ;
675
675
}
676
676
}
677
677
678
- private afterAnimation ( isOpen : boolean ) {
678
+ private afterAnimation ( isOpen : boolean , role ?: string ) {
679
679
// keep opening/closing the menu disabled for a touch more yet
680
680
// only add listeners/css if it's enabled and isOpen
681
681
// and only remove listeners/css if it's not open
@@ -731,7 +731,7 @@ export class Menu implements ComponentInterface, MenuI {
731
731
}
732
732
733
733
// emit close event
734
- this . ionDidClose . emit ( ) ;
734
+ this . ionDidClose . emit ( { role } ) ;
735
735
736
736
// undo focus trapping so multiple menus don't collide
737
737
document . removeEventListener ( 'focus' , this . handleFocus , true ) ;
@@ -767,7 +767,7 @@ export class Menu implements ComponentInterface, MenuI {
767
767
* If the menu is disabled then we should
768
768
* forcibly close the menu even if it is open.
769
769
*/
770
- this . afterAnimation ( false ) ;
770
+ this . afterAnimation ( false , GESTURE ) ;
771
771
}
772
772
}
773
773
0 commit comments