Skip to content

Commit 1c5dbb9

Browse files
committed
fix(react): keep the inline math popup unclipped in table cells
1 parent b2175c6 commit 1c5dbb9

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

packages/core/src/editor/Block.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,8 @@ NESTED BLOCKS
579579
.bn-inline-content-section
580580
.bn-preview-with-source-popup[data-open="true"]
581581
.bn-source-block-popup {
582+
margin-top: 0;
583+
z-index: calc(var(--bn-ui-base-z-index, 0) + 15);
582584
width: 300px;
583585
}
584586

packages/react/src/blocks/SourceWithPreview/SourceWithPreview.tsx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { BlockNoteEditor } from "@blocknote/core";
2-
import { MouseEvent, ReactNode, useId, useRef } from "react";
2+
import {
3+
autoUpdate,
4+
flip,
5+
offset,
6+
shift,
7+
useFloating,
8+
} from "@floating-ui/react";
9+
import { MouseEvent, ReactNode, useCallback, useId, useRef } from "react";
310
import { MdKeyboardReturn } from "react-icons/md";
411

512
import { PreviewPlaceholder } from "./PreviewPlaceholder.js";
@@ -129,6 +136,20 @@ export const SourceWithPreview = (
129136
errorPreview
130137
);
131138

139+
const { refs, floatingStyles } = useFloating({
140+
placement: "bottom-start",
141+
strategy: "fixed",
142+
middleware: [offset(4), flip(), shift({ padding: 8 })],
143+
whileElementsMounted: autoUpdate,
144+
});
145+
146+
const isFloating = inline === true && popup.isOpen;
147+
148+
const setAnchor = useCallback(
149+
(node: HTMLElement | null) => refs.setPositionReference(node),
150+
[refs],
151+
);
152+
132153
// Links the source input to the render error so screen readers announce it
133154
// when the input is focused.
134155
const errorId = useId();
@@ -182,13 +203,18 @@ export const SourceWithPreview = (
182203
<PreviewContainer
183204
className="bn-preview-container"
184205
contentEditable={false}
206+
ref={setAnchor}
185207
// When no source code is available, the "Add source" button should have the appropriate role.
186208
role={previewIsButton ? "button" : undefined}
187209
onClick={handlePreviewClick}
188210
>
189211
{previewContent}
190212
</PreviewContainer>
191-
<div className="bn-source-block-popup">
213+
<div
214+
className="bn-source-block-popup"
215+
ref={isFloating ? refs.setFloating : undefined}
216+
style={isFloating ? floatingStyles : undefined}
217+
>
192218
<div className="bn-code-block-source-popup-body">
193219
<pre
194220
className={

0 commit comments

Comments
 (0)