Conditionally return focus
See original GitHub issueI’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:
- Created 2 years ago
- Comments:10 (4 by maintainers)
Top 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 >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
@far-fetched unfortunately
return false
inside ofsetReturnFocus
leads to the error: “setReturnFocus
did not return a node” and thepreviousActiveElement
isundefined
when trying to use this withfocus-trap-react
.Any ideas? I also posted on focus-trap-react.
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.