From afa37bc7a5059c352aaf047053d169786576ca09 Mon Sep 17 00:00:00 2001 From: "nongzhou.yh" Date: Wed, 24 Feb 2021 16:51:00 +0800 Subject: [PATCH] fix: document.activeElement cannot get correct dom when the component is placed in shadow dom --- 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 318dca4c1..0d54e3fcf 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);