-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Popover 使用ref打开失败 #6731
Comments
看看 |
https://github.com/ant-design/ant-design-mobile/blob/master/src/components/popover/popover.tsx#L198 |
当组件Popover指定trigger='click'后,点击该Popover以外的元素,预期会隐藏该Popover(点击事件冒泡)。 function App() {
const ref = React.createRef();
return (
<div className="App">
<h1>Popover With trigger='click'</h1>
<Popover
ref={ref}
content="Hello World"
trigger="click"
placement="right"
>
<Button>点我</Button>
</Popover>
<br />
<Button
onClick={(e) => {
e.stopPropagation(); // 阻止冒泡事件
ref.current.show();
}}
>
点我通过ref控制
</Button>
</div>
);
} demo地址: |
这个可以了 |
这样也可以,但是可能不是每个使用者都知道要加上这行代码才能生效。。。 |
还可以使用定时器,先让Povover触发自身关闭完成后,再使用ref.current.show()来展示。 function App() {
const ref = React.createRef();
return (
<div className="App">
<h1>Popover With trigger='click'</h1>
<Popover
ref={ref}
content="Hello World"
trigger="click"
placement="right"
>
<Button>点我</Button>
</Popover>
<br />
<Button
onClick={(e) => {
setTimeout(() => { // 使用定时器
ref.current.show();
});
}}
>
点我通过ref控制
</Button>
</div>
);
} |
Version of antd-mobile
5.37.1
Operating system and its version
iOS, Android, Others
Browser and its version
所有手机上均不生效
Sandbox to reproduce
No response
What happened?
如图所示,通过menu 图片打开Popover 一切正常,但是line1 的div中通过ref打开pop时,页面没有任何反应。
Relevant log output
The text was updated successfully, but these errors were encountered: