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

Support for inline mention context autocomplete menu #365

Closed
raDiesle opened this issue Apr 4, 2022 · 2 comments
Closed

Support for inline mention context autocomplete menu #365

raDiesle opened this issue Apr 4, 2022 · 2 comments

Comments

@raDiesle
Copy link

raDiesle commented Apr 4, 2022

I couldnt find any information if it is supported or can be extended to have a context menu / mention with available options, whenever you type e.g. ":" or "@" like github supports it. - Is it? And if yes, how to do it?

@raDiesle raDiesle changed the title Support for inline context autocomplete menu Support for inline mention context autocomplete menu Apr 4, 2022
@jaywcjlove
Copy link
Member

@raDiesle Example: https://codesandbox.io/embed/react-md-editor-issues-365-8hm4rd?fontsize=14&hidenavigation=1&theme=dark

import React, { useRef, useEffect } from "react";
import ReactDOM from "react-dom";
import MDEditor from "@uiw/react-md-editor";
import "tributejs/tribute.css"
import Tribute from "tributejs";

const mkdStr = `**Hello world!!!** `;

var tribute = new Tribute({
  trigger: '@',
  values: [
    { key: "Phil Heartman", value: "pheartman" },
    { key: "Gordon Ramsey", value: "gramsey" }
  ]
});

function App() {
  const [value, setValue] = React.useState(mkdStr);
  const ref = useRef()
  const isBundle = useRef(false)
  useEffect(() => {
    if (ref.current.textarea && !isBundle.current) {
      isBundle.current = true;
      tribute.attach(ref.current.textarea);
      ref.current.textarea.addEventListener("tribute-replaced", (e) => {
        setValue(e.target.value)
      });
    }
  }, [ref.current])
  return (
    <div className="container">
      <div data-color-mode="light">
        <h3>Light</h3>
        <MDEditor
          ref={ref}
          height={200} value={value} onChange={(value) => setValue(value)}
        />
      </div>
    </div>
  );
}

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

@raDiesle
Copy link
Author

raDiesle commented Apr 4, 2022

Thank you, I will give it a try for my needs, so its going replaced with an image

@raDiesle raDiesle closed this as completed Apr 4, 2022
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