Skip to content
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

Allow 0 tabindex to be focusable #3617

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/js/phoenix_live_view/aria.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let ARIA = {
(el instanceof HTMLAreaElement && el.href !== undefined) ||
(!el.disabled && (this.anyOf(el, [HTMLInputElement, HTMLSelectElement, HTMLTextAreaElement, HTMLButtonElement]))) ||
(el instanceof HTMLIFrameElement) ||
(el.tabIndex > 0 || (!interactiveOnly && el.getAttribute("tabindex") !== null && el.getAttribute("aria-hidden") !== "true"))
(el.tabIndex >= 0 || (!interactiveOnly && el.getAttribute("tabindex") !== null && el.getAttribute("aria-hidden") !== "true"))
)
},

Expand Down
20 changes: 20 additions & 0 deletions assets/test/js_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -900,4 +900,24 @@ describe("JS", () => {
expect(document.activeElement).toBe(modal1)
})
})

describe("exec_focus_first", () => {
test("focuses div with tabindex 0", () => {
let view = setupView(`
<div id="parent">
<div id="modal1" class="modal">modal 1</div>
<div id="modal2" tabindex="0" class="modal">modal 2</div>
<div id="modal3" tabindex="1" class="modal">modal 1</div>
<div id="push" phx-click='[["focus_first", {"to": "#parent"}]]'></div>
</div>
`)
let modal2 = document.querySelector("#modal2")
let push = document.querySelector("#push")

JS.exec(event, "click", push.getAttribute("phx-click"), view, push)

jest.runAllTimers()
expect(document.activeElement).toBe(modal2)
})
})
})