-
-
Notifications
You must be signed in to change notification settings - Fork 78.9k
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
Hopefully fixes trigger focus restoration on modal close #13627
Conversation
* register the callback before invoking the toggling * listen for `hidden` instead of `hide` * account for the possibility of the associated `show` event being preventDefault-ed Adds relevant unit tests.
$target.one('hide.bs.modal', function () { | ||
$this.is(':visible') && $this.trigger('focus') | ||
$target.one('show.bs.modal', function (showEvent) { | ||
if (showEvent.isDefaultPrevented()) return // only register focus restorer if modal will actually get shown |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't hidden never get called if shown was prevented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean show
or shown
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problematic scenario is:
- I click a button to trigger a modal
- The
show.bs.modal
event gets prevented by some code, so the modal doesn't get shown. - I click a different button that triggers the same modal.
- The modal gets successfully shown.
Now when I close the modal, we want the latter button to get refocused (and it'd be best not to have the focus jump around multiple times unnecessarily). Hence, this if
statement.
unit tests are great, thanks chris 😍 |
@fat So, do the explanations I posted make sense? |
yep, lgtm - thanks! |
Hopefully fixes trigger focus restoration on modal close
Thanks for reviewing this. |
Fixes #12364? I admit this is not my forte, but this explanation for the cause of the bug seems to make sense, and the new unit tests pass, so...
hidden
instead ofhide
show
event being preventDefault-edAdds relevant unit tests.
To: @fat for review