Skip to content
Merged
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
3 changes: 2 additions & 1 deletion packages/react/src/components/Popovers/GenericPopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type GenericPopoverReference =
cacheMountedBoundingClientRect?: boolean;
}
| {
element: undefined;
// When no reference element is provided, this can be provided as an
// alternative "virtual" element to position the popover around.
getBoundingClientRect: () => DOMRect;
Expand Down Expand Up @@ -62,7 +63,7 @@ export function getMountedBoundingClientRectCache(

return () => {
if (
"element" in reference &&
reference.element &&
(reference.cacheMountedBoundingClientRect ?? true)
) {
if (reference.element.isConnected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import {
useExtensionState,
} from "../../../hooks/useExtension.js";
import { FloatingUIOptions } from "../../Popovers/FloatingUIOptions.js";
import { GenericPopover } from "../../Popovers/GenericPopover.js";
import {
GenericPopover,
GenericPopoverReference,
} from "../../Popovers/GenericPopover.js";
import { getDefaultReactEmojiPickerItems } from "./getDefaultReactEmojiPickerItems.js";
import { GridSuggestionMenu } from "./GridSuggestionMenu.js";
import { GridSuggestionMenuWrapper } from "./GridSuggestionMenuWrapper.js";
Expand Down Expand Up @@ -95,13 +98,16 @@ export function GridSuggestionMenuController<

const state = useExtensionState(SuggestionMenu);
const reference = useExtensionState(SuggestionMenu, {
selector: (state) => ({
// Use first child as the editor DOM element may itself be scrollable.
// For FloatingUI to auto-update the position during scrolling, the
// `contextElement` must be a descendant of the scroll container.
element: editor.domElement?.firstChild || undefined,
getBoundingClientRect: () => state?.referencePos || new DOMRect(),
}),
selector: (state) =>
({
// Use first child as the editor DOM element may itself be scrollable.
// For FloatingUI to auto-update the position during scrolling, the
// `contextElement` must be a descendant of the scroll container.
element: (editor.domElement?.firstChild || undefined) as
| Element
| undefined,
getBoundingClientRect: () => state?.referencePos || new DOMRect(),
}) satisfies GenericPopoverReference,
});

const floatingUIOptions = useMemo<FloatingUIOptions>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { FC, useEffect, useMemo } from "react";
import { useBlockNoteEditor } from "../../hooks/useBlockNoteEditor.js";
import { useExtension, useExtensionState } from "../../hooks/useExtension.js";
import { FloatingUIOptions } from "../Popovers/FloatingUIOptions.js";
import { GenericPopover } from "../Popovers/GenericPopover.js";
import {
GenericPopover,
GenericPopoverReference,
} from "../Popovers/GenericPopover.js";
import { SuggestionMenu } from "./SuggestionMenu.js";
import { SuggestionMenuWrapper } from "./SuggestionMenuWrapper.js";
import { getDefaultReactSlashMenuItems } from "./getDefaultReactSlashMenuItems.js";
Expand Down Expand Up @@ -90,13 +93,16 @@ export function SuggestionMenuController<

const state = useExtensionState(SuggestionMenuExtension);
const reference = useExtensionState(SuggestionMenuExtension, {
selector: (state) => ({
// Use first child as the editor DOM element may itself be scrollable.
// For FloatingUI to auto-update the position during scrolling, the
// `contextElement` must be a descendant of the scroll container.
element: editor.domElement?.firstChild || undefined,
getBoundingClientRect: () => state?.referencePos || new DOMRect(),
}),
selector: (state) =>
({
// Use first child as the editor DOM element may itself be scrollable.
// For FloatingUI to auto-update the position during scrolling, the
// `contextElement` must be a descendant of the scroll container.
element: (editor.domElement?.firstChild || undefined) as
| Element
| undefined,
getBoundingClientRect: () => state?.referencePos || new DOMRect(),
}) satisfies GenericPopoverReference,
});

const floatingUIOptions = useMemo<FloatingUIOptions>(
Expand Down
Loading