mirror of
https://github.com/colanode/colanode.git
synced 2025-12-16 03:37:51 +01:00
Fix onClick and floating mounting for mention menu (#206)
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
shift,
|
||||
autoUpdate,
|
||||
FloatingPortal,
|
||||
VirtualElement,
|
||||
} from '@floating-ui/react';
|
||||
import type { Range } from '@tiptap/core';
|
||||
import { Editor, Node } from '@tiptap/core';
|
||||
@@ -60,19 +61,26 @@ const CommandList = ({
|
||||
}) => {
|
||||
const [selectedIndex, setSelectedIndex] = useState(0);
|
||||
|
||||
const { refs, floatingStyles } = useFloating({
|
||||
const { refs, floatingStyles, update } = useFloating({
|
||||
placement: 'bottom-start',
|
||||
middleware: [offset(6), flip(), shift()],
|
||||
whileElementsMounted: autoUpdate,
|
||||
strategy: 'fixed',
|
||||
elements: {
|
||||
reference: {
|
||||
getBoundingClientRect: () => props.clientRect?.() || new DOMRect(),
|
||||
contextElement: document.body,
|
||||
} as unknown as Element,
|
||||
},
|
||||
});
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const rect = props.clientRect?.();
|
||||
if (!rect) return;
|
||||
|
||||
const virtualEl = {
|
||||
getBoundingClientRect: () => rect,
|
||||
contextElement: props.editor.view.dom as Element,
|
||||
};
|
||||
|
||||
refs.setPositionReference(virtualEl as VirtualElement);
|
||||
update();
|
||||
}, [props.clientRect, props.editor.view.dom, refs, update]);
|
||||
|
||||
const selectItem = useCallback(
|
||||
(index: number) => {
|
||||
const item = items[index];
|
||||
@@ -145,6 +153,12 @@ const CommandList = ({
|
||||
}`}
|
||||
key={item.id}
|
||||
onClick={() => selectItem(index)}
|
||||
onPointerDownCapture={(e) => {
|
||||
// Added this event handler because the onClick handler was not working
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
selectItem(index);
|
||||
}}
|
||||
>
|
||||
<div className="flex size-10 min-w-10 items-center justify-center rounded-md border bg-background">
|
||||
<Avatar
|
||||
|
||||
Reference in New Issue
Block a user