mirror of
https://github.com/twbs/bootstrap.git
synced 2025-11-11 00:05:17 -05:00
Merge c1ad7ce9702ea7a60c8117856c2561ec9548076a into 12b3f76cc497ea59c471b9eeb89f9bbb58991dba
This commit is contained in:
commit
a2d439c4c1
@ -95,7 +95,11 @@ class FocusTrap extends Config {
|
|||||||
const elements = SelectorEngine.focusableChildren(trapElement)
|
const elements = SelectorEngine.focusableChildren(trapElement)
|
||||||
|
|
||||||
if (elements.length === 0) {
|
if (elements.length === 0) {
|
||||||
trapElement.focus()
|
// Don't focus the trapElement if it has a negative tabindex
|
||||||
|
// as this creates an unwanted focus stop for keyboard users
|
||||||
|
if (trapElement.tabIndex >= 0) {
|
||||||
|
trapElement.focus()
|
||||||
|
}
|
||||||
} else if (this._lastTabNavDirection === TAB_NAV_BACKWARD) {
|
} else if (this._lastTabNavDirection === TAB_NAV_BACKWARD) {
|
||||||
elements[elements.length - 1].focus()
|
elements[elements.length - 1].focus()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -155,7 +155,7 @@ describe('FocusTrap', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should force focus on itself if there is no focusable content', () => {
|
it('should not force focus on element with negative tabindex if there is no focusable content', () => {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
fixtureEl.innerHTML = [
|
fixtureEl.innerHTML = [
|
||||||
'<a href="#" id="outside">outside</a>',
|
'<a href="#" id="outside">outside</a>',
|
||||||
@ -167,7 +167,7 @@ describe('FocusTrap', () => {
|
|||||||
focustrap.activate()
|
focustrap.activate()
|
||||||
|
|
||||||
const focusInListener = () => {
|
const focusInListener = () => {
|
||||||
expect(spy).toHaveBeenCalled()
|
expect(spy).not.toHaveBeenCalled()
|
||||||
document.removeEventListener('focusin', focusInListener)
|
document.removeEventListener('focusin', focusInListener)
|
||||||
resolve()
|
resolve()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user