.focus() doesn't work
See original GitHub issueBug Report
What’s the current behavior?
firing .focus()
doesn’t revert to previous selection, or even focus the editor.
code sample: https://codesandbox.io/s/13r8qmv0l3 (see: line 113)
Made a simple change to slate example code, removing event.preventDefault()
from buttons (to lose focus) and then run .focus()
. Found while trying to set link hrefs from a custom dialog popup, with no success.
What’s the expected behavior?
Previous selection/highlight should be retained after firing .focus()
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:5 (4 by maintainers)
Top Results From Across the Web
javascript - Why doesn't focus() select my container div?
When you set the tabindex=-1 for an element it allows it to get focus() through javascript. If instead you want it to get...
Read more >.focus() not working on input - JavaScript - W3Schools Forum
Hi, I'm creating a search form that is appearing full screen when clicking on a "search" icon. The code I have for the...
Read more >Focus Not Working on your iPhone? 10 Ways to Fix the Issue
10 Ways to fix Focus not working issue · #1: Make sure you have not whitelisted the app · #2: Make sure you...
Read more >HTMLElement.focus() - Web APIs | MDN
The HTMLElement.focus() method sets focus on the specified element, if it can be focused. The focused element is the element that will ...
Read more >Focus mode not working on iOS 16? 8 Quick fixes
Turn off Focus sharing across devices · Check for whitelisted apps and contacts · Disable time-sensitive notifications · Turn off repeated Calls ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey, thanks for using Slate! Unfortunately, we can’t offer support for usage questions in the issues here because it becomes overwhelming to maintain the project if the issues are filled with questions.
However, we do have a Slack channel and people are constantly asking and answering questions in there. So I’m going to close this issue, but I definitely recommend joining the Slack channel if you want to find people that might be able to help.
Thanks for understanding!
@afrankel-sfdo @Slapbox
editor.focus()
, being an imperative command that does not directly affect the state, ends up being in conflict with the React lifecycle, which renders the Editor and its focus based on what’s in the state. in the code sample given originally, if you callthis.editor.focus()
outside of the React lifecycle (like if you wrap it in asetTimeout()
), you’ll find that it works as expected. but if you try to do so synchronously, React will go ahead and re-render over that, based on the state, which is unfocused