10 lines
455 B
JavaScript
10 lines
455 B
JavaScript
|
|
// Keyboard and screen-reader focus after HTMX swaps a thread in place.
|
||
|
|
// The server marks the element to land on (a new or edited comment, or the thread itself)
|
||
|
|
// with data-autofocus; without this, focus would fall back to the top of the page.
|
||
|
|
document.addEventListener("htmx:afterSettle", function () {
|
||
|
|
var target = document.querySelector("[data-autofocus]");
|
||
|
|
if (!target) return;
|
||
|
|
target.removeAttribute("data-autofocus");
|
||
|
|
target.focus();
|
||
|
|
});
|