RIP21 / react-simplemde-editor

React wrapper for simplemde (easymde) markdown editor
https://react-simplemde-edtior.netlify.com/
MIT License
766 stars 103 forks source link

When status or toolbar hidden editor loses focus after every keystroke #165

Closed chris-ck closed 3 years ago

chris-ck commented 3 years ago

When hiding the toolbar or status bar via options, the editor loses focus after every keystroke. This happens only in controlled mode. It can be "fixed" with autofocus: true in options, however, then after editing a character that is not at the end of text makes the cursor (caret) jump to the end of the text. Reproducible with a minimal setup (easymde 2.15.0 and rect-simplemde-editor 5.0.1):

import "./styles.css";
import "easymde/dist/easymde.min.css";
import { SimpleMdeReact } from "react-simplemde-editor";
import { useState } from "react";

export default function App() {
  const [value, setValue] = useState("");
  const onChange = (value) => setValue(value);

  return (
    <div className="App">
      <SimpleMdeReact value={value} onChange={onChange} options={{status:false, toolbar: false}}/>
    </div>
  );
}
RIP21 commented 3 years ago

@chris-ck memoize your options and it will work just fine. Read the docs section here: https://github.com/RIP21/react-simplemde-editor#options