plate icon indicating copy to clipboard operation
plate copied to clipboard

When inserting a link after another link, you can't submit the input when the input are filled with previous values

Open brian-bourdon opened this issue 1 year ago • 1 comments

Description

When inserting a link and then clicking on the link toolbar button to insert a second link, the floating link toolbar open with previous value link filled. When pressing enter to insert the link nothing is happening. A secondary problem coming from this one is that e.preventDefault() will not be called and if the editor is inside a form it will submit the form instead of the link input.

Steps

Here are the steps to reproduce on the playground.

  • Clear the playground
  • insert a link, it will work first.
  • click on the link toolbar button
  • press enter to insert another link => if nothing happens, you reproduced

Maybe it's more clear with a video: screen-capture.webm

Expectation

My expectation would be that on pressing enter to submit the (second) link, the link should be created. Or maybe if the behavior wanted is to prevent user to submit link input if input are not dirty, calling preventDefault before the condition would prevent an above form to be submitted.

For more information (from what i understand):

My guess is that the "problem" is here: https://github.com/udecode/plate/blob/edd8560fb26e25baced14c94ff3f5f4219fe24b1/packages/link/src/components/FloatingLink/useFloatingLinkEdit.ts#L94C51-L94C51 floatingLinkSelectors.mode() === 'edit probably return false if the user has not type into the input, causing the triggerFloatingLinkEdit(editor) and the e.preventDefault() to not be called.

If we reproduce the steps exactly but instead of submitting directly the second link we just add and remove a character. Then we can see the link is inserted.

Funding

  • You can sponsor this specific effort via a Polar.sh pledge below
  • We receive the pledge once the issue is completed & verified
Fund with Polar

brian-bourdon avatar Jul 18 '23 20:07 brian-bourdon

I encountered the same issue, and my investigation is there is something wrong with <FloatingLinkUrlInput />, as the value of url within floatingLinkStore is '' on appending a link second time(which is correct) but the link input opens with last value, which should be empty ''.

joshua7v avatar Oct 19 '23 04:10 joshua7v