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.

Conditionally return focus

See original GitHub issue

I’m looking to conditionally return focus to the previously focused element. For example, I want to check if the intended element is actually focusable (i.e. it may have disappeared by this point). Have checked out checkCanReturnFocus but can’t seem to get this to work (docs are a bit vague for this option).

Can anyone help out here?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Slapboxcommented, Jun 8, 2022

@far-fetched unfortunately return false inside of setReturnFocus leads to the error: “setReturnFocus did not return a node” and the previousActiveElement is undefined when trying to use this with focus-trap-react.

Any ideas? I also posted on focus-trap-react.

2reactions
Slapboxcommented, Jun 8, 2022

Ah I think you’re right @far-fetched! Thanks for the reply. There’s so much in the line on setReturnFocus that I didn’t realize that one of the types it can accept is a function.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React set focus on input[type="number"] with conditional render
I have a problem with conditional rendering inputs which might have focus after rendering in table , where input placed in td ....
Read more >
Setting focus on conditionally rendered input
Now I'd like to set it focused when input is rendered. But it seems like rendering of templates takes few milli seconds if...
Read more >
React Tips — State vs Props, Focus Inputs, and Conditional ...
In this article, we'll look at some tips for writing better React apps. Set Focus on an Input Field After Rendering. We can...
Read more >
Initializing focus state in React: you might be doing it wrong
In terms of conditional rendering, you can hide or show elements, but not mount or unmount them from the DOM. And crucially, you...
Read more >
Set focus to an element conditionally - JSF - CodeRanch
I would however like the h:inputtext element to gain focus only if the value is out of bounds. The focus attribute does not...
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