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.

.focus() doesn't work

See original GitHub issue

Bug Report

What’s the current behavior?

ezgif-1-b8c62dfb7f-1

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

github_iconTop GitHub Comments

17reactions
ianstormtaylorcommented, Aug 8, 2018

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!

5reactions
davidchangcommented, May 3, 2018

@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 call this.editor.focus() outside of the React lifecycle (like if you wrap it in a setTimeout()), 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

Read more comments on GitHub >

github_iconTop 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 >

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