-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useClickAway判断不对 #1641
Comments
感谢你的反馈,排查的情况是这样的:
|
我们可能需要讨论下是否要针对这一情况处理呢 @brickspert @crazylxr
各有一些优点和缺点,需要讨论看一下哈 @cl1107 欢迎提出你的想法💡 |
上面的情况是在 react17 之后的,react17 之后,事件默认绑定在了根元素 在 react17 以前,react 默认绑定事件在 这个情况下我认为 ahooks 是合理的,因为 可以这两个例子: |
我感觉改成mousedown和touchstart的效果更符合预期,点击第二个CodeSandbox文字,对于第一个CodeSandbox而言就是clickAway了,应该是要触发第一个的clickAway的回调函数的 |
是的,不过默认如果改成了 |
遇到类似问题,useClickAway 绑定的元素(假设为Parent)中的子元素(假设为Child1)如果销毁了,并且产生了其他的子元素(假设为Child2),点击Child2也会触发useClickAway。 |
遇到类似问题。 如果在 Modal 上使用
|
楼主的使用方式,违背了 useClickAway 的设计用途:“监听目标元素外的点击事件”。 请考虑把不想触发 useClickAway 的元素放在 ref 引用的 dom 范围里(可以解决楼主在线 demo 里的问题): + <div ref={ref1} style={{ height: 100 }}>
<div
onClick={(e) => {
e.stopPropagation();
console.log("CodeSandbox");
setVisible(true);
}}
>
CodeSandbox
</div>
- <div ref={ref1} style={{ display: visible ? "block" : "none" }}>
+ <div style={{ display: visible ? "block" : "none" }}>
foobar
</div>
</div> |
复现链接:https://codesandbox.io/s/ahooks-clickaway-bug-v5t3zp?file=/src/App.js
这是使用react-use时的效果
https://user-images.githubusercontent.com/21985353/170660093-99cc3097-0ad9-45fa-866e-f8ab404aaf7a.mov
这是使用ahooks时的效果
https://user-images.githubusercontent.com/21985353/170660185-3abb028c-d082-4c59-8fda-46993ebbfd5a.mov
The text was updated successfully, but these errors were encountered: