@internetarchive/ia-topnav 1.3.5-alpha2 → 1.3.5-alpha3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/ia-topnav",
3
- "version": "1.3.5-alpha2",
3
+ "version": "1.3.5-alpha3",
4
4
  "description": "Top nav for Internet Archive",
5
5
  "license": "AGPL-3.0-only",
6
6
  "main": "index.js",
package/src/nav-search.js CHANGED
@@ -100,6 +100,17 @@ class NavSearch extends TrackedElement {
100
100
  autocomplete="off"
101
101
  tabindex="2"
102
102
  @focus=${this.toggleSearchMenu}
103
+ @blur=${(e) => {
104
+ if (e.relatedTarget?.tagName !== 'SEARCH-MENU') {
105
+ this.dispatchEvent(new CustomEvent('menuToggled', {
106
+ detail: {
107
+ menuName: 'search'
108
+ },
109
+ composed: true,
110
+ bubbles: true,
111
+ }));
112
+ }
113
+ }}
103
114
  value=${this.searchQuery || ''}
104
115
  />
105
116
  ${this.searchInsideInput}
@@ -157,12 +157,7 @@ class PrimaryNav extends TrackedElement {
157
157
  return html`
158
158
  <a href="${formatUrl('/create', this.baseHost)}"
159
159
  class="upload"
160
- tabindex="1"
161
- @focus=${(e) => {
162
- if (e.relatedTarget !== null) {
163
- this.toggleSearchMenu(e)
164
- }
165
- }}>
160
+ tabindex="1">
166
161
  ${icons.upload}
167
162
  <span>Upload</span>
168
163
  </a>`;
@@ -30,10 +30,15 @@ class SearchMenu extends TrackedElement {
30
30
  }
31
31
 
32
32
  firstUpdated() {
33
- this.shadowRoot.addEventListener('keyup', (e) => {
33
+ this.shadowRoot.addEventListener('keydown', (e) => {
34
34
  const searchTypes = this.shadowRoot.querySelectorAll('.search-menu-inner label input[type=radio]');
35
35
  const length = searchTypes.length - 1;
36
36
 
37
+ // Prevent the default scrolling behavior for Home and End keys
38
+ if (e.key === 'Home' || e.key === 'End') {
39
+ e.preventDefault();
40
+ }
41
+
37
42
  // early return if searchTypes not found
38
43
  if (!length) return;
39
44
 
@@ -52,6 +57,11 @@ class SearchMenu extends TrackedElement {
52
57
  });
53
58
  }
54
59
 
60
+ disconnectedCallback() {
61
+ // Clean up event listener when the element is removed
62
+ this.shadowRoot.removeEventListener('keydown');
63
+ }
64
+
55
65
  selectSearchType(e) {
56
66
  this.selectedSearchType = e.target.value;
57
67
  }