Merge c1ad7ce9702ea7a60c8117856c2561ec9548076a into 12b3f76cc497ea59c471b9eeb89f9bbb58991dba

This commit is contained in:
Quaylyn Rimer 2025-10-31 13:18:47 +02:00 committed by GitHub
commit a2d439c4c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 3 deletions

View File

@ -95,7 +95,11 @@ class FocusTrap extends Config {
const elements = SelectorEngine.focusableChildren(trapElement)
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) {
elements[elements.length - 1].focus()
} else {

View File

@ -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 => {
fixtureEl.innerHTML = [
'<a href="#" id="outside">outside</a>',
@ -167,7 +167,7 @@ describe('FocusTrap', () => {
focustrap.activate()
const focusInListener = () => {
expect(spy).toHaveBeenCalled()
expect(spy).not.toHaveBeenCalled()
document.removeEventListener('focusin', focusInListener)
resolve()
}