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.

Input field within a SortableElement loses focus on typing

See original GitHub issue

I have a sorted list of divs. Within these divs, there are a few input fields. The value of these fields are maintained in the state - so every key press triggers a re-render. Everything works as expected, except for the fact that the input loses focus after each key press. See below:

example

I feel like I’m close to understanding this - but just can’t figure out how to make it work. I’ve read through the issues, and it feels similar to #49. I know you have the shouldCancelStart and distance parameters (with shouldCancelStart defaulting to true for inputs, textareas, etc). But, it doesn’t seem that disabling the drag is the problem (and indeed, perhaps the fact that I have a dragHandle makes these irrelevant).

I also thought that if I make sure everything in the SortableElement has a key, it would re-render and see that it was unchanged, but focus is still lost. Any ideas?

Thanks so much for your work on this project.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:21 (1 by maintainers)

github_iconTop GitHub Comments

68reactions
gouxlordcommented, Jan 27, 2017

Ok, i found why this happened in my case.

I was creating the SortableItem and SortableList inside my render method (before return) to make quick lib testing. In this case, classes was created at each render and in this case React reconciliation process discard and replace dom.

So i just needed to use same SortableItem and SortableList classes at each render to avoid this.

13reactions
davekisscommented, Jan 26, 2017

@gouxlord you saved my life

Read more comments on GitHub >

github_iconTop Results From Across the Web

reactjs - in react-sortable-hoc Input wrapped loses focus when ...
i am using react-sortable-hoc in Model view, But my component below, the input field loses focus after typing a character.
Read more >
React Text Input Losing Focus After Each Keypress
Click back into the text input. Then type the final 'o'. Obviously that is messed up. The problem was, I was defining a...
Read more >
clauderic/react-sortable-hoc - Gitter
I know that React Sortable HOC supports keyboard sorting out of the box,does anybody tried a custom ... Input field in SortableElement loses...
Read more >
In React , why does the input field lose focus after typing a ...
Coding example for the question In React , why does the input field lose focus after typing a character?-Reactjs.
Read more >
React.js loses input focus on typing
React.js was loosing focus on an input while the user was typing. ... it throws away the old input and adds a new...
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