Skip to content

Commit

Permalink
Use Popper to prevent overlay from rendering out of view
Browse files Browse the repository at this point in the history
  • Loading branch information
richardolsson committed Jan 17, 2025
1 parent 3213701 commit 541dc71
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/zui/ZUIEditor/elements/TextAndHrefOverlay.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { OpenInNew } from '@mui/icons-material';
import { Box, Button, IconButton, Paper, TextField } from '@mui/material';
import { FC } from 'react';
import {
Box,
Button,
IconButton,
Paper,
Popper,
TextField,
} from '@mui/material';
import { FC, useState } from 'react';

import formatUrl from 'utils/formatUrl';
import messageIds from 'zui/l10n/messageIds';
Expand Down Expand Up @@ -31,6 +38,7 @@ const TextAndHrefOverlay: FC<Props> = ({
x,
y,
}) => {
const [anchorEl, setAnchorEl] = useState<HTMLElement>();
const messages = useMessages(messageIds);

const formattedHref = formatUrl(href);
Expand All @@ -39,14 +47,14 @@ const TextAndHrefOverlay: FC<Props> = ({
return (
<Box position="relative">
<Box
ref={(el: HTMLElement) => setAnchorEl(el)}
sx={{
left: x,
minWidth: 300,
position: 'absolute',
top: y,
}}
>
{open && (
<Popper anchorEl={anchorEl} open={open}>
<Paper elevation={1}>
<Box
alignItems="stretch"
Expand Down Expand Up @@ -118,7 +126,7 @@ const TextAndHrefOverlay: FC<Props> = ({
</Box>
</Box>
</Paper>
)}
</Popper>
</Box>
</Box>
);
Expand Down

0 comments on commit 541dc71

Please sign in to comment.