@brightspace-ui/core 3.159.4 → 3.159.5

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.
@@ -123,6 +123,7 @@ if (usePopoverMixin) {
123
123
  // reset to root view
124
124
  const menu = this.#getMenuElement();
125
125
  menu.show({ preventFocus: true });
126
+ menu.resetFocusables();
126
127
  }
127
128
 
128
129
  #handleFocus(e) {
@@ -303,6 +304,7 @@ if (usePopoverMixin) {
303
304
  // reset to root view
304
305
  const menu = this.__getMenuElement();
305
306
  menu.show({ preventFocus: true });
307
+ menu.resetFocusables();
306
308
  }
307
309
 
308
310
  _onFocus(e) {
@@ -97,14 +97,13 @@ class Menu extends PropertyRequiredMixin(ThemeMixin(HierarchicalViewMixin(LitEle
97
97
  firstUpdated(changedProperties) {
98
98
  super.firstUpdated(changedProperties);
99
99
 
100
- this.addEventListener('d2l-hierarchical-view-show-start', this._onVisibilityChange);
101
- this.addEventListener('d2l-hierarchical-view-hide-complete', this._onVisibilityChange);
100
+ this.addEventListener('d2l-hierarchical-view-show-start', this._onShowStart);
101
+ this.addEventListener('d2l-hierarchical-view-hide-complete', this._onHideComplete);
102
102
  this.addEventListener('d2l-hierarchical-view-show-complete', this._onShowComplete);
103
103
  this.addEventListener('d2l-hierarchical-view-resize', this._onViewResize);
104
104
  this.addEventListener('d2l-menu-item-visibility-change', this._onMenuItemsChanged);
105
105
  this.addEventListener('keydown', this._onKeyDown);
106
106
  this.addEventListener('keypress', this._onKeyPress);
107
- this.addEventListener('focusout', this._onFocusOut);
108
107
 
109
108
  this._labelChanged();
110
109
 
@@ -144,7 +143,9 @@ class Menu extends PropertyRequiredMixin(ThemeMixin(HierarchicalViewMixin(LitEle
144
143
  if (this.getMenuType() === 'menu-radio') {
145
144
  this._focusSelected();
146
145
  } else {
147
- this._focusFirst();
146
+ const lastFocused = this._getTabFocusable();
147
+ if (lastFocused) this._focusItem(lastFocused);
148
+ else this._focusFirst();
148
149
  }
149
150
  }
150
151
 
@@ -166,6 +167,10 @@ class Menu extends PropertyRequiredMixin(ThemeMixin(HierarchicalViewMixin(LitEle
166
167
  }
167
168
  }
168
169
 
170
+ resetFocusables() {
171
+ this._getTabFocusable()?.setAttribute('tabindex', '-1');
172
+ }
173
+
169
174
  _createReturnItem() {
170
175
  const item = document.createElement('d2l-menu-item-return');
171
176
  item.addEventListener('d2l-menu-item-select', (e) => {
@@ -177,6 +182,8 @@ class Menu extends PropertyRequiredMixin(ThemeMixin(HierarchicalViewMixin(LitEle
177
182
  }
178
183
 
179
184
  _focusFirst() {
185
+ const lastFocused = this._getTabFocusable();
186
+ if (lastFocused) lastFocused.setAttribute('tabindex', '-1');
180
187
  const item = this._tryGetNextFocusable();
181
188
  if (item) this._focusItem(item);
182
189
  }
@@ -192,11 +199,13 @@ class Menu extends PropertyRequiredMixin(ThemeMixin(HierarchicalViewMixin(LitEle
192
199
  }
193
200
 
194
201
  _focusNext(item) {
202
+ item.setAttribute('tabindex', '-1');
195
203
  item = this._tryGetNextFocusable(item);
196
204
  item ? this._focusItem(item) : this._focusFirst();
197
205
  }
198
206
 
199
207
  _focusPrevious(item) {
208
+ item.setAttribute('tabindex', '-1');
200
209
  item = this._tryGetPreviousFocusable(item);
201
210
  item ? this._focusItem(item) : this._focusLast();
202
211
  }
@@ -249,6 +258,10 @@ class Menu extends PropertyRequiredMixin(ThemeMixin(HierarchicalViewMixin(LitEle
249
258
  });
250
259
  }
251
260
 
261
+ _getTabFocusable() {
262
+ return this._items.find(i => i.getAttribute('tabindex') === '0');
263
+ }
264
+
252
265
  _isFocusable(item) {
253
266
  if (item.nodeType !== 1) {
254
267
  return false;
@@ -272,11 +285,9 @@ class Menu extends PropertyRequiredMixin(ThemeMixin(HierarchicalViewMixin(LitEle
272
285
  if (returnItem) returnItem.setAttribute('text', this.label);
273
286
  }
274
287
 
275
- _onFocusOut(e) {
276
- e.stopPropagation();
277
- const isMenuItem = e.target.role === 'menuitem' || e.target.role === 'menuitemcheckbox' || e.target.role === 'menuitemradio';
278
- if (!isMenuItem || e.target.hasAttribute('first') || e.target.hasChildView) return;
279
- e.target.setAttribute('tabindex', '-1');
288
+ _onHideComplete() {
289
+ this.resetFocusables();
290
+ this.active = this.isActive();
280
291
  }
281
292
 
282
293
  _onKeyDown(e) {
@@ -304,7 +315,8 @@ class Menu extends PropertyRequiredMixin(ThemeMixin(HierarchicalViewMixin(LitEle
304
315
  }
305
316
 
306
317
  _onKeyPress(e) {
307
- if (this._items.indexOf(e.composedPath()[0]) === -1) return;
318
+ const currentItem = e.composedPath()[0];
319
+ if (this._items.indexOf(currentItem) === -1) return;
308
320
 
309
321
  if (e.keyCode === keyCodes.DOWN || e.keyCode === keyCodes.UP
310
322
  || e.keyCode === keyCodes.SPACE || e.keyCode === keyCodes.ENTER
@@ -314,6 +326,8 @@ class Menu extends PropertyRequiredMixin(ThemeMixin(HierarchicalViewMixin(LitEle
314
326
 
315
327
  e.stopPropagation();
316
328
 
329
+ currentItem.setAttribute('tabindex', '-1');
330
+
317
331
  const startsWith = function(item, value) {
318
332
  if (item.text && item.text.length > 0 && item.text.toLowerCase().substr(0, 1) === value) {
319
333
  return true;
@@ -361,6 +375,10 @@ class Menu extends PropertyRequiredMixin(ThemeMixin(HierarchicalViewMixin(LitEle
361
375
  this.focus();
362
376
  }
363
377
 
378
+ _onShowStart() {
379
+ this.active = this.isActive();
380
+ }
381
+
364
382
  _onViewResize(e) {
365
383
  if (!this.rootView) return;
366
384
 
@@ -372,10 +390,6 @@ class Menu extends PropertyRequiredMixin(ThemeMixin(HierarchicalViewMixin(LitEle
372
390
  this.dispatchEvent(new CustomEvent('d2l-menu-resize', eventDetails));
373
391
  }
374
392
 
375
- _onVisibilityChange() {
376
- this.active = this.isActive();
377
- }
378
-
379
393
  _tryGetNextFocusable(item) {
380
394
  const focusableItems = this._items.filter(this._isFocusable, this);
381
395
  if (!focusableItems || focusableItems.length === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/core",
3
- "version": "3.159.4",
3
+ "version": "3.159.5",
4
4
  "description": "A collection of accessible, free, open-source web components for building Brightspace applications",
5
5
  "type": "module",
6
6
  "repository": "https://github.com/BrightspaceUI/core.git",