reactjs - 禁用或隐藏工具提示而不管理提示状态(材料 UI)
问题描述
因此,我有一个带有子选择的文本字段,而该子菜单又具有这样的子菜单:
<Tooltip
title={
features.length > 1
? features
.map((feat) => FeatureOptions.find((f) => f.value === feat).label)
.join(", ")
: ""
}
placement="'bottom-start'"
>
<TextField
label="ML Features"
variant="outlined"
margin="dense"
select
multiple
fullWidth
InputLabelProps={{ shrink: true, margin: "dense" }}
SelectProps={{
multiple: true,
value: features,
displayEmpty: true,
renderValue: (features) =>
features.length > 0
? features
.map((feat) => FeatureOptions.find((f) => f.value === feat).label)
.join(", ")
: "None",
onChange: (event) => setFeatures(event.target.value),
MenuProps,
classes: {
root: classes.selectOutlined,
outlined: classes.outlined,
iconOutlined: classes.iconOutlined
}
}}
>
{FeatureOptions.map((opt, i) => (
<MenuItem key={opt.value} value={opt.value} dense>
<Checkbox size="small" checked={features.includes(opt.value)} />
{opt.label}
</MenuItem>
))}
</TextField>
</Tooltip>
我的问题是工具提示第一次出现在菜单项上方并且非常不愉快,如下所示:
我真的只希望在将鼠标悬停在文本字段本身上时显示工具提示,但由于文本字段包含选择和菜单项,因此它也在那里被激活。
尝试的解决方案:这里是什么:
Material-UI Tooltip zIndex over MenuItem in Select component
遗憾的是,这不起作用,我也尝试弄乱PopperProps
但没有去。
预期行为:不要在我的菜单项上显示工具提示!
*我不想要的是开始以编程方式更改工具提示状态或 disableHover,我保持足够的状态,并且对它不感兴趣。
解决方案
增加菜单弹出框root
z-index
,使其高于工具提示z-index
const useStyles = makeStyles({
customMenu: {
// !important is applied because the default z-index is applied inline
zIndex: "1501 !important"
}
});
<Tooltip open={true} title="Sample Tooltip Title" arrow>
<TextField
label="ML Features"
variant="outlined"
margin="dense"
select
multiple
fullWidth
SelectProps={{
MenuProps: {
PopoverClasses: {
root: classes.customMenu
}
}
}}
>
<MenuItem value="foo">Foo</MenuItem>
<MenuItem value="bar">Bar</MenuItem>
</TextField>
</Tooltip>
推荐阅读
- python - VS Code 中的 Python:从子文件夹导入模块时出错
- python - 我该怎么做才能使我的约会时间变得可行?
- docker - 我可以使用 Hasura 快速入门进行生产吗?
- php - Docker:docker-compose 将文件从容器复制到主机
- android-studio - java.lang.IllegalStateException:在 android:onClick 的父或祖先上下文中找不到方法 onCreate_Clicked(View)
- python - Python - 使用异步工作人员池时如何处理 KeyboardInterrupt 并干净地退出?
- google-apps-script - 如何使用谷歌应用脚本复制特定表格并将其粘贴到文档的特定部分?
- r - 插入符号 CV 中的平均预测值
- javascript - 无法读取 BoostrapVue 模态中未定义的属性“显示”
- react-native - × TypeError: Cannot read property 'navigate' of undefined on React-Native expo react-navigation 5.xx