udecode / plate

A rich-text editor powered by AI
https://platejs.org
Other
12.08k stars 737 forks source link

Insert floating link toolbar persists state and not reacting on enter #2791

Closed Feshchenko closed 1 month ago

Feshchenko commented 11 months ago

Description

After creating the first link, the insert floating UI state persists.

Steps to Reproduce

  1. go to platejs.org
  2. create a new paragraph or use existing one
  3. click Create Link button
  4. fill insert floating link with valid content: https://google.com and text google
  5. add some other text like
  6. click Create Link button again
  7. insert form is filled with https://google.com and google and you can't submit it again until adding changes

https://github.com/udecode/plate/assets/7198398/93d9e5c3-5154-44c1-828b-07e3a21278fe

Sandbox

Expected Behavior

Environment

Bounty

Click here to add a bounty via Algora.

Funding

Fund with Polar

Saland1214 commented 9 months ago

I met this problem too. I turn input component to a function. and watch insertState.open changed, when it changed, I'll reset loading, it will rerender input. It's work for me.

  const [loading, setLoading] = useState(false);

  useEffect(() => {
    if (!insertState.isOpen) {
      setLoading(true);
    } else {
      setLoading(false);
    }
  }, [insertState]);

  const input = () =>
    loading ? (
      ''
    ) : (
      <div className="flex w-[330px] flex-col">
        <div className="flex items-center">
          <div className="flex items-center pl-3 text-slate-500 dark:text-slate-400">
            <Icons.link className="h-4 w-4" />
          </div>
          <FloatingLinkUrlInput
            className={inputVariants({ variant: 'ghost', h: 'sm' })}
            placeholder="Paste link"
          />
        </div>

        <Separator />

        <div className="flex items-center">
          <div className="flex items-center pl-3 text-slate-500 dark:text-slate-400">
            <Icons.text className="h-4 w-4" />
          </div>
          <input
            className={inputVariants({ variant: 'ghost', h: 'sm' })}
            placeholder="Text to display, please press Enter to save"
            {...textInputProps}
          />
        </div>
      </div>
    );