@internetarchive/ia-topnav 1.3.5-alpha8 → 1.3.5-alpha9

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-alpha8",
3
+ "version": "1.3.5-alpha9",
4
4
  "description": "Top nav for Internet Archive",
5
5
  "license": "AGPL-3.0-only",
6
6
  "main": "index.js",
package/src/ia-topnav.js CHANGED
@@ -83,7 +83,7 @@ export default class IATopNav extends LitElement {
83
83
 
84
84
  updated(props) {
85
85
  if (props.has('username') || props.has('localLinks') || props.has('baseHost') ||
86
- props.has('waybackPagesArchived') || props.has('itemIdentifier')) {
86
+ props.has('waybackPagesArchived') || props.has('itemIdentifier')) {
87
87
  this.menuSetup();
88
88
  }
89
89
  }
@@ -201,6 +201,7 @@ export default class IATopNav extends LitElement {
201
201
  tabindex="${this.userMenuTabIndex}"
202
202
  @menuToggled=${this.menuToggled}
203
203
  @trackClick=${this.trackClick}
204
+ @moveFocusToOthers=${(e) => this.currentTab = e.detail}
204
205
  ></user-menu>
205
206
  `;
206
207
  }
@@ -1,3 +1,6 @@
1
+
2
+
3
+
1
4
  export default class KeyboardNavigation {
2
5
  /**
3
6
  * Constructor for the KeyboardNavigation class.
@@ -60,6 +63,7 @@ export default class KeyboardNavigation {
60
63
 
61
64
  if (isArrowKey) {
62
65
  this.handleArrowKey(key);
66
+ event.preventDefault();
63
67
  } else if (isTabKey) {
64
68
  this.handleTabKey(event);
65
69
  }
@@ -97,11 +101,13 @@ export default class KeyboardNavigation {
97
101
  * @param {KeyboardEvent} event - The keyboard event object.
98
102
  */
99
103
  handleTabKey(event) {
100
- if (this.menuOption !== 'usermenu') {
104
+ console.log(this.menuOption)
105
+ if (this.menuOption) {
101
106
  const isShiftPressed = event.shiftKey;
102
107
  this.focusNextMenuItem(isShiftPressed);
103
108
  }
104
109
 
110
+ this.focusableElements[this.focusedIndex]?.blur();
105
111
  event.preventDefault();
106
112
  }
107
113
 
@@ -67,9 +67,9 @@ class LoginButton extends TrackedElement {
67
67
  ${icons.user}
68
68
  </a>
69
69
  <span>
70
- <a href="${this.signupPath}" tabindex="1">Sign up</a>
70
+ <a href="${this.signupPath}">Sign up</a>
71
71
  |
72
- <a href="${this.loginPath}" tabindex="1">Log in</a>
72
+ <a href="${this.loginPath}">Log in</a>
73
73
  </span>
74
74
  </div>
75
75
  `;
@@ -18,7 +18,6 @@ class MediaButton extends TrackedElement {
18
18
  mediatype: { type: String },
19
19
  openMenu: { type: String },
20
20
  selected: { type: Boolean },
21
- selectedMenuOption: { type: String },
22
21
  followable: { type: Boolean },
23
22
  };
24
23
  }
@@ -36,16 +35,9 @@ class MediaButton extends TrackedElement {
36
35
  this.mediatype = '';
37
36
  this.openMenu = '';
38
37
  this.selected = false;
39
- this.selectedMenuOption = '';
40
38
  this.followable = false;
41
39
  }
42
40
 
43
- updated() {
44
- console.log(this.selectedMenuOption)
45
- // if (this.selectedMenuOption)
46
- // this.shadowDom.querySelector(`a.${this.mediatype}`).focus();
47
- }
48
-
49
41
  onClick(e) {
50
42
  this.trackClick(e);
51
43
  e.preventDefault();
@@ -103,23 +95,12 @@ class MediaButton extends TrackedElement {
103
95
  `;
104
96
  }
105
97
 
106
- emitHandleSubMenuKeyDown(e) {
107
- this.dispatchEvent(new CustomEvent('subMenuKeyDown1', {
108
- bubbles: true,
109
- composed: true,
110
- detail: {
111
- e
112
- }
113
- }));
114
- }
115
-
116
98
  render() {
117
99
  return html`
118
100
  <a
119
101
  href="${this.href}"
120
102
  class="menu-item ${this.mediatype} ${this.buttonClass}"
121
103
  @click=${this.followable ? this.trackClick : this.onClick}
122
- @keydown="${this.emitHandleSubMenuKeyDown}"
123
104
  data-event-click-tracking="${this.analyticsEvent}"
124
105
  title="${this.tooltipPrefix} ${this.mediatype} menu"
125
106
  tabindex="${this.openMenu === 'media' ? '' : '0'}"
package/src/media-menu.js CHANGED
@@ -67,10 +67,6 @@ class MediaMenu extends LitElement {
67
67
  config: { type: Object },
68
68
  openMenu: { type: String },
69
69
  selectedMenuOption: { type: String },
70
-
71
- isSubMenuOpen: { type: Boolean },
72
- focusedIndex: { type: Number },
73
-
74
70
  currentTab: { type: Object },
75
71
  };
76
72
  }
@@ -80,95 +76,27 @@ class MediaMenu extends LitElement {
80
76
  this.config = {};
81
77
  this.openMenu = '';
82
78
  this.selectedMenuOption = '';
83
-
84
- this.isSubMenuOpen = false;
85
- this.focusedIndex = -1;
86
- this.menuRef = [];
87
- this.subMenuRef = [];
88
-
89
79
  this.currentTab = {};
90
- this.focusOn = 0;
91
- }
92
-
93
- firstUpdated() {
94
- this.menuRef = Array.from(this.shadowRoot.querySelectorAll('media-button'));
95
- // this.subMenuRef = Array.from(this.shadowRoot.querySelectorAll('.submenu-item'));
96
- // this.shadowRoot.querySelector('media-button').focus();
97
- // this.addEventListener('keydown', this.handleKeyDown.bind(this));
98
-
99
- // this.shadowRoot.querySelector('.menu-group media-button').shadowRoot.querySelector(`${this.selectedMenuOption}`);
100
80
  }
101
81
 
102
82
  updated(props) {
103
- // console.log(props)
104
83
  if (props.has('currentTab')) {
105
- // console.log(this.currentTab.mediatype, this.currentTab.moveTo)
106
-
107
- // const dd = this.shadowRoot.querySelector('primary-nav').shadowRoot.querySelector('media-menu');
108
84
  const mediaButtons = Array.from(this.shadowRoot.querySelectorAll('media-button'));
109
- // console.log(mediaButtons)
110
85
 
111
- // let = newIndex1 = 0;
112
86
  mediaButtons.map((button, index) => {
113
- // console.log(button.shadowRoot.querySelector('a.menu-item'));
114
-
115
87
  const linkItem = button.shadowRoot.querySelector('a.menu-item');
116
88
  if (linkItem) {
117
- // console.log(linkItem)
118
89
  if (linkItem.classList.contains(`${this.selectedMenuOption}`)) {
119
90
  linkItem.classList.remove('selected');
120
91
  linkItem.blur();
121
92
 
122
- // newIndex1 = this.currentTab.moveTo === 'next' ? index++ : index--;
123
- // if (this.currentTab.moveTo)
124
- // mediaButtons[index].shadowRoot.querySelector('a.menu-item').blur();
125
- // if (this.currentTab.moveTo === 'next') {
126
- // mediaButtons[index + 1].shadowRoot.querySelector('a.menu-item').focus();
127
- // } else if (this.currentTab.moveTo === 'prev') {
128
- mediaButtons[this.currentTab.moveTo === 'next' ? index + 1 : index - 1].shadowRoot.querySelector('a.menu-item').focus();
129
- // }
93
+ mediaButtons[this.currentTab.moveTo === 'next' ? index + 1 : index - 1].shadowRoot.querySelector('a.menu-item').focus();
130
94
  }
131
95
  }
132
96
  });
133
-
134
- // console.log('updatedddddddddddd', this.selectedMenuOption, this.shadowRoot.querySelector('.menu-group'));
135
-
136
-
137
- // this.shadowRoot.querySelector('.menu-group').focus();
138
- // console.log(props);
139
- // this.shadowRoot.querySelectorAll('media-button').shadowRoot.querySelector(`${this.selectedMenuOption}`);
140
-
141
- // this.requestUpdate();
142
- // this.updateRequest();
143
- // this.menuRef = Array.from(this.shadowRoot.querySelectorAll('media-button'));
144
97
  }
145
98
  }
146
99
 
147
- handleKeyDown(e) {
148
- // console.log('dddddddddddd')
149
- if (e.key === 'Tab') {
150
- console.log(this.menuRef)
151
- this.focusedIndex = (this.focusedIndex + 1) % this.menuRef.length;
152
- this.submenuFocusedIndex = -1; // reset submenu focus index
153
- this.menuRef[this.focusedIndex].focus();
154
- }
155
- }
156
-
157
- // handleSubMenuKeydown(e) {
158
- // console.log(e);
159
- // if (e.key === 'ArrowDown') {
160
- // this.focusedIndex = (this.focusedIndex + 1) % this.subMenuRef.length;
161
- // this.subMenuRef[this.focusedIndex].focus();
162
- // } else if (e.key === 'ArrowUp') {
163
- // this.focusedIndex = (this.focusedIndex - 1 + this.subMenuRef.length) % this.subMenuRef.length;
164
- // this.subMenuRef[this.focusedIndex].focus();
165
- // } else if (e.key === 'Escape') {
166
- // this.isSubMenuOpen = false;
167
- // this.requestUpdate();
168
- // setTimeout(() => this.menuRef[0]?.focus(), 0);
169
- // }
170
- // }
171
-
172
100
  get mediaMenuOptionsTemplate() {
173
101
  const buttons = menuSelection.map(({
174
102
  icon,
@@ -178,7 +106,6 @@ class MediaMenu extends LitElement {
178
106
  followable,
179
107
  }) => {
180
108
  const selected = this.selectedMenuOption === menu;
181
- // this.focusOn =
182
109
  return html`
183
110
  <media-button
184
111
  .config=${this.config}
@@ -191,7 +118,6 @@ class MediaMenu extends LitElement {
191
118
  .selected=${selected}
192
119
  .selectedMenuOption=${this.selectedMenuOption}
193
120
  data-mediatype="${menu}"
194
- .focusOn=${this.focusOn}
195
121
  ></media-button>
196
122
  `;
197
123
  });
@@ -81,6 +81,21 @@ class PrimaryNav extends TrackedElement {
81
81
  );
82
82
  }
83
83
 
84
+ updated(props) {
85
+ const { currentTab } = this;
86
+ const isUserMenuTab = currentTab && currentTab.mediatype === 'usermenu';
87
+ if (props.has('currentTab') && isUserMenuTab) {
88
+ console.log(currentTab)
89
+ const focusElement = currentTab.moveTo === 'next'
90
+ ? this.shadowRoot.querySelector('a.upload')
91
+ : this.shadowRoot.querySelector('.media-menu-container');
92
+
93
+ if (focusElement) {
94
+ focusElement.focus();
95
+ }
96
+ }
97
+ }
98
+
84
99
  get userIcon() {
85
100
  const userMenuClass = this.openMenu === 'user' ? 'active' : '';
86
101
  const userMenuToolTip = this.openMenu === 'user' ? 'Close user menu' : 'Expand user menu';
@@ -23,10 +23,6 @@ export default css`
23
23
 
24
24
  /* Mobile view styles */
25
25
  @media (max-width: 889px) {
26
- .media-menu-container {
27
- // position: relative;
28
- }
29
-
30
26
  .media-menu-inner {
31
27
  position: absolute;
32
28
  width: 100%;
@@ -9,8 +9,6 @@ export default css`
9
9
 
10
10
  nav {
11
11
  position: relative;
12
- display: -ms-grid;
13
- // display: grid;
14
12
  display: flex;
15
13
  height: 4rem;
16
14
  grid-template-areas: 'hamburger empty heart search user';
package/src/user-menu.js CHANGED
@@ -23,7 +23,7 @@ class UserMenu extends DropdownMenu {
23
23
  }
24
24
 
25
25
  updated(props) {
26
- if (props.has('open')) {
26
+ if (props.has('open') && this.open) {
27
27
  const container = this.shadowRoot?.querySelector('.nav-container');
28
28
 
29
29
  if (container) {