Move Dialog with resize/zoom events
This commit is contained in:
parent
a581a6b133
commit
a8363ab53f
|
|
@ -37,6 +37,10 @@ export const Dialog: React.FC<React.PropsWithChildren<DialogProps>> = ({
|
||||||
}) => {
|
}) => {
|
||||||
const dialogRef = React.useRef<HTMLDialogElement>(null);
|
const dialogRef = React.useRef<HTMLDialogElement>(null);
|
||||||
|
|
||||||
|
// Allow window dimension changes to force a rerender
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
const [_, setRecalculateDimensionsCount] = React.useState(0);
|
||||||
|
|
||||||
let style: React.CSSProperties | undefined = undefined;
|
let style: React.CSSProperties | undefined = undefined;
|
||||||
|
|
||||||
if (hostingElement?.current) {
|
if (hostingElement?.current) {
|
||||||
|
|
@ -83,14 +87,19 @@ export const Dialog: React.FC<React.PropsWithChildren<DialogProps>> = ({
|
||||||
return () => {};
|
return () => {};
|
||||||
}, [open, requestClose]);
|
}, [open, requestClose]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
const onResize = () => setRecalculateDimensionsCount(count => count + 1);
|
||||||
|
|
||||||
|
window.addEventListener('resize', onResize);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('resize', onResize);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
open && (
|
open && (
|
||||||
<dialog
|
<dialog ref={dialogRef} style={style} className={className} open>
|
||||||
ref={dialogRef}
|
|
||||||
style={style}
|
|
||||||
className={className}
|
|
||||||
open
|
|
||||||
>
|
|
||||||
{children}
|
{children}
|
||||||
</dialog>
|
</dialog>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue