astro-accelerator 4.0.13 → 4.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/public/js/search.js +28 -24
package/package.json
CHANGED
package/public/js/search.js
CHANGED
|
@@ -113,30 +113,7 @@ siteSearchInput.addEventListener('click', () => {
|
|
|
113
113
|
removeSearchButton.addEventListener('click', () => clearInput());
|
|
114
114
|
|
|
115
115
|
// Dropdown accessibility controls
|
|
116
|
-
document.addEventListener('keydown',
|
|
117
|
-
if (e.key === 'Escape' && siteSearchWrapper.classList.contains('is-active')) {
|
|
118
|
-
closeDropdown();
|
|
119
|
-
deactivateInput();
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Only proceed if search is active
|
|
123
|
-
if (!siteSearchWrapper.classList.contains('is-active')) return;
|
|
124
|
-
|
|
125
|
-
const firstElement = siteSearchInput;
|
|
126
|
-
const lastElement = siteSearchResults.querySelector('button');
|
|
127
|
-
|
|
128
|
-
if (e.key === 'Tab') {
|
|
129
|
-
if (e.shiftKey && document.activeElement === firstElement) {
|
|
130
|
-
// If shift+tab is pressed on the first focusable element, move to the last
|
|
131
|
-
e.preventDefault();
|
|
132
|
-
if (lastElement) lastElement.focus();
|
|
133
|
-
} else if (!e.shiftKey && document.activeElement === lastElement) {
|
|
134
|
-
// If tab is pressed on the last focusable element, move to the first
|
|
135
|
-
e.preventDefault();
|
|
136
|
-
firstElement.focus();
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
});
|
|
116
|
+
document.addEventListener('keydown', handleDropdownKeyboardNavigation);
|
|
140
117
|
|
|
141
118
|
function activateInput() {
|
|
142
119
|
siteSearchWrapper.classList.add('is-active');
|
|
@@ -183,6 +160,33 @@ function clearInput() {
|
|
|
183
160
|
siteSearchInput.focus();
|
|
184
161
|
}
|
|
185
162
|
|
|
163
|
+
function handleDropdownKeyboardNavigation(e) {
|
|
164
|
+
// Proceed only if search dropdown is active
|
|
165
|
+
if (!siteSearchWrapper.classList.contains('is-active')) return;
|
|
166
|
+
|
|
167
|
+
if (e.key === 'Escape') {
|
|
168
|
+
closeDropdown();
|
|
169
|
+
deactivateInput();
|
|
170
|
+
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (e.key === 'Tab') {
|
|
175
|
+
const firstElement = siteSearchInput;
|
|
176
|
+
const lastElement = siteSearchResults.querySelector('button') || siteSearchResults.querySelector('.site-search-results__item:last-child .result-wrapper');
|
|
177
|
+
|
|
178
|
+
if (e.shiftKey && document.activeElement === firstElement) {
|
|
179
|
+
// Shift + Tab: Move focus to the last element if the first element is currently focused
|
|
180
|
+
e.preventDefault();
|
|
181
|
+
if (lastElement) lastElement.focus();
|
|
182
|
+
} else if (!e.shiftKey && document.activeElement === lastElement) {
|
|
183
|
+
// Tab: Move focus to the first element if the last element is currently focused
|
|
184
|
+
e.preventDefault();
|
|
185
|
+
firstElement.focus();
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
186
190
|
/** @type{Synonyms | null} */
|
|
187
191
|
var _synonyms = null;
|
|
188
192
|
|