0

I want all my editor links to open in a new tab with target={blank}

From documentation I did not find a way to do it!

Ι have add the LinkEditor implementation, but I don't understand from documentation-api where to add setTarget attribute to LinkNode

gikall
  • 559
  • 5
  • 16

1 Answers1

0

Finally I found it, and it is what I want! I leave it here for anyone else with the same worry.

I replaced editor.dispatchCommand(TOGGLE_LINK_COMMAND, linkUrl) with editor.dispatchCommand(TOGGLE_LINK_COMMAND, { url: linkUrl, target: '_blank' }) at the point which I set the link to editor!

gikall
  • 559
  • 5
  • 16
  • Where did you go about setting this? I thought by reading the documentation, we would be able to achieve this by providing the optional `attributes` to one of the matchers for the `AutoLinkPlugin`. I tried following the [docs](https://lexical.dev/docs/react/plugins#lexicalautolinkplugin) here. – Tyler Klose Jul 24 '23 at 19:23
  • `AutoLinkPlugin` is something else, as docs mentioned: Plugin will convert text into links based on passed matchers list. In example below whenever user types url-like string it will automaticaly convert it into a link node. What we want is the link to have by default `target: '_blank'` – gikall Jul 26 '23 at 12:19
  • So I created an `LinkEditor` component and `onKeyDown` I have add this func `const onKeyboard = (event: any) => { if (event.key === 'Enter') { event.preventDefault(); if (lastSelection !== null) { if (linkUrl !== '') { editor.dispatchCommand(TOGGLE_LINK_COMMAND, { url: linkUrl, target: '_blank' }); } setEditMode(false); } } else if (event.key === 'Escape') { event.preventDefault(); setEditMode(false); } };` – gikall Jul 26 '23 at 12:25