Skip to content

Commit 555fae6

Browse files
fix: Block side menu flipping to right side (#225)
* Temp changes * Updated test screenshots * Made side menu positioning forced left * Fixed side menu positioning on horizontal scroll * Fixed type issue
1 parent e1b43b7 commit 555fae6

30 files changed

+27
-2
lines changed

packages/core/src/editor.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
.bnEditor {
44
outline: none;
5-
padding-inline: 50px;
5+
padding-inline: 54px;
66
border-radius: 8px;
77

88
/* Define a set of colors to be used throughout the app for consistency

packages/core/src/extensions/DraggableBlocks/DraggableBlocksPlugin.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ export class BlockMenuView<BSchema extends BlockSchema> {
320320
};
321321

322322
/**
323-
* If the event is outside of the editor contents,
323+
* If the event is outside the editor contents,
324324
* we dispatch a fake event, so that we can still drop the content
325325
* when dragging / dropping to the side of the editor
326326
*/
@@ -430,6 +430,14 @@ export class BlockMenuView<BSchema extends BlockSchema> {
430430
};
431431

432432
onScroll = () => {
433+
// Editor itself may have padding or other styling which affects size/position, so we get the boundingRect of
434+
// the first child (i.e. the blockGroup that wraps all blocks in the editor) for a more accurate bounding box.
435+
const editorBoundingBox = (
436+
this.ttEditor.view.dom.firstChild! as HTMLElement
437+
).getBoundingClientRect();
438+
439+
this.horizontalPosAnchor = editorBoundingBox.x;
440+
433441
if (this.menuOpen) {
434442
this.blockMenu.render(this.getDynamicParams(), false);
435443
}

packages/react/src/BlockSideMenu/BlockSideMenuFactory.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,22 @@ export const createReactBlockSideMenuFactory = <BSchema extends BlockSchema>(
2828
animation: "fade",
2929
offset: [0, 0],
3030
placement: "left",
31+
popperOptions: {
32+
modifiers: [
33+
{
34+
name: "flip",
35+
options: {
36+
fallbackPlacements: [],
37+
},
38+
},
39+
{
40+
name: "preventOverflow",
41+
options: {
42+
mainAxis: false,
43+
altAxis: false,
44+
},
45+
},
46+
],
47+
},
3148
});
3249
};
-263 Bytes
Loading
-432 Bytes
Loading
-479 Bytes
Loading
-388 Bytes
Loading
-1.31 KB
Loading
-1.09 KB
Loading
-233 Bytes
Loading

0 commit comments

Comments
 (0)