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

Is it possible to have access to ref for textArea? #534

Closed
ianfelix opened this issue Jun 1, 2023 · 5 comments
Closed

Is it possible to have access to ref for textArea? #534

ianfelix opened this issue Jun 1, 2023 · 5 comments

Comments

@ianfelix
Copy link

ianfelix commented Jun 1, 2023

I would like to have the control of the textArea input

@jaywcjlove
Copy link
Member

@ianfelix https://codesandbox.io/embed/markdown-editor-for-react-https-github-com-uiwjs-react-md-editor-issues-534-nmu6u9?fontsize=14&hidenavigation=1&theme=dark

import React, { useEffect, useState } from "react";
import ReactDOM from "react-dom";
import MDEditor from "@uiw/react-md-editor";

const mkdStr = `# Markdown Editor`;

function App() {
  const [textarea, setTextarea] = useState();
  const [value, setValue] = React.useState(mkdStr);
  useEffect(() => {
    console.log("$edit:12", textarea);
  }, [textarea]);
  function refCallback(node) {
    if (node && node.textarea) {
      setTextarea(node.textarea);
    }
  }
  return (
    <div className="container">
      <h3>Auto</h3>
      <MDEditor
        ref={refCallback}
        height={200}
        value={value}
        onChange={setValue}
      />
    </div>
  );
}

@ianfelix
Copy link
Author

ianfelix commented Jun 1, 2023

It seems that on typescript project doesn't recognize the ref prop

image

jaywcjlove added a commit that referenced this issue Jun 1, 2023
@jaywcjlove
Copy link
Member

@ianfelix Upgrade v3.23.3

github-actions bot added a commit that referenced this issue Jun 1, 2023
@jaywcjlove
Copy link
Member

@ianfelix https://codesandbox.io/embed/misty-waterfall-485be5?fontsize=14&hidenavigation=1&theme=dark

import React, { useEffect, useState } from "react";
import MDEditor, { RefMDEditor } from "@uiw/react-md-editor";

export default function App() {
  const [textarea, setTextarea] = useState<HTMLTextAreaElement>();
  const [value, setValue] = React.useState("# Markdown Editor");
  useEffect(() => {
    console.log("$edit:12", textarea);
  }, [textarea]);
  function refCallback(node: RefMDEditor) {
    if (node && node.textarea) {
      setTextarea(node.textarea);
    }
  }
  return (
    <div className="container">
      <h3>Auto</h3>
      <MDEditor
        ref={refCallback}
        height={200}
        value={value}
        onChange={(val) => {
          setValue(val || "");
        }}
      />
    </div>
  );
}

@ianfelix
Copy link
Author

ianfelix commented Jun 1, 2023

wow, thank you!! you are doing an amazing work here

@ianfelix ianfelix closed this as completed Jun 1, 2023
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