UMB-CS-682-Team-03 / tracker

0 stars 0 forks source link

Set focus to first input in search fragment #67

Closed rouilj closed 3 months ago

rouilj commented 4 months ago

The following patch sets the focus to the first element of the searchFragment (if present). The user can tab to move the focus to the first item, but in this case setting focus is probably better. Since the searchFragment is at the top of the page, we don't have issues with scrolling the form into view and losing context.

diff --git a/html/classhelper.js b/html/classhelper.js
index 3ff630ef..44d98c17 100644
--- a/html/classhelper.js
+++ b/html/classhelper.js
@@ -565,6 +567,7 @@ class ClassHelper extends HTMLElement {
             label.setAttribute("for", param);
             label.textContent = ClassHelper.translations[param] + ":";

+            let focusSet = false
             let input;
             if (this.dropdownsData[param]) {
                 input = document.createElement("select");
@@ -601,6 +604,10 @@ class ClassHelper extends HTMLElement {
             input.setAttribute("name", param);
             input.setAttribute("id", param);
             input.classList.add("search-input"); // Add class for styling   
+       if (!focusSet) {
+         input.setAttribute("autofocus", "");
+         focusSet = true;
+       }

             labelCell.appendChild(label);
             inputCell.appendChild(input);