Clarify behavior of Portal when target changes dynamically #8262
-
Mantine Portal dynamic target behaviorIssue descriptionWhen using Instead, Minimal reproductionimport * as React from 'react';
import { Portal } from '@mantine/core';
const OUTLET_NAME = 'outlet';
const A = () => <div><h3>A</h3><div id={OUTLET_NAME} /></div>;
const B = () => <div><h3>B</h3><div id={OUTLET_NAME} /></div>;
const C = () => <div><h3>C</h3><div id={OUTLET_NAME} /></div>;
const VIEW_MAP = { A, B, C };
export default function App() {
const [view, setView] = React.useState<'A' | 'B' | 'C'>('A');
const Component = VIEW_MAP[view];
return (
<div>
<button onClick={() => setView('A')}>Show A</button>
<button onClick={() => setView('B')}>Show B</button>
<button onClick={() => setView('C')}>Show C</button>
<Component />
<Portal target={`#${OUTLET_NAME}`}>
<span>view name: {view}</span>
</Portal>
</div>
);
} Steps to reproduce:
![]() Live demo & source
Expected behaviorIt would be useful if either:
ProposalAdd a note to the documentation explaining this behavior:
Workarounds
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Thanks for reporting, I'll update the documentation to include the information about the target prop. |
Beta Was this translation helpful? Give feedback.
Do you use the Portal component as is and want to modify it? Or you use it as part of another component, like Modal? In first case, you can use
createPortal
function on your side directly. In the second case, I'd use thekey
prop.