From 186e91b811017ce7fb843435c7ca9b1405b2faf5 Mon Sep 17 00:00:00 2001 From: navedqb Date: Wed, 15 Nov 2023 23:47:20 +0530 Subject: [PATCH 1/2] Improve focusable element handling --- components/lib/focustrap/FocusTrap.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/lib/focustrap/FocusTrap.js b/components/lib/focustrap/FocusTrap.js index f9961a9b0b..0c9968906e 100644 --- a/components/lib/focustrap/FocusTrap.js +++ b/components/lib/focustrap/FocusTrap.js @@ -40,7 +40,7 @@ const FocusTrap = BaseFocusTrap.extend('focustrap', { : DomHandler.getFirstFocusableElement(el, this.getComputedSelector(el.$_pfocustrap_focusableselector)) : DomHandler.getFirstFocusableElement(_el); - return ObjectUtils.isNotEmpty(focusableElement) ? focusableElement : findNextFocusableElement(_el.nextSibling); + return ObjectUtils.isNotEmpty(focusableElement) ? focusableElement : _el.nextSibling ? findNextFocusableElement(_el.nextSibling) : null; }; DomHandler.focus(findNextFocusableElement(mutation.nextSibling)); From 8764814a1994efdfcb5894ee943db949a8b8ba71 Mon Sep 17 00:00:00 2001 From: navedqb <109583873+navedqb@users.noreply.github.com> Date: Thu, 16 Nov 2023 00:00:43 +0530 Subject: [PATCH 2/2] Refactor: Improve error handling --- components/lib/focustrap/FocusTrap.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/lib/focustrap/FocusTrap.js b/components/lib/focustrap/FocusTrap.js index 0c9968906e..44f984449f 100644 --- a/components/lib/focustrap/FocusTrap.js +++ b/components/lib/focustrap/FocusTrap.js @@ -40,7 +40,7 @@ const FocusTrap = BaseFocusTrap.extend('focustrap', { : DomHandler.getFirstFocusableElement(el, this.getComputedSelector(el.$_pfocustrap_focusableselector)) : DomHandler.getFirstFocusableElement(_el); - return ObjectUtils.isNotEmpty(focusableElement) ? focusableElement : _el.nextSibling ? findNextFocusableElement(_el.nextSibling) : null; + return ObjectUtils.isNotEmpty(focusableElement) ? focusableElement : _el.nextSibling && findNextFocusableElement(_el.nextSibling); }; DomHandler.focus(findNextFocusableElement(mutation.nextSibling));