Replies: 1 comment 4 replies
-
Hi @clljf! I'm Dosu and I’m helping the ant-design-mobile team. 这是 iOS 浏览器的已知问题:即使元素被 Modal 的 overflow 或遮罩隐藏,只要它还在 DOM 里、z-index 足够高,iOS 仍然会让它响应点击事件(pointer-events 泄漏)。安卓和 H5 没有这个 bug。 解决方法通常有两种:
举例: <Modal
// ...你的其他 props
content={
<div style={{ position: 'relative' }}>
<div
className="size-[2.75rem] absolute bottom-[-4.625rem] left-1/2 translate-x-[-50%] z-[1999] bg-red-500"
onClick={async () => { alert(1); }}
style={{
pointerEvents: 'auto',
// 你可以用 clip-path 或 overflow:hidden 的父容器裁剪
}}
/>
{/* 额外遮罩,盖住超出 Modal 的部分 */}
<div
style={{
position: 'absolute',
left: 0,
right: 0,
bottom: '-4.625rem',
height: '4.625rem',
pointerEvents: 'auto',
background: 'transparent',
zIndex: 2000
}}
onClick={e => e.stopPropagation()}
/>
</div>
}
/> 或者直接让 Modal 的内容区加 ant-design-mobile FAQ 也提到 iOS 下 fixed/absolute 定位的兼容性问题,建议用 absolute 替代 fixed,并注意滚动和遮罩结构设计,详见 FAQ。 本质上,这个问题只能通过结构和 CSS 规避,库本身没有自动处理。 To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
<Modal

visible={showModal}
destroyOnClose
onClose={() => {
setShowModal(false);
}}
closeOnMaskClick
bodyClassName="!p-0"
maskClassName="!p-0"
className="custom-modal_w327"
content={
<div
className="size-[2.75rem] absolute bottom-[-4.625rem] left-1/2 translate-x-[-50%] z-[1999] bg-red-500"
onClick={async () => {
alert(1);
}}
/>}
/>
可以看到这个正方形只展示了一部分,同时点击下半部分阴影处仍然会触发点击事件,如何解决不被隐藏的问题,安卓和h5都没有问题
Beta Was this translation helpful? Give feedback.
All reactions