Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combobox closing issue #4031

Open
mknight9090 opened this issue Jan 24, 2025 · 2 comments
Open

Combobox closing issue #4031

mknight9090 opened this issue Jan 24, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@mknight9090
Copy link

Description

After update from Plate 40.2.2 to the latest version, I have problems with comboboxes (slash command or mention). It's possible to reproduce the problem in the official Plate playground.

The combobox does not close when clicking another paragraph - it moves with the selection. The Esc key makes it jump to point [0, 0].

Recording.2025-01-24.101359.mp4

Reproduction URL

https://platejs.org/

Reproduction steps

1. Open '/' command in new paragraph
2. Click on another paragraph (or press Esc)

Plate version

latest

Slate React version

latest

Screenshots

Logs

Browsers

No response

@mknight9090 mknight9090 added the bug Something isn't working label Jan 24, 2025
@dima-mamaev
Copy link

Upgraded to v43, faced same issue. Pretty annoying.

@TheHogginator
Copy link

Upgraded to v43, faced same issue. Pretty annoying.

Yeah super annoying, I just ran into this as well. I had copied the InlineCombobox element code from https://platejs.org/docs/components/inline-combobox it's doing something funky with setting a ref into state meaning it's not the correct value when the onCancelInput function tries to read it. Here's what I changed to get it working. God speed brother.

diff --git a/components/plate-ui/inline-combobox.tsx b/components/plate-ui/inline-combobox.tsx
index 52c1ab1..b6c721d 100644
--- a/components/plate-ui/inline-combobox.tsx
+++ b/components/plate-ui/inline-combobox.tsx
@@ -11,10 +11,11 @@ import React, {
   useContext,
   useEffect,
   useMemo,
+  useRef,
   useState,
 } from 'react';
 
-import type { PointRef, TElement } from '@udecode/plate';
+import type { Point, PointRef, TElement } from '@udecode/plate';
 
 import {
   type ComboboxItemProps,
@@ -115,7 +116,7 @@ const InlineCombobox = ({
    * Track the point just before the input element so we know where to
    * insertText if the combobox closes due to a selection change.
    */
-  const [insertPoint, setInsertPoint] = useState<PointRef | null>(null);
+  const insertPoint = useRef<Point | null>(null);
 
   useEffect(() => {
     const path = editor.api.findPath(element);
@@ -127,7 +128,7 @@ const InlineCombobox = ({
     if (!point) return;
 
     const pointRef = editor.api.pointRef(point);
-    setInsertPoint(pointRef);
+    insertPoint.current = pointRef.current;
 
     return () => {
       pointRef.unref();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants