From 4611de11849a9720c953d5559d98a2fb0e587682 Mon Sep 17 00:00:00 2001 From: Christian Vuerings Date: Mon, 25 Mar 2024 09:23:00 -0700 Subject: [PATCH] Modal: add extra focus element check --- .changeset/soft-melons-yell.md | 5 +++++ packages/syntax-core/src/Modal/FocusTrap.tsx | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changeset/soft-melons-yell.md diff --git a/.changeset/soft-melons-yell.md b/.changeset/soft-melons-yell.md new file mode 100644 index 00000000..25258c5c --- /dev/null +++ b/.changeset/soft-melons-yell.md @@ -0,0 +1,5 @@ +--- +"@cambly/syntax-core": minor +--- + +Modal: add extra focus element check diff --git a/packages/syntax-core/src/Modal/FocusTrap.tsx b/packages/syntax-core/src/Modal/FocusTrap.tsx index 9dc78f63..dc74f7af 100644 --- a/packages/syntax-core/src/Modal/FocusTrap.tsx +++ b/packages/syntax-core/src/Modal/FocusTrap.tsx @@ -22,8 +22,8 @@ function queryFocusableAll(el: HTMLDivElement): NodeListOf { return el.querySelectorAll(selector); } -const focusElement = (el: HTMLElement) => { - if (typeof el.focus === "function") { +const focusElement = (el?: HTMLElement) => { + if (el && typeof el.focus === "function") { el.focus(); } };