-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -268,10 +268,13 @@ | |
|
||
if ($this.is('a')) e.preventDefault() | ||
|
||
Plugin.call($target, option, this) | ||
$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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problematic scenario is:
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 |
||
$target.one('hidden.bs.modal', function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hidden change def makes sense 👍 |
||
$this.is(':visible') && $this.trigger('focus') | ||
}) | ||
}) | ||
Plugin.call($target, option, this) | ||
}) | ||
|
||
}(jQuery); |
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.
dont quite understand why this is inside the
show
… maybe im missing something obvious though :)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.
Doing the setup after the
Plugin.call
is too late and leaves the tests failing. FWICT, the modal can get shown and dismissed before the code gets a chance to setup thehidden
event handler. So we've gotta do it before making the call.But we need to avoid setting up the handler if the showing of the modal gets cancelled, so we have to wait for
show
orshown
.IIRC,
shown
led to test failures, which leaves us withshow
as the event to wait for.