focus-trap-react | A React component that traps focus | Frontend Framework library
kandi X-RAY | focus-trap-react Summary
kandi X-RAY | focus-trap-react Summary
A React component that traps focus
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Triggered when focus is on the focus element .
focus-trap-react Key Features
focus-trap-react Examples and Code Snippets
Community Discussions
Trending Discussions on focus-trap-react
QUESTION
My code below works but the this.buttonRef.current.firstChild.focus()
stops working if it's not in a setTimeout function.
From looking at the official docs for refs I cant see why this is happening. Is there anything obviously wrong with my component? If not Im wondering if another component on my site is 'stealing' focus as when the url
prop changes a modal is closed.
UPDATE: One weird thing is if I console.log
outside of the setTimeout then I can see the element is present in the DOM.
UPDATE2: Turns out it was React Trap Focus in my modal that was causing the issue. Removing the focus trap means I don't need the timeout. As I need the focus trap I think the setTimeout will need to stay.
...ANSWER
Answered 2019-Mar-14 at 09:31Considering that seemingly componentDidUpdate runs before your buttonRef is resolved, a short setTimeout isn't the worst solution.
You could try other ways involving setting state:
QUESTION
I have react 16.3.2, and today i attempted to upgrade it through yarn upgrade react@latest
it has upgraded the yarn.lock
's react@^16.8.2 but when I console.log
out the react version it still outputs 16.3.2
Did I miss something?
Here's my package.json
ANSWER
Answered 2019-Feb-14 at 22:18yarn upgrade
does not update package.json
, only the lock file. Actually, none of the yarn upgrade
flags do. There's a long discussion about this in here
You can do the following:
- Reinstall React with
yarn add react@latest
- Install a npm package to check updates, for example, npm-check-updates. Run it to update
package.json
and then tryyarn install
. - Or you can install that specific React version
yarn upgrade react@16.8.2
.
This is the intended behaviour, even though it is very confusing in the docs.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install focus-trap-react
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page