question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The text area goes out of focus after a single character is typed

See original GitHub issue

Whenever I type a single character, the text area goes out of focus or is deselected rather, and I have to click in the text area once again to type yet another character and the cycle continues.

This is my state of the class component where my editor resides in.

state = {
    imageUrl: "",
    title: "",
    excerpt: "",
    body: "",
    submitMessage: "",
    submitMessageTextColor: "",
  };

This is my handler function:

onBodyChange = (value) => {
    this.setState({
      body: value,
    });
  };

This is my MDE component call:

<SimpleMDE onChange={this.onBodyChange} options={{hideIcons: ["preview", "side-by-side", "fullscreen"], }} />

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
RIP21commented, Sep 11, 2021

As per README.md

Note that you need to useMemo to memoize options so they do not change on each rerender! It will affect behavior and performance because then on each render of the parent that renders SimpleMdeReact you’ll get a new instance of the editor, which you definitely want to avoid! Also, if you change options on each value change you will lose focus. So, put options as a const outside of the component, or if options shall be partially or fully set by props make sure to useMemo in case of functional/hooks components, or class field for class based components. Slightly more on that here: #164

0reactions
RIP21commented, Sep 12, 2021

I’m so sorry, but I am new to React as a technology, could you please guide me further by helping me with what you mean when you say "into a class field"?

It’s not React, but JS. Read online what’s class field declaration in JS is.

Use react hooks API instead. React class components are deprecated much and nobody writes them anymore.

Read more comments on GitHub >

github_iconTop Results From Across the Web

In React ES6, why does the input field lose focus after typing a ...
Show activity on this post. In my component below, the input field loses focus after typing a character. While using Chrome's Inspector, it...
Read more >
React Text Input Losing Focus After Each Keypress
Then click back into the text input. Then type 'o'. Click back into the text input. Then type the final 'o'.
Read more >
Focusing: focus/blur - The Modern JavaScript Tutorial
The focus event is called on focusing, and blur – when the element loses the focus. Let's use them for validation of an...
Read more >
How to Use Text Areas (The Java™ Tutorials > Creating a GUI ...
Here is a picture of an example called TextDemo that enables you to type text using a text field (at the top) and...
Read more >
TextArea focus out when typing - SAP Community
... of the TextAreas, after I type one character (maybe a couple if I am fast), the TextArea loses focus and the view...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found