Skip to content

Commit f1a9740

Browse files
committed
fix(ui): anchor container chrome to the container, not a descendant
`BlockPopover` searched for any `[data-node-type]` under the node view's DOM, which matches a nested child container's root when the author's own root isn't stamped - anchoring the popover to a child. The search is now scoped to the block's own type, and falls back to the container's node element rather than descending into its contentDOM (the first child's box). `SideMenu` read `container.firstElementChild!` for the handle's x position, which is null for a container rendering no element children.
1 parent e479c17 commit f1a9740

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ export class SideMenuView<
304304
// non-nested and we only take the x coordinate, it's ok.
305305
(
306306
getDirectChildBlocks(container, containerUIInfo)[0] ??
307-
container.firstElementChild!
307+
container.firstElementChild ??
308+
container
308309
).getBoundingClientRect().x
309310
: (
310311
this.pmView.dom.firstChild as HTMLElement

‎packages/react/src/components/Popovers/BlockPopover.tsx‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,17 @@ export const BlockPopover = (
4242
// stamps with `data-node-type`; vanilla containers render that boxed
4343
// element directly as the node view's DOM.
4444
if (dom instanceof Element) {
45-
const boxed = dom.matches("[data-node-type]")
45+
// Scoped to this block's own type: an unscoped descendant search
46+
// would match a nested child container's root when the author's
47+
// root hasn't been stamped, anchoring the popover to a child.
48+
const selector = `[data-node-type="${nodePosInfo.node.type.name}"]`;
49+
const boxed = dom.matches(selector)
4650
? dom
47-
: dom.querySelector("[data-node-type]");
48-
if (boxed) {
49-
return { element: boxed };
50-
}
51+
: dom.querySelector(selector);
52+
// No stamped root to anchor to, so fall back to the container's
53+
// own node element rather than descending into its contentDOM,
54+
// which is the first child's box.
55+
return { element: boxed ?? dom };
5156
}
5257
}
5358

0 commit comments

Comments
 (0)