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.

When 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:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

16reactions
chrisrobbinscommented, Mar 26, 2021

I am still seeing this happen as well. Is there a way to programmatically clear the selection?

1reaction
flarniecommented, Jul 20, 2017

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Clear Selection - Oracle Help Center
Use this system function to clear all system-function-defined selection information that was used to build previous SQL statements during the current ...
Read more >
CLEAR-SELECTION( ) method - Progress Software
CLEAR -SELECTION( ) method. Removes the highlight from the currently selected text. Return type: LOGICAL. Applies to: BROWSE widget (column), ...
Read more >
Clear selection Icons – Download for Free in PNG and SVG
Free Clear selection icons in various UI design styles for web, mobile. Download static and animated Clear selection vector icons for free in...
Read more >
Clear Selection – Blender Knowledgebase - KatsBits.com
Tag: Clear Selection. Using Select All/None/Invert in Blender · (De)select All. Posted on 28th November 2018 22nd September 2021 by KatsBits.
Read more >
Selection.clear does not unselect selection - Stack Overflow
Alright, .Clear is meant to clear the contents (& formatting) inside a cell/range, but not unselect. therefore, when you use Selection.
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