@brightspace-ui/core 2.180.8 → 2.181.0
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.
@@ -172,8 +172,8 @@ export const TagListItemMixin = superclass => class extends LocalizeCoreElement(
|
|
172
172
|
}
|
173
173
|
|
174
174
|
await this.updateComplete;
|
175
|
-
|
176
|
-
container.focus();
|
175
|
+
// delay the focus to allow focusin to fire
|
176
|
+
setTimeout(() => container.focus());
|
177
177
|
});
|
178
178
|
|
179
179
|
this.addEventListener('keydown', this._handleKeydown);
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import '../button/button-subtle.js';
|
2
2
|
import { css, html, LitElement } from 'lit';
|
3
|
+
import { getOffsetParent, isComposedAncestor } from '../../helpers/dom.js';
|
3
4
|
import { announce } from '../../helpers/announce.js';
|
4
5
|
import { ArrowKeysMixin } from '../../mixins/arrow-keys/arrow-keys-mixin.js';
|
5
6
|
import { classMap } from 'lit/directives/class-map.js';
|
6
7
|
import { getComposedActiveElement } from '../../helpers/focus.js';
|
7
|
-
import { getOffsetParent } from '../../helpers/dom.js';
|
8
8
|
import { InteractiveMixin } from '../../mixins/interactive/interactive-mixin.js';
|
9
9
|
import { LocalizeCoreElement } from '../../helpers/localize-core-element.js';
|
10
10
|
import ResizeObserver from 'resize-observer-polyfill/dist/ResizeObserver.es.js';
|
@@ -109,6 +109,7 @@ class TagList extends LocalizeCoreElement(InteractiveMixin(ArrowKeysMixin(LitEle
|
|
109
109
|
this._listContainerObserver = null;
|
110
110
|
this._resizeObserver = null;
|
111
111
|
this._showHiddenTags = false;
|
112
|
+
this._refocus = null;
|
112
113
|
}
|
113
114
|
|
114
115
|
disconnectedCallback() {
|
@@ -197,7 +198,7 @@ class TagList extends LocalizeCoreElement(InteractiveMixin(ArrowKeysMixin(LitEle
|
|
197
198
|
aria-roledescription="${this.localize('components.tag-list.role-description')}"
|
198
199
|
@d2l-tag-list-item-clear="${this._handleItemDeleted}"
|
199
200
|
@d2l-tag-list-item-tooltip-show="${this._handleKeyboardTooltipShown}">
|
200
|
-
<slot @slotchange="${this._handleSlotChange}"></slot>
|
201
|
+
<slot @slotchange="${this._handleSlotChange}" @focusout="${this._handleSlotFocusOut}" @focusin="${this._handleSlotFocusIn}"></slot>
|
201
202
|
${overflowButton}
|
202
203
|
<d2l-button-subtle
|
203
204
|
class="${classMap(clearableClasses)}"
|
@@ -219,9 +220,10 @@ class TagList extends LocalizeCoreElement(InteractiveMixin(ArrowKeysMixin(LitEle
|
|
219
220
|
<d2l-button-subtle aria-hidden="true" slim text="${this.localize('components.tag-list.num-hidden', { count: '##' })}" class="d2l-tag-list-hidden-button"></d2l-button-subtle>
|
220
221
|
${this.arrowKeysContainer(list)}
|
221
222
|
</div>
|
222
|
-
`,
|
223
|
+
`,
|
224
|
+
this.localize('components.tag-list.interactive-label', { count: this._items ? this._items.length : 0 }),
|
223
225
|
() => {
|
224
|
-
|
226
|
+
this._items?.[0]?.focus?.();
|
225
227
|
}
|
226
228
|
);
|
227
229
|
}
|
@@ -350,9 +352,11 @@ class TagList extends LocalizeCoreElement(InteractiveMixin(ArrowKeysMixin(LitEle
|
|
350
352
|
const itemIndex = children.indexOf(rootTarget);
|
351
353
|
|
352
354
|
if (children.length <= 1) return;
|
353
|
-
const focusableElem = children[itemIndex - 1] || children[itemIndex + 1];
|
354
355
|
|
355
|
-
setTimeout(() =>
|
356
|
+
setTimeout(() => {
|
357
|
+
const focusableElem = children[itemIndex - 1] || (children[itemIndex] === e.target ? children[itemIndex + 1] : children[itemIndex]);
|
358
|
+
focusableElem.focus();
|
359
|
+
}, this.clearFocusTimeout);
|
356
360
|
}
|
357
361
|
|
358
362
|
_handleKeyboardTooltipShown() {
|
@@ -406,7 +410,22 @@ class TagList extends LocalizeCoreElement(InteractiveMixin(ArrowKeysMixin(LitEle
|
|
406
410
|
this._items[0].setAttribute('keyboard-tooltip-item', true);
|
407
411
|
if (this._hasShownKeyboardTooltip) this._items[0].setAttribute('keyboard-tooltip-shown', true);
|
408
412
|
await this.updateComplete;
|
409
|
-
|
413
|
+
if (this._refocus?.classList.contains('d2l-tag-list-button')) {
|
414
|
+
this._refocus = this.shadowRoot.querySelector('.d2l-tag-list-button');
|
415
|
+
}
|
416
|
+
await this._refocus?.updateComplete;
|
417
|
+
(this._refocus || refocus).focus?.();
|
418
|
+
this._refocus = null;
|
419
|
+
}
|
420
|
+
|
421
|
+
_handleSlotFocusIn() {
|
422
|
+
this._items[0].setAttribute('tabindex', '-1');
|
423
|
+
}
|
424
|
+
|
425
|
+
_handleSlotFocusOut(e) {
|
426
|
+
if (!isComposedAncestor(e.currentTarget, e.relatedTarget)) {
|
427
|
+
this._items[0].setAttribute('tabindex', '0');
|
428
|
+
}
|
410
429
|
}
|
411
430
|
|
412
431
|
async _toggleHiddenTagVisibility(e) {
|
@@ -417,10 +436,11 @@ class TagList extends LocalizeCoreElement(InteractiveMixin(ArrowKeysMixin(LitEle
|
|
417
436
|
const isMoreButton = e.target.classList.contains('d2l-tag-list-button-show-more');
|
418
437
|
await this.updateComplete;
|
419
438
|
if (isMoreButton) {
|
420
|
-
this._items[this._chompIndex]
|
439
|
+
this._refocus = this._items[this._chompIndex];
|
421
440
|
} else {
|
422
|
-
this.shadowRoot.querySelector('.d2l-tag-list-button')
|
441
|
+
this._refocus = this.shadowRoot.querySelector('.d2l-tag-list-button');
|
423
442
|
}
|
443
|
+
this._refocus.focus();
|
424
444
|
}
|
425
445
|
}
|
426
446
|
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# LoadingCompleteMixin
|
2
|
+
|
3
|
+
The `LoadingCompleteMixin` contains boilerplate code for [`getLoadingComplete`](https://github.com/BrightspaceUI/testing#waiting-for-asynchronous-components). It simplifies fixture setup for custom components in automated tests, and provides a `loadingComplete` promise that can be used internally.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
Apply the mixin and call `resolveLoadingComplete()` once your component has finished loading
|
7
|
+
|
8
|
+
```js
|
9
|
+
import { LoadingCompleteMixin } from '@brightspace-ui/core/mixins/loading-complete/loading-complete-mixin.js';
|
10
|
+
|
11
|
+
class MyComponent extends LoadingCompleteMixin(LitElement) {
|
12
|
+
|
13
|
+
connectedCallback() {
|
14
|
+
this._fetchMyData().then(this.resolveLoadingComplete);
|
15
|
+
}
|
16
|
+
|
17
|
+
}
|
18
|
+
```
|
19
|
+
|
20
|
+
To make use of the `loadingComplete` promise, simply `await` it where needed:
|
21
|
+
|
22
|
+
```js
|
23
|
+
async removeSkeleton() {
|
24
|
+
await this.loadingComplete;
|
25
|
+
this.skeleton = false;
|
26
|
+
}
|
27
|
+
```
|
28
|
+
|
29
|
+
If for any reason `resolveLoadingComplete` is never called, `loadingComplete` won't resolve and any consumers will hang.
|
30
|
+
|
31
|
+
### `getLoadingComplete`
|
32
|
+
|
33
|
+
In some cases, instead of finding one spot to call `resolveLoadingComplete`, you may find it easier to `await` a set of promises in a custom `getLoadingComplete` method.
|
34
|
+
|
35
|
+
You'll also need to use this method if you're working in a general-use mixin rather than directly in a component.
|
36
|
+
|
37
|
+
```js
|
38
|
+
class MyComponent extends LoadingCompleteMixin(LitElement) {
|
39
|
+
|
40
|
+
async getLoadingComplete() {
|
41
|
+
await super.getLoadingComplete();
|
42
|
+
await this._myCustomIconImport;
|
43
|
+
await Promise.all(this._allMyDataPromises);
|
44
|
+
}
|
45
|
+
}
|
46
|
+
```
|
47
|
+
Note that the work to generate these promises should have already started, before `firstUpdated`, and we simply `await` them here.
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { dedupeMixin } from '@open-wc/dedupe-mixin';
|
2
|
+
|
3
|
+
export const LoadingCompleteMixin = dedupeMixin((superclass) => class extends superclass {
|
4
|
+
|
5
|
+
#loadingCompleteResolve;
|
6
|
+
|
7
|
+
// eslint-disable-next-line sort-class-members/sort-class-members
|
8
|
+
#loadingCompletePromise = !Object.prototype.hasOwnProperty.call(this.constructor.prototype, 'getLoadingComplete')
|
9
|
+
? new Promise(resolve => this.#loadingCompleteResolve = resolve)
|
10
|
+
: Promise.resolve();
|
11
|
+
|
12
|
+
get loadingComplete() {
|
13
|
+
return this.getLoadingComplete();
|
14
|
+
}
|
15
|
+
|
16
|
+
get resolveLoadingComplete() {
|
17
|
+
return () => {
|
18
|
+
if (this.#loadingCompleteResolve) {
|
19
|
+
this.#loadingCompleteResolve();
|
20
|
+
this.#loadingCompleteResolve = null;
|
21
|
+
}
|
22
|
+
};
|
23
|
+
}
|
24
|
+
|
25
|
+
async getLoadingComplete() {
|
26
|
+
await super.getLoadingComplete?.();
|
27
|
+
return this.#loadingCompletePromise;
|
28
|
+
}
|
29
|
+
|
30
|
+
});
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@brightspace-ui/core",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.181.0",
|
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",
|