[英]React material-ui tooltip hover over(fire an event trigger when the item is disabled)
i know that disabled item doesn't trigger any event and the possible workaround is to wrap my elements in another which i tried but it didn't work.我知道禁用的项目不会触发任何事件,可能的解决方法是将我的元素包装在另一个我尝试过但没有用的元素中。 I can't think of another solution to hover over a disabled tooltip.我想不出另一种将鼠标悬停在禁用工具提示上的解决方案。 Here's the sandbox i have这是我的沙箱
import React from "react";
import "./styles.css";
import MenuItem from "@material-ui/core/MenuItem";
import Tooltip from "@material-ui/core/Tooltip";
export default function App() {
const content = (
<Tooltip title="hover over">
<p>Hey</p>
</Tooltip>
);
return (
<MenuItem disabled component="div">
{content}
</MenuItem>
);
}
https://codesandbox.io/s/beautiful-wing-mgowh?fontsize=14&hidenavigation=1&theme=dark https://codesandbox.io/s/beautiful-wing-mgowh?fontsize=14&hidenavigation=1&theme=dark
In order to get the tooltip to show you need to wrap the disabled MenuItem
with a <div>
and then wrap it with the Tooltip
:为了让工具提示显示,您需要用<div>
包装禁用的MenuItem
,然后用Tooltip
包装它:
export default function App() {
const content = (
<span title="lol">
<p title="lol">Hey</p>
</span>
);
return (
<Tooltip
title="hover over"
>
<div style={{ display: "inline-block" }}>
<MenuItem disabled component="div">
{content}
</MenuItem>
</div>
</Tooltip>
);
}
Checkout this sandbox in which I also used PopperProps
on the Tooltip
in order to get it to show next to the MenuItem
.检查这个沙箱,我还在Tooltip
上使用了PopperProps
以便让它显示在MenuItem
旁边。 You can play around with the marginTop
and marginLeft
values in order to adjust it to your use-case.您可以使用marginTop
和marginLeft
值来调整它以适应您的用例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.