我正在开发一个使用模式对话框的react-bootstrap Web应用程序。多个模式对话框在应用程序的不同位置呈现(例如,在不同的组件、路由/开关构造、不同的层次结构级别等)。但是,一次只有一个模式对话框处于活动状态。
到目前为止,我对这种方法从未遇到过问题(我的反应相对较新)。不知何故,我最终陷入了两个模式对话框“半冻结”的情况?它们各自按预期打开和关闭(并且按钮也可以工作),但我无法再编辑其中的表单(例如也无法选择标题文本)。
两个对话框都可以工作,直到我在其他地方添加更多对话框(至少这是我的猜测)。使用多个模式对话框时需要注意什么吗?或者更一般地说,像在哪里渲染模式对话框?
<Modal show={show} onHide={discardChanges} backdrop={edited ? "static" : true}
keyboard={edited ? false : true} size="lg" centered>
<Modal.Header closeButton>
<Modal.Title>{t("edit tour")}</Modal.Title>
</Modal.Header>
<Modal.Body>
<TourContainer tourTemplate={editableTourTemplate} pointsOfInterest={pointsOfInterest}
dispatch={dispatchEditableTourTemplate} validated={edited} />
</Modal.Body>
<Modal.Footer>
<Button onClick={saveChanges} disabled={!(edited && editableTourTemplate.valid)}>
{t("save")}
</Button>
<Button onClick={discardChanges} variant="outline-primary">{t("cancel")}</Button>
</Modal.Footer>
</Modal>
它在另一个组件中渲染,如下所示:
<Col>
<button onClick={showEditModal} className="bg-white border-0">
<img src="/img/pencil.png" alt="Pencil" height="25" width="25" />
</button>
<TourEditModal show={editModalVisible} hide={hideEditModal}
tourTemplate={tourTemplate}
pointsOfInterest={pointsOfInterest}
update={updateTourTemplates.update} />
</Col>
这两个模态出现这种行为的原因是我将它们移到了 NavLink 元素内。这个 NavLink 元素在鼠标按下时有一个 PreventDefault() ,因为我不喜欢那里的按钮焦点。自然地,模态框变得无法聚焦。
一旦我将模态框移出 NavLink 元素,它们就会再次按预期工作。
I have the same problem once, my code would look like this.
<Modal>
<Link className='p-3'> <Button> <Add New Record/> </Button> </Link>
</Modal>
- The Button is very unresponsive.
So what i did is i remove them inside the Link, and make them a single base.