Skip to content

Commit 4d2fe51

Browse files
fix: Side menu scrolling (#1394)
1 parent 844de93 commit 4d2fe51

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

packages/core/src/extensions/SideMenu/SideMenuPlugin.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ export class SideMenuView<
187187
this.onKeyDown as EventListener,
188188
true
189189
);
190+
191+
// Setting capture=true ensures that any parent container of the editor that
192+
// gets scrolled will trigger the scroll event. Scroll events do not bubble
193+
// and so won't propagate to the document by default.
194+
pmView.root.addEventListener("scroll", this.onScroll, true);
190195
}
191196

192197
updateState = (state: SideMenuState<BSchema, I, S>) => {
@@ -473,6 +478,13 @@ export class SideMenuView<
473478
return evt;
474479
}
475480

481+
onScroll = () => {
482+
if (this.state?.show) {
483+
this.state.referencePos = this.hoveredBlock!.getBoundingClientRect();
484+
this.emitUpdate(this.state);
485+
}
486+
};
487+
476488
// Needed in cases where the editor state updates without the mouse cursor
477489
// moving, as some state updates can require a side menu update. For example,
478490
// adding a button to the side menu which removes the block can cause the
@@ -515,6 +527,7 @@ export class SideMenuView<
515527
this.onKeyDown as EventListener,
516528
true
517529
);
530+
this.pmView.root.removeEventListener("scroll", this.onScroll, true);
518531
}
519532
}
520533

0 commit comments

Comments
 (0)