From eb0b15e28064320067e1e69dbb92128c6046f7c9 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Wed, 18 Aug 2021 17:55:30 +0200 Subject: [PATCH] fix(cdk/a11y): error on firefox We seem to hitting an error on Firefox when calling `closest` inside a unit test. These changes add a null check to work around the issue. --- src/cdk/a11y/focus-trap/event-listener-inert-strategy.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cdk/a11y/focus-trap/event-listener-inert-strategy.ts b/src/cdk/a11y/focus-trap/event-listener-inert-strategy.ts index 8fc31ea17539..afd11c02c970 100644 --- a/src/cdk/a11y/focus-trap/event-listener-inert-strategy.ts +++ b/src/cdk/a11y/focus-trap/event-listener-inert-strategy.ts @@ -52,8 +52,7 @@ export class EventListenerFocusTrapInertStrategy implements FocusTrapInertStrate // Don't refocus if target was in an overlay, because the overlay might be associated // with an element inside the FocusTrap, ex. mat-select. - if (target && !focusTrapRoot.contains(target) && - target.closest('div.cdk-overlay-pane') === null) { + if (target && !focusTrapRoot.contains(target) && !target.closest?.('div.cdk-overlay-pane')) { // Some legacy FocusTrap usages have logic that focuses some element on the page // just before FocusTrap is destroyed. For backwards compatibility, wait // to be sure FocusTrap is still enabled before refocusing.