Skip to content

Commit ee9180a

Browse files
rzyanhaonongzhou.yh
andauthored
fix: document.activeElement cannot get correct dom when the component is placed in shadow dom (#221)
Co-authored-by: nongzhou.yh <[email protected]>
1 parent c0963ac commit ee9180a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/hooks/usePickerInput.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,12 @@ export default function usePickerInput({
112112

113113
if (blurToCancel) {
114114
setTimeout(() => {
115-
if (isClickOutside(document.activeElement)) {
115+
let { activeElement } = document;
116+
while (activeElement && activeElement.shadowRoot) {
117+
activeElement = activeElement.shadowRoot.activeElement;
118+
}
119+
120+
if (isClickOutside(activeElement)) {
116121
onCancel();
117122
}
118123
}, 0);

0 commit comments

Comments
 (0)