From ee9180ab5d2419b01e2ebe024966bc0103a92767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=97=AB=E6=98=8A?= Date: Wed, 24 Feb 2021 17:50:14 +0800 Subject: [PATCH] fix: document.activeElement cannot get correct dom when the component is placed in shadow dom (#221) Co-authored-by: nongzhou.yh --- src/hooks/usePickerInput.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/hooks/usePickerInput.ts b/src/hooks/usePickerInput.ts index 318dca4c1be8..0d54e3fcf3b3 100644 --- a/src/hooks/usePickerInput.ts +++ b/src/hooks/usePickerInput.ts @@ -112,7 +112,12 @@ export default function usePickerInput({ if (blurToCancel) { setTimeout(() => { - if (isClickOutside(document.activeElement)) { + let { activeElement } = document; + while (activeElement && activeElement.shadowRoot) { + activeElement = activeElement.shadowRoot.activeElement; + } + + if (isClickOutside(activeElement)) { onCancel(); } }, 0);