Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modal autoFocus does not refocus on last focused element when Modal is closed #81

Closed
vabruzzo opened this issue Apr 28, 2016 · 0 comments

Comments

@vabruzzo
Copy link
Contributor

I opened an issue previously here: react-bootstrap/react-bootstrap#1851

In short, the element triggering the modal is not being refocused when the modal is closed. It appears that what is happening is that componentWillUpdate is called twice, and in turn, checkForFocus is called twice. So the modal is opened, checkForFocus is called, this.lastFocus is set to the triggering element (good), checkForFocus is called again, and this.lastFocus is set to the modal (assuming that autoFocus is set to true). I don't know why componentWillUpdate is being called twice, but I double checked that my own component is being rendered only once. This issue also affects the modals in the react-bootstrap doc., so I don't think my own code is causing the issue.

A simple fix appears to be to check that both nextProps.show is true (which is the current check) and that this.props.show is false within componentWillUpdate. This prevents the call to checkForFocus occurring when it doesn't need to.

I'll submit a pull request in a few, in the mean time I'm curious to know if I'm just way off track here :)

@taion taion closed this as completed in d2db8c3 Apr 28, 2016
taion added a commit that referenced this issue Apr 28, 2016
add additional check to Modal componentWillUpdate, fixes #81
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant