This repository was archived by the owner on Jan 13, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +26
-1
lines changed
Expand file tree Collapse file tree 6 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -64,4 +64,7 @@ export interface MDCMenuSurfaceAdapter {
6464
6565 /** Emits an event when the menu surface is opened. */
6666 notifyOpen ( ) : void ;
67+
68+ /** Emits an event when the menu surface is opening. */
69+ notifyOpening ( ) : void ;
6770}
Original file line number Diff line number Diff line change @@ -160,6 +160,8 @@ export class MDCMenuSurface extends MDCComponent<MDCMenuSurfaceFoundation> {
160160 } ,
161161 notifyOpen : ( ) =>
162162 this . emit ( MDCMenuSurfaceFoundation . strings . OPENED_EVENT , { } ) ,
163+ notifyOpening : ( ) =>
164+ this . emit ( MDCMenuSurfaceFoundation . strings . OPENING_EVENT , { } ) ,
163165 isElementInContainer : ( el ) => this . root . contains ( el ) ,
164166 isRtl : ( ) =>
165167 getComputedStyle ( this . root ) . getPropertyValue ( 'direction' ) === 'rtl' ,
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ const strings = {
3636 CLOSED_EVENT : 'MDCMenuSurface:closed' ,
3737 CLOSING_EVENT : 'MDCMenuSurface:closing' ,
3838 OPENED_EVENT : 'MDCMenuSurface:opened' ,
39+ OPENING_EVENT : 'MDCMenuSurface:opening' ,
3940 FOCUSABLE_ELEMENTS : [
4041 'button:not(:disabled)' ,
4142 '[href]:not([aria-disabled="true"])' ,
Original file line number Diff line number Diff line change @@ -82,8 +82,9 @@ export class MDCMenuSurfaceFoundation extends
8282 restoreFocus : ( ) => undefined ,
8383
8484 notifyClose : ( ) => undefined ,
85- notifyOpen : ( ) => undefined ,
8685 notifyClosing : ( ) => undefined ,
86+ notifyOpen : ( ) => undefined ,
87+ notifyOpening : ( ) => undefined ,
8788 } ;
8889 // tslint:enable:object-literal-sort-keys
8990 }
@@ -238,6 +239,7 @@ export class MDCMenuSurfaceFoundation extends
238239 return ;
239240 }
240241
242+ this . adapter . notifyOpening ( ) ;
241243 this . adapter . saveFocus ( ) ;
242244
243245 if ( this . isQuickOpen ) {
Original file line number Diff line number Diff line change @@ -316,6 +316,15 @@ describe('MDCMenuSurface', () => {
316316 expect ( handler ) . toHaveBeenCalled ( ) ;
317317 } ) ;
318318
319+ it ( `adapter#notifyOpening fires an ${ strings . OPENING_EVENT } custom event` ,
320+ ( ) => {
321+ const { root, component} = setupTest ( ) ;
322+ const handler = jasmine . createSpy ( 'notifyOpening handler' ) ;
323+ root . addEventListener ( strings . OPENING_EVENT , handler ) ;
324+ ( component . getDefaultFoundation ( ) as any ) . adapter . notifyOpening ( ) ;
325+ expect ( handler ) . toHaveBeenCalled ( ) ;
326+ } ) ;
327+
319328 it ( 'adapter#restoreFocus restores focus saved by adapter#saveFocus' , ( ) => {
320329 const { root, component} = setupTest ( { open : true } ) ;
321330 const button = document . createElement ( 'button' ) ;
Original file line number Diff line number Diff line change @@ -196,6 +196,7 @@ describe('MDCMenuSurfaceFoundation', () => {
196196 'notifyClose' ,
197197 'notifyClosing' ,
198198 'notifyOpen' ,
199+ 'notifyOpening' ,
199200 'isElementInContainer' ,
200201 'isRtl' ,
201202 'setTransformOrigin' ,
@@ -264,6 +265,13 @@ describe('MDCMenuSurfaceFoundation', () => {
264265 . toHaveBeenCalledWith ( cssClasses . ANIMATING_OPEN ) ;
265266 } ) ;
266267
268+ testFoundation (
269+ '#open emits the opening event at the beginning of the animation' ,
270+ ( { foundation, mockAdapter} ) => {
271+ foundation . open ( ) ;
272+ expect ( mockAdapter . notifyOpening ) . toHaveBeenCalled ( ) ;
273+ } ) ;
274+
267275 testFoundation (
268276 '#open emits the open event at the end of the animation' ,
269277 ( { foundation, mockAdapter} ) => {
You can’t perform that action at this time.
0 commit comments