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

Firefox: Focus gets lost in modal when active tab/window changes #18365

Closed
robsch opened this issue Nov 28, 2015 · 3 comments
Closed

Firefox: Focus gets lost in modal when active tab/window changes #18365

robsch opened this issue Nov 28, 2015 · 3 comments

Comments

@robsch
Copy link

@robsch robsch commented Nov 28, 2015

I've tested this with Chrome and Firefox. In Chrome all is fine, in Firefox I've got the problem:
You can test it right here: http://getbootstrap.com/javascript/#modals-related-target . If you open one of the modals, focus an input, enter some characters, switch to another Firefox tab or to another window and then come back to the tab with the open modal, the input is not focused anymore. The user has to click again into the input. In Chrome the input is still focused, in Firefox not.

Can you recommend a workaround for this?

@cvrebert
Copy link
Collaborator

@cvrebert cvrebert commented Nov 29, 2015

Filed Firefox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1228802
(I'd recommend adding yourself to the CC List of the bug.)

The <input> loses focus because, when switching back to the tab, Firefox, unlike all the other browsers and in apparent violation of the relevant spec, fires an initial focus event at window.document. Bootstrap's code interprets this as an attempt to move focus outside of the modal, so it refocuses the modal itself, thus interrupting the subsequent focus events which would normally fire at the window and then at the <input> to restore the normal focus, as happens in the other browsers.

In my limited testing, it does not appear to be possible to actually focus the document per se, so it seems like we could fix this by adding a special case in enforceFocus to ignore the focus event if its target is document.

@cvrebert cvrebert added the v4 label Nov 29, 2015
cvrebert added a commit that referenced this issue Nov 29, 2015
See http://bugzil.la/1228802

[skip sauce]
[skip validator]
cvrebert added a commit that referenced this issue Nov 29, 2015
Add Wall of Browser Bugs entry for #18365

See http://bugzil.la/1228802

[skip sauce]
[skip validator]
@robsch
Copy link
Author

@robsch robsch commented Nov 29, 2015

Thank you for your efforts! If anyone is interested or can provide a workaround you may want to also take a look at http://stackoverflow.com/q/33970707/57091 .

cvrebert added a commit that referenced this issue Dec 23, 2015
cvrebert added a commit that referenced this issue Dec 23, 2015
@cvrebert cvrebert changed the title Firefox: Focus gets lost in modal when window changes Firefox: Focus gets lost in modal when active tab/window changes Dec 23, 2015
@cvrebert
Copy link
Collaborator

@cvrebert cvrebert commented Feb 11, 2016

Added relevant web-platform-test: web-platform-tests/wpt#2571

chiraggmodi pushed a commit to chiraggmodi/bootstrap that referenced this issue Apr 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants