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

Intercept hyperlinks on click #514

Open
ThatCanadianGuy opened this issue May 4, 2023 · 1 comment
Open

Intercept hyperlinks on click #514

ThatCanadianGuy opened this issue May 4, 2023 · 1 comment

Comments

@ThatCanadianGuy
Copy link

Similar to issue #445 in which the question was to open in a new tab, I'd like to intercept the link click entirely. Our app redirects to a native control for the anchors. Is there any exposed function or way to basically preventDefault and get an event to trigger when a hyperlink is clicked so the listener can propagate it in a different way?

@jaywcjlove
Copy link
Member

@ThatCanadianGuy

import React from "react";
import ReactDOM from "react-dom";
import MDEditor from "@uiw/react-md-editor";

const mkdStr = `
[uiwjs/react-md-editor/issues/445](https://github.com/uiwjs/react-md-editor/issues/445)
`;

function App() {
  const [value, setValue] = React.useState(mkdStr);
  return (
    <div className="container">
      <h3>uiwjs/react-md-editor/issues/445</h3>
      <MDEditor
        previewOptions={{
          rehypeRewrite: (node) => {
            if (node.type === "element" && node.tagName === "a") {
              console.log(node);
              node.properties = {
                ...node.properties,
+                href:"javascript:void(0)"
              };
            }
          }
        }}
        height={200}
        value={value}
        onChange={setValue}
      />
    </div>
  );
}

ReactDOM.render(<App />, document.getElementById("container"));

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