add processFocus to makeAjaxTask

This adds an additional check to makeAjaxLoadTask that focuses on the first element with the HTML standard "autofocus" attribute set.

I've put it right next to the makeAjaxLoadTask function for clarity, but it should probably be organized into a different place, next to other corresponding functions.
This commit is contained in:
Ben Pate 2020-08-13 20:50:02 -06:00
parent 7d83527bfb
commit 018ba7c2c2

View File

@ -411,10 +411,18 @@ return (function () {
return function () {
processNode(child, true);
processScripts(child);
processFocus(child)
triggerEvent(child, 'htmx:load', {});
};
}
function processFocus(child) {
var el = child.querySelector("[autofocus]")
if (el != null) {
el.focus()
}
}
function insertNodesBefore(parentNode, insertBefore, fragment, settleInfo) {
handleAttributes(parentNode, fragment, settleInfo);
while(fragment.childNodes.length > 0){