Clear selection?
See original GitHub issueWhen you have a selection of text, then click away blurring the component, then click back focusing the component again, the same selection remains. A second click must then be performed to clear the selection and place the cursor under the mouse.
This is bazaar and not the way textareas normally behave.
Normally when you blur a textarea, the selection is lost, and when you focus a textarea, the cursor is placed at the point in which you clicked.
I am trying recreate the normal textarea behavior and nothing I try seems to do the trick.
Since this only happens if there is a current selection. And it behaves correctly if there is no selection. My thought is to clear the selection on blur.
I have tried various combinations of using moveSelectionToEnd
, and forceSelection
and acceptSelection
with SelectionState.createEmpty
but nothing I try actually clears the selection. The previous selection is always there when I focus the component.
What is the appropriate way to clear the selection on blur and place the cursor at the correct spot on focus, the way a generic textarea behaves?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:13 (7 by maintainers)
Top GitHub Comments
I am still seeing this happen as well. Is there a way to programmatically clear the selection?
The fix is under a Feature Flag here on master: https://github.com/facebook/draft-js/blob/master/src/component/handlers/edit/editOnFocus.js#L37-L39 The comment there explains things.
We have been testing this internally, and need to decide if this is stable enough to make the default behavior.
I’ll add it to the agenda for this week’s Draft.js discussion. Thanks for checking in!