@@ -38,7 +38,7 @@ const createController = <Opts extends object, HTMLElm>(tagName: string) => {
38
38
return dismissOverlay ( document , data , role , tagName , id ) ;
39
39
} ,
40
40
async getTop ( ) : Promise < HTMLElm | undefined > {
41
- return getOverlay ( document , tagName ) as any ;
41
+ return getPresentedOverlay ( document , tagName ) as any ;
42
42
} ,
43
43
} ;
44
44
} ;
@@ -175,7 +175,10 @@ const focusLastDescendant = (ref: Element, overlay: HTMLIonOverlayElement) => {
175
175
* Should NOT include: Toast
176
176
*/
177
177
const trapKeyboardFocus = ( ev : Event , doc : Document ) => {
178
- const lastOverlay = getOverlay ( doc , 'ion-alert,ion-action-sheet,ion-loading,ion-modal,ion-picker,ion-popover' ) ;
178
+ const lastOverlay = getPresentedOverlay (
179
+ doc ,
180
+ 'ion-alert,ion-action-sheet,ion-loading,ion-modal,ion-picker,ion-popover'
181
+ ) ;
179
182
const target = ev . target as HTMLElement | null ;
180
183
181
184
/**
@@ -346,7 +349,7 @@ const connectListeners = (doc: Document) => {
346
349
347
350
// handle back-button click
348
351
doc . addEventListener ( 'ionBackButton' , ( ev ) => {
349
- const lastOverlay = getOverlay ( doc ) ;
352
+ const lastOverlay = getPresentedOverlay ( doc ) ;
350
353
if ( lastOverlay ?. backdropDismiss ) {
351
354
( ev as BackButtonEvent ) . detail . register ( OVERLAY_BACK_BUTTON_PRIORITY , ( ) => {
352
355
return lastOverlay . dismiss ( undefined , BACKDROP ) ;
@@ -357,7 +360,7 @@ const connectListeners = (doc: Document) => {
357
360
// handle ESC to close overlay
358
361
doc . addEventListener ( 'keydown' , ( ev ) => {
359
362
if ( ev . key === 'Escape' ) {
360
- const lastOverlay = getOverlay ( doc ) ;
363
+ const lastOverlay = getPresentedOverlay ( doc ) ;
361
364
if ( lastOverlay ?. backdropDismiss ) {
362
365
lastOverlay . dismiss ( undefined , BACKDROP ) ;
363
366
}
@@ -373,7 +376,7 @@ export const dismissOverlay = (
373
376
overlayTag : string ,
374
377
id ?: string
375
378
) : Promise < boolean > => {
376
- const overlay = getOverlay ( doc , overlayTag , id ) ;
379
+ const overlay = getPresentedOverlay ( doc , overlayTag , id ) ;
377
380
if ( ! overlay ) {
378
381
return Promise . reject ( 'overlay does not exist' ) ;
379
382
}
@@ -399,13 +402,17 @@ const getPresentedOverlays = (doc: Document, overlayTag?: string): HTMLIonOverla
399
402
} ;
400
403
401
404
/**
402
- * Returns an overlay element
405
+ * Returns a presented overlay element.
403
406
* @param doc The document to find the element within.
404
407
* @param overlayTag The selector for the overlay, defaults to Ionic overlay components.
405
408
* @param id The unique identifier for the overlay instance.
406
409
* @returns The overlay element or `undefined` if no overlay element is found.
407
410
*/
408
- export const getOverlay = ( doc : Document , overlayTag ?: string , id ?: string ) : HTMLIonOverlayElement | undefined => {
411
+ export const getPresentedOverlay = (
412
+ doc : Document ,
413
+ overlayTag ?: string ,
414
+ id ?: string
415
+ ) : HTMLIonOverlayElement | undefined => {
409
416
const overlays = getPresentedOverlays ( doc , overlayTag ) ;
410
417
return id === undefined ? overlays [ overlays . length - 1 ] : overlays . find ( ( o ) => o . id === id ) ;
411
418
} ;
0 commit comments