IsolatedEventContainer 是一个已弃用的 WordPress 组件,用于包装 UI 元素(如模态框和弹出框),以防止特定事件(如 mousedown)传播到容器外部,从而避免外部 UI 的意外交互。事件在组件内部仍正常工作。
import { IsolatedEventContainer } from '@wordpress/components';
const MyModal = () => {
return (
<IsolatedEventContainer
className="component-some_component"
onClick={ clickHandler }
>
<p>This is an isolated component</p>
</IsolatedEventContainer>
);
};Deprecated
This is a container that prevents certain events from propagating outside of the container. This is used to wrap
UI elements such as modals and popovers where the propagated event can cause problems. The event continues to work
inside the component.
For example, a mousedown event in a modal container can propagate to the surrounding DOM, causing UI outside of the
modal to be interacted with.
The current isolated events are:
mousedown event handlers, such as selectionCreates a custom component that won’t propagate mousedown events outside of the component.
import { IsolatedEventContainer } from '@wordpress/components';
const MyModal = () => {
return (
<IsolatedEventContainer
className="component-some_component"
onClick={ clickHandler }
>
<p>This is an isolated component</p>
</IsolatedEventContainer>
);
};
All props are passed as-is to the <IsolatedEventContainer />