From 018ba7c2c2f4d99425dc2362e68e4cc6fc2803c5 Mon Sep 17 00:00:00 2001 From: Ben Pate Date: Thu, 13 Aug 2020 20:50:02 -0600 Subject: [PATCH] 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. --- src/htmx.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/htmx.js b/src/htmx.js index 7a5478b5..143e7939 100644 --- a/src/htmx.js +++ b/src/htmx.js @@ -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){