ux improve
This commit is contained in:
@@ -14,5 +14,28 @@
|
||||
</nav>
|
||||
{% block content %}{% endblock %}
|
||||
</main>
|
||||
<script>
|
||||
document.addEventListener("keydown", function (event) {
|
||||
if (event.key !== "Enter") return;
|
||||
if (event.target.tagName === "TEXTAREA") return;
|
||||
if (event.target.type === "submit") return;
|
||||
if (!event.target.closest("form")) return;
|
||||
|
||||
const focusable = Array.from(
|
||||
event.target.form.querySelectorAll(
|
||||
'input:not([type="hidden"]):not([type="submit"]):not([type="checkbox"]), textarea, select'
|
||||
)
|
||||
).filter((element) => !element.disabled);
|
||||
|
||||
const index = focusable.indexOf(event.target);
|
||||
if (index === -1 || index === focusable.length - 1) return;
|
||||
|
||||
event.preventDefault();
|
||||
focusable[index + 1].focus();
|
||||
if (focusable[index + 1].select) {
|
||||
focusable[index + 1].select();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user