Skip to content

Commit 53eabff

Browse files
1) fix click event issue
2) popper should be open only when its children is not equal to null and its length is greater then zero
1 parent 6d8558c commit 53eabff

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ function ReactCustomSearchList(props) {
6363
},
6464
[onKeyDown],
6565
);
66+
useEffect(() => {
67+
const rEl = document.documentElement,
68+
input = rootRef.current.querySelector('input');
69+
const mousedown = (e) => open && e.target == input && e.stopImmediatePropagation();
70+
rEl.addEventListener('click', mousedown, {useCapture: true});
71+
return () => {
72+
rEl.removeEventListener('click', mousedown, {useCapture: true});
73+
};
74+
}, [open]);
6675
useEffect(() => {
6776
const click = (e) => {
6877
setTimeout(() => {
@@ -80,7 +89,7 @@ function ReactCustomSearchList(props) {
8089
}, [open]);
8190
return (
8291
<div className={`rc-search-suggestions-root ${theme}${corner ? ' corner' : ''}`} style={rootStyle}>
83-
{open ? (
92+
{open && children != null && children.length ? (
8493
<Popper
8594
rootRef={rootRef}
8695
style={popperStyle}

0 commit comments

Comments
 (0)