Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/core/src/extensions/SideMenu/SideMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,13 @@ export class SideMenuView<
clientX: number;
clientY: number;
}) => {
// Get all editor elements in the document
const editors = Array.from(this.pmView.root.querySelectorAll(".bn-editor"));
// Read-only editors cannot show a side menu or accept a dropped block, so
// they must not compete with editable editors that overlap them.
const editors = Array.from(
this.pmView.root.querySelectorAll(
'.bn-editor:not([contenteditable="false"])',
),
);

if (editors.length === 0) {
return null;
Expand Down
38 changes: 38 additions & 0 deletions tests/src/end-to-end/draghandle/overlappingEditors.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import "@blocknote/core/fonts/inter.css";
import { BlockNoteView } from "@blocknote/mantine";
import "@blocknote/mantine/style.css";
import { useCreateBlockNote } from "@blocknote/react";
import { describe, test } from "vite-plus/test";
import { render } from "vitest-browser-react";
import { DRAG_HANDLE_SELECTOR } from "../../utils/const.js";
import { waitForSelector } from "../../utils/editor.js";
import { moveMouseOverElement } from "../../utils/mouse.js";

function OverlappingEditors() {
const readOnlyEditor = useCreateBlockNote();
const editableEditor = useCreateBlockNote();

return (
<div style={{ display: "grid" }}>
<div style={{ gridArea: "1 / 1" }}>
<BlockNoteView editor={readOnlyEditor} editable={false} />
</div>
<div style={{ gridArea: "1 / 1", zIndex: 1 }}>
<BlockNoteView editor={editableEditor} />
</div>
</div>
);
}

describe("Overlapping editors", () => {
test("shows the side menu for an editable editor over a read-only editor", async () => {
await render(<OverlappingEditors />);

const editableBlock = await waitForSelector(
'.bn-editor[contenteditable="true"] [data-content-type="paragraph"]',
);
await moveMouseOverElement(editableBlock);

await waitForSelector(DRAG_HANDLE_SELECTOR);
});
});