Skip to content

Commit 0a433ca

Browse files
committed
menu positioning fixes
1 parent e1f82ea commit 0a433ca

File tree

5 files changed

+17
-19
lines changed

5 files changed

+17
-19
lines changed

examples/09-ai/03-custom-ai-menu-items/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@blocknote/example-ai-ai-menu-items",
2+
"name": "@blocknote/example-ai-custom-ai-menu-items",
33
"description": "AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY",
44
"private": true,
55
"version": "0.12.4",

packages/react/src/hooks/useUIElementPositioning.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type UIElementPosition = {
2222
getFloatingProps: ReturnType<typeof useInteractions>["getFloatingProps"];
2323
getReferenceProps: ReturnType<typeof useInteractions>["getReferenceProps"];
2424
setReference: ReturnType<typeof useFloating>["refs"]["setReference"];
25+
isPositioned: boolean;
2526
};
2627

2728
export function useUIElementPositioning(
@@ -32,7 +33,7 @@ export function useUIElementPositioning(
3233
UseFloatingOptions & { canDismiss: boolean | UseDismissProps }
3334
>,
3435
): UIElementPosition {
35-
const { refs, update, context, floatingStyles } = useFloating({
36+
const { refs, update, context, floatingStyles, isPositioned } = useFloating({
3637
open: show,
3738
...options,
3839
});
@@ -84,8 +85,10 @@ export function useUIElementPositioning(
8485
},
8586
getFloatingProps,
8687
getReferenceProps,
88+
isPositioned,
8789
};
8890
}, [
91+
isPositioned,
8992
floatingStyles,
9093
isMounted,
9194
refs.setFloating,

packages/xl-ai/src/components/AIMenu/AIMenuController.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ export const AIMenuController = (props: { aiMenu?: FC<AIMenuProps> }) => {
1818

1919
return (
2020
<BlockPositioner
21+
canDismissViaOutsidePress={
22+
aiMenuState === "closed" || aiMenuState.status === "user-input"
23+
}
2124
blockID={blockId}
2225
onOpenChange={(open) => {
2326
if (open || aiMenuState === "closed") {

packages/xl-ai/src/components/AIMenu/BlockPositioner.tsx

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const BlockPositioner = (props: {
1010
event: Event,
1111
reason: OpenChangeReason,
1212
) => void;
13+
canDismissViaOutsidePress?: boolean;
1314
}) => {
1415
const element = props.blockID
1516
? document.querySelector(`[data-id="${props.blockID}"]`)
@@ -21,28 +22,20 @@ export const BlockPositioner = (props: {
2122
return element
2223
? {
2324
getBoundingClientRect: () => {
24-
// console.log(
25-
// "getBoundingClientRect",
26-
// element.getBoundingClientRect()
27-
// );
2825
return element.getBoundingClientRect();
2926
},
3027
contextElement: element,
3128
}
3229
: null;
3330
}, [element]);
3431

35-
const { isMounted, ref, style, getFloatingProps } = useUIElementPositioning(
36-
element ? true : false,
37-
reference,
38-
3000,
39-
{
32+
const { isMounted, ref, style, getFloatingProps, isPositioned } =
33+
useUIElementPositioning(element ? true : false, reference, 3000, {
4034
canDismiss: {
4135
enabled: true,
4236
escapeKey: true,
43-
outsidePress: false,
37+
outsidePress: props.canDismissViaOutsidePress,
4438
},
45-
// canDismiss: false,
4639
placement: "bottom",
4740
middleware: [
4841
offset(10),
@@ -62,8 +55,7 @@ export const BlockPositioner = (props: {
6255
});
6356
return cleanup;
6457
},
65-
},
66-
);
58+
});
6759

6860
if (!isMounted) {
6961
return null;
@@ -77,7 +69,7 @@ export const BlockPositioner = (props: {
7769
}}
7870
{...getFloatingProps()}
7971
>
80-
{props.children}
72+
{isPositioned && props.children}
8173
</div>
8274
);
8375
};

playground/src/examples.gen.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,9 +1442,9 @@
14421442
}
14431443
},
14441444
{
1445-
"projectSlug": "ai-menu-items",
1446-
"fullSlug": "ai/ai-menu-items",
1447-
"pathFromRoot": "examples/09-ai/03-ai-menu-items",
1445+
"projectSlug": "custom-ai-menu-items",
1446+
"fullSlug": "ai/custom-ai-menu-items",
1447+
"pathFromRoot": "examples/09-ai/03-custom-ai-menu-items",
14481448
"config": {
14491449
"playground": true,
14501450
"docs": true,

0 commit comments

Comments
 (0)