Skip to content

Commit e2d8ffd

Browse files
committed
Added same changes to GridSuggestionMenuController
1 parent b4e0773 commit e2d8ffd

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

packages/react/src/components/SuggestionMenu/GridSuggestionMenu/GridSuggestionMenuController.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BlockSchema, InlineContentSchema, StyleSchema } from "@blocknote/core";
22
import { SuggestionMenu } from "@blocknote/core/extensions";
3-
import { flip, offset, shift, size } from "@floating-ui/react";
3+
import { autoPlacement, offset, shift, size } from "@floating-ui/react";
44
import { FC, useEffect, useMemo } from "react";
55

66
import { useBlockNoteEditor } from "../../../hooks/useBlockNoteEditor.js";
@@ -126,17 +126,22 @@ export function GridSuggestionMenuController<
126126
offset(10),
127127
// Flips the menu placement to maximize the space available, and prevents
128128
// the menu from being cut off by the confines of the screen.
129-
flip({
130-
mainAxis: true,
131-
crossAxis: false,
129+
autoPlacement({
130+
allowedPlacements: ["bottom-start", "top-start"],
131+
padding: 10,
132132
}),
133133
shift(),
134134
size({
135-
apply({ availableHeight, elements }) {
136-
Object.assign(elements.floating.style, {
137-
maxHeight: `${availableHeight - 10}px`,
138-
});
135+
apply(p) {
136+
// Because the height of the suggestion menu is dynamic and based
137+
// on the number of items, the `autoPlacement` middleware gets
138+
// confused when the height is set on the initial render.
139+
// Therefore, it's set right after instead.
140+
setTimeout(() => {
141+
p.elements.floating.style.maxHeight = `${p.availableHeight}px`;
142+
}, 10);
139143
},
144+
padding: 10,
140145
}),
141146
],
142147
},

packages/react/src/components/SuggestionMenu/SuggestionMenuController.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ export function SuggestionMenuController<
135135
size({
136136
apply(p) {
137137
// Because the height of the suggestion menu is dynamic and based
138-
// on the number of items, the `flip` middleware gets confused
139-
// when the height is set on the initial render. Therefore, it's
140-
// set right after instead.
138+
// on the number of items, the `autoPlacement` middleware gets
139+
// confused when the height is set on the initial render.
140+
// Therefore, it's set right after instead.
141141
setTimeout(() => {
142142
p.elements.floating.style.maxHeight = `${p.availableHeight}px`;
143143
}, 10);

0 commit comments

Comments
 (0)