Skip to content

Commit 1fe2877

Browse files
author
Kunwartejpal Sidhu
committed
fix(modal): Fix JS closure bug in focus restoration timeout
- Fixes issue where was null when the 50ms timeout fired, preventing focus restoration. - Removed invalid copy-pasted code from that could crash the handler before restoring focus.
1 parent 6d467b9 commit 1fe2877

1 file changed

Lines changed: 2 additions & 37 deletions

File tree

web-app/js/main.js

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,42 +1259,6 @@ document.addEventListener("DOMContentLoaded", function () {
12591259
removeTrap = null;
12601260
}
12611261

1262-
recentSearchesList.innerHTML = '';
1263-
recentSearches.slice(0, 5).forEach((search) => {
1264-
const item = document.createElement('div');
1265-
item.className = 'dropdown-recent-item';
1266-
item.innerHTML = `
1267-
<button type="button" class="dropdown-recent-text" aria-label="Search ${search}">
1268-
<i class="fas fa-history" style="opacity: 0.5; font-size: 0.9rem;"></i>
1269-
<span style="flex: 1; color: var(--text-secondary);">${search}</span>
1270-
</button>
1271-
<button type="button" class="dropdown-recent-remove" aria-label="Remove search">
1272-
<i class="fas fa-x"></i>
1273-
</button>
1274-
`;
1275-
1276-
const textButton = item.querySelector('.dropdown-recent-text');
1277-
const removeBtn = item.querySelector('.dropdown-recent-remove');
1278-
1279-
if (textButton) {
1280-
textButton.addEventListener('click', () => {
1281-
searchInput.value = search;
1282-
currentSearchQuery = search;
1283-
performSearch();
1284-
closeDropdown();
1285-
});
1286-
}
1287-
1288-
if (removeBtn) {
1289-
removeBtn.addEventListener('click', (e) => {
1290-
e.stopPropagation();
1291-
recentSearches = recentSearches.filter(s => s !== search);
1292-
localStorage.setItem('recentSearches', JSON.stringify(recentSearches));
1293-
renderRecentSearches();
1294-
});
1295-
}
1296-
});
1297-
12981262
// Clear content
12991263
if (modalBody) {
13001264
modalBody.innerHTML = "";
@@ -1304,8 +1268,9 @@ document.addEventListener("DOMContentLoaded", function () {
13041268
}
13051269

13061270
if (lastFocusedElement && typeof lastFocusedElement.focus === "function") {
1271+
var elemToFocus = lastFocusedElement;
13071272
setTimeout(function () {
1308-
lastFocusedElement.focus({ preventScroll: true });
1273+
elemToFocus.focus({ preventScroll: true });
13091274
}, 50);
13101275
}
13111276
lastFocusedElement = null;

0 commit comments

Comments
 (0)