@@ -7,14 +7,14 @@ import { shouldUseCloseWatcher } from '@utils/hardware-back-button';
77import type { Attributes } from '@utils/helpers' ;
88import { inheritAriaAttributes , assert , clamp , isEndSide as isEnd } from '@utils/helpers' ;
99import { menuController } from '@utils/menu-controller' ;
10- import { getPresentedOverlay } from '@utils/overlays' ;
10+ import { BACKDROP , GESTURE , getPresentedOverlay } from '@utils/overlays' ;
1111import { hostContext } from '@utils/theme' ;
1212
1313import { config } from '../../global/config' ;
1414import { getIonMode } from '../../global/ionic-global' ;
1515import type { Animation , Gesture , GestureDetail } from '../../interface' ;
1616
17- import type { MenuChangeEventDetail , MenuI , MenuType , Side } from './menu-interface' ;
17+ import type { MenuChangeEventDetail , MenuCloseEventDetail , MenuI , MenuType , Side } from './menu-interface' ;
1818
1919const iosEasing = 'cubic-bezier(0.32,0.72,0,1)' ;
2020const mdEasing = 'cubic-bezier(0.0,0.0,0.2,1)' ;
@@ -179,7 +179,7 @@ export class Menu implements ComponentInterface, MenuI {
179179 /**
180180 * Emitted when the menu is about to be closed.
181181 */
182- @Event ( ) ionWillClose ! : EventEmitter < void > ;
182+ @Event ( ) ionWillClose ! : EventEmitter < MenuCloseEventDetail > ;
183183 /**
184184 * Emitted when the menu is open.
185185 */
@@ -188,7 +188,7 @@ export class Menu implements ComponentInterface, MenuI {
188188 /**
189189 * Emitted when the menu is closed.
190190 */
191- @Event ( ) ionDidClose ! : EventEmitter < void > ;
191+ @Event ( ) ionDidClose ! : EventEmitter < MenuCloseEventDetail > ;
192192
193193 /**
194194 * Emitted when the menu state is changed.
@@ -331,14 +331,14 @@ export class Menu implements ComponentInterface, MenuI {
331331 if ( shouldClose ) {
332332 ev . preventDefault ( ) ;
333333 ev . stopPropagation ( ) ;
334- this . close ( ) ;
334+ this . close ( undefined , BACKDROP ) ;
335335 }
336336 }
337337 }
338338
339339 onKeydown ( ev : KeyboardEvent ) {
340340 if ( ev . key === 'Escape' ) {
341- this . close ( ) ;
341+ this . close ( undefined , BACKDROP ) ;
342342 }
343343 }
344344
@@ -375,8 +375,8 @@ export class Menu implements ComponentInterface, MenuI {
375375 * it returns `false`.
376376 */
377377 @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 ) ;
380380 }
381381
382382 /**
@@ -393,8 +393,8 @@ export class Menu implements ComponentInterface, MenuI {
393393 * If the operation can't be completed successfully, it returns `false`.
394394 */
395395 @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 ) ;
398398 }
399399
400400 private trapKeyboardFocus ( ev : Event , doc : Document ) {
@@ -438,13 +438,13 @@ export class Menu implements ComponentInterface, MenuI {
438438 }
439439 }
440440
441- async _setOpen ( shouldOpen : boolean , animated = true ) : Promise < boolean > {
441+ async _setOpen ( shouldOpen : boolean , animated = true , role ?: string ) : Promise < boolean > {
442442 // If the menu is disabled or it is currently being animated, let's do nothing
443443 if ( ! this . _isActive ( ) || this . isAnimating || shouldOpen === this . _isOpen ) {
444444 return false ;
445445 }
446446
447- this . beforeAnimation ( shouldOpen ) ;
447+ this . beforeAnimation ( shouldOpen , role ) ;
448448
449449 await this . loadAnimation ( ) ;
450450 await this . startAnimation ( shouldOpen , animated ) ;
@@ -459,7 +459,7 @@ export class Menu implements ComponentInterface, MenuI {
459459 return false ;
460460 }
461461
462- this . afterAnimation ( shouldOpen ) ;
462+ this . afterAnimation ( shouldOpen , role ) ;
463463
464464 return true ;
465465 }
@@ -542,7 +542,7 @@ export class Menu implements ComponentInterface, MenuI {
542542 }
543543
544544 private onWillStart ( ) : Promise < void > {
545- this . beforeAnimation ( ! this . _isOpen ) ;
545+ this . beforeAnimation ( ! this . _isOpen , GESTURE ) ;
546546 return this . loadAnimation ( ) ;
547547 }
548548
@@ -624,11 +624,11 @@ export class Menu implements ComponentInterface, MenuI {
624624
625625 this . animation
626626 . 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 } )
628628 . progressEnd ( playTo ? 1 : 0 , this . _isOpen ? 1 - newStepValue : newStepValue , 300 ) ;
629629 }
630630
631- private beforeAnimation ( shouldOpen : boolean ) {
631+ private beforeAnimation ( shouldOpen : boolean , role ?: string ) {
632632 assert ( ! this . isAnimating , '_before() should not be called while animating' ) ;
633633
634634 // this places the menu into the correct location before it animates in
@@ -671,11 +671,11 @@ export class Menu implements ComponentInterface, MenuI {
671671 if ( shouldOpen ) {
672672 this . ionWillOpen . emit ( ) ;
673673 } else {
674- this . ionWillClose . emit ( ) ;
674+ this . ionWillClose . emit ( { role } ) ;
675675 }
676676 }
677677
678- private afterAnimation ( isOpen : boolean ) {
678+ private afterAnimation ( isOpen : boolean , role ?: string ) {
679679 // keep opening/closing the menu disabled for a touch more yet
680680 // only add listeners/css if it's enabled and isOpen
681681 // and only remove listeners/css if it's not open
@@ -731,7 +731,7 @@ export class Menu implements ComponentInterface, MenuI {
731731 }
732732
733733 // emit close event
734- this . ionDidClose . emit ( ) ;
734+ this . ionDidClose . emit ( { role } ) ;
735735
736736 // undo focus trapping so multiple menus don't collide
737737 document . removeEventListener ( 'focus' , this . handleFocus , true ) ;
@@ -767,7 +767,7 @@ export class Menu implements ComponentInterface, MenuI {
767767 * If the menu is disabled then we should
768768 * forcibly close the menu even if it is open.
769769 */
770- this . afterAnimation ( false ) ;
770+ this . afterAnimation ( false , GESTURE ) ;
771771 }
772772 }
773773
0 commit comments