Draft-js: [HELP] How do I retain focus on the selected content after a style is applied?

Created on 7 Apr 2016  Â·  5Comments  Â·  Source: facebook/draft-js

I'm trying out the basic implementation of DraftJS with Rich styles. When I select a word and apply a style to it (like bold/italics), it applies it. But it loses the selected text (the word is not selected anymore). If I click on the editor region, it selects it again.

I don't see a similar workflow when I try the examples. So I'm pretty sure I'm missing something, but I don't know what. Is there something I should do to retain the selected content?

question

Most helpful comment

I suggest using preventDefault on the mousedown event.

All 5 comments

Are you applying a style with a mouse click that's changing focus
after? You could try prevent default in the click handler where you apply
the style.

On Thursday, April 7, 2016, Swaathi Kakarla [email protected]
wrote:

I'm trying out the basic implementation of DraftJS with Rich styles. When
I select a word and apply a style to it (like bold/italics), it applies it.
But it loses the selected text (the word is not selected anymore). If I
click on the editor region, it selects it again.

I don't see a similar workflow when I try the examples. So I'm pretty sure
I'm missing something, but I don't know what. Is there something I should
do to retain the selected content?

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
https://github.com/facebook/draft-js/issues/275

Nope. I'm using a onMouseDown on a span element to apply the style.

I suggest using preventDefault on the mousedown event.

Thanks so much! This cleared it up right away. :+1: :smile:

The preventdefault fix doesn't work anymore in 0.11

Was this page helpful?
0 / 5 - 0 ratings