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

Link add target="_blank" #55

Closed
arthur-overlord opened this issue Sep 12, 2024 · 1 comment
Closed

Link add target="_blank" #55

arthur-overlord opened this issue Sep 12, 2024 · 1 comment

Comments

@arthur-overlord
Copy link

In case someone need to add target value to anchor. here is a simple solution to do it.

export const BtnLink = createButton(
  "Link",
  <svg
    xmlns="http://www.w3.org/2000/svg"
    fill="none"
    viewBox="0 0 24 24"
    strokeWidth="1.5"
    stroke="currentColor"
    className={btnSize}
  >
    <path
      strokeLinecap="round"
      strokeLinejoin="round"
      d="M13.19 8.688a4.5 4.5 0 0 1 1.242 7.244l-4.5 4.5a4.5 4.5 0 0 1-6.364-6.364l1.757-1.757m13.35-.622 1.757-1.757a4.5 4.5 0 0 0-6.364-6.364l-4.5 4.5a4.5 4.5 0 0 0 1.242 7.244"
    />
  </svg>,
  ({ $selection }) => {
    if ($selection?.nodeName === "A") {
      document.execCommand("unlink");
    } else {
      const Selection = document.getSelection()?.toString();
      // eslint-disable-next-line no-alert -- ignore
      const Uri = prompt("URL", "");
      document.execCommand(
        "insertHTML",
        false,
        Uri ? `<a href="${Uri}" target="_blank">${Selection ? Selection : Uri}</a>` : Selection,
      );
    }
  },
);
@megahertz
Copy link
Owner

megahertz commented Sep 12, 2024

Thanks, I just added a link to this sample to the README

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants