reactjs - 在 Semantic-UI-React Modal 中显示 VisX 图会导致 z-index 出现问题
问题描述
我在 Semantic-UI-React Modal 中添加了一个 VisX 图。
该图本身正确显示了工具提示、十字准线和系列字形:
但是当它处于模态时,所有这些都出现在模态下方:
我可以在我为renderTooltip
属性提供的组件中使用更高的 z-index 重建工具提示,但它缺少十字准线和系列字形:
由于这些元素是在悬停时添加到 DOM 中的,因此我无法在devtools 中捕获它们并查看它们具有和继承的样式。
有什么方法可以设置他们的 z-index 或以其他方式解决这个问题吗?
const Visx: FC = () => {
return (
<Modal open>
<Modal.Content>
<XYChart width={900} height={500} xScale={{ type: 'time' }} yScale={{ type: 'linear' }}>
<Grid rows numTicks={maxCount + 1} />
<Axis
orientation="left"
label="Play count"
numTicks={maxCount + 1}
tickFormat={(value) => {
return value;
}}
/>
<Axis orientation="bottom" label="Date" />
<LineSeries dataKey="plays" data={data} {...accessors} />
<Tooltip
showHorizontalCrosshair
showVerticalCrosshair
snapTooltipToDatumX
snapTooltipToDatumY
showSeriesGlyphs
showDatumGlyph
renderTooltip={({ tooltipData }) => {
const datum = tooltipData.nearestDatum?.datum as DataPoint | null;
return (
<div>
{datum?.count || 'no'} plays on {moment(datum?.date).format('MMM D, YYYY')}
</div>
);
}}
/>
</XYChart>
</Modal.Content>
</Modal>
);
};
解决方案
通过添加这个全局 CSS 样式来修复它:
.visx-tooltip {
z-index: 9999; /* or whatever height is appropriate */
}
推荐阅读
- firebase - 是否可以设置 Firebase 存储规则来检查 Firebase Firestore 中的参数?
- javascript - Mac 上的 Visual Studio Code 上出现无法解释的 Typescript 编译器错误
- jquery - 未捕获的 SyntaxError:JQuery UI Datepicker 中分配的左侧无效
- javascript - Leaflet-Routing-Machine:TypeError:无法读取未定义的属性“getSize”
- python - 通过 selenium 获取此元素属性
- c# - 使用 C# 和 html 将多个图像添加到 .NetCore 中的表
- ssl - 如何解决“NSS 错误 -12276 (SSL_ERROR_BAD_CERT_DOMAIN)”
- python - 遇到另一个字母时分裂
- python - 使用循环根据在其他列行中找到的内容在 python 中填充新列的行
- ruby-on-rails - 使用 rails 形式的参数