Skip to content

Commit faa4ad1

Browse files
authored
Allow 0 tabindex to be focusable (#3617)
MDN recommends that divs with tabindex of 0 should be focusable, and also recommends that tabindex should only ever be -1 or 0.
1 parent 3740e1e commit faa4ad1

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

assets/js/phoenix_live_view/aria.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let ARIA = {
77
(el instanceof HTMLAreaElement && el.href !== undefined) ||
88
(!el.disabled && (this.anyOf(el, [HTMLInputElement, HTMLSelectElement, HTMLTextAreaElement, HTMLButtonElement]))) ||
99
(el instanceof HTMLIFrameElement) ||
10-
(el.tabIndex > 0 || (!interactiveOnly && el.getAttribute("tabindex") !== null && el.getAttribute("aria-hidden") !== "true"))
10+
(el.tabIndex >= 0 || (!interactiveOnly && el.getAttribute("tabindex") !== null && el.getAttribute("aria-hidden") !== "true"))
1111
)
1212
},
1313

assets/test/js_test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,4 +1193,24 @@ describe("JS", () => {
11931193
expect(document.activeElement).toBe(modal1)
11941194
})
11951195
})
1196+
1197+
describe("exec_focus_first", () => {
1198+
test("focuses div with tabindex 0", () => {
1199+
let view = setupView(`
1200+
<div id="parent">
1201+
<div id="modal1" class="modal">modal 1</div>
1202+
<div id="modal2" tabindex="0" class="modal">modal 2</div>
1203+
<div id="modal3" tabindex="1" class="modal">modal 1</div>
1204+
<div id="push" phx-click='[["focus_first", {"to": "#parent"}]]'></div>
1205+
</div>
1206+
`)
1207+
let modal2 = document.querySelector("#modal2")
1208+
let push = document.querySelector("#push")
1209+
1210+
JS.exec(event, "click", push.getAttribute("phx-click"), view, push)
1211+
1212+
jest.runAllTimers()
1213+
expect(document.activeElement).toBe(modal2)
1214+
})
1215+
})
11961216
})

0 commit comments

Comments
 (0)