@salesforcedevs/arch-components 1.20.17-alpha1 → 1.20.17-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 +45 -2
- package/src/modules/common/context/context.ts +14 -14
- package/src/modules/common/effectAdapter/__tests__/effectAdapter.test.ts +4 -4
- package/src/modules/common/effectAdapter/effectAdapter.ts +13 -7
- package/src/modules/common/reflectedElement/__tests__/reflectedElement.test.ts +5 -5
- package/src/modules/common/reflectedElement/reflectedElement.ts +1 -1
- package/src/modules/common/slot/__tests__/slot.test.ts +12 -12
- package/src/modules/common/slot/slot.ts +4 -3
- package/src/modules/sa/coverage/coverage.ts +14 -18
- package/src/modules/sa/coverage/types.d.ts +12 -12
- package/src/modules/sa/explorer/explorer.ts +25 -25
- package/src/modules/sa/gallery/gallery.ts +11 -11
- package/src/modules/shared/a11y/a11y.ts +5 -5
- package/src/modules/shared/color/color.ts +13 -13
- package/src/modules/shared/fetch/fetch.ts +6 -6
- package/src/modules/shared/helpers/helpers.ts +6 -6
- package/src/modules/shared/i18n/i18n.ts +1 -1
- package/src/modules/shared/labels/__tests__/helpers.test.ts +3 -3
- package/src/modules/shared/labels/__tests__/pointHelpers.test.ts +3 -3
- package/src/modules/shared/labels/__tests__/timeHelpers.test.ts +8 -8
- package/src/modules/shared/labels/helpers.ts +4 -4
- package/src/modules/shared/labels/pointHelpers.ts +2 -2
- package/src/modules/shared/labels/timeHelpers.ts +3 -3
- package/src/modules/shared/menu/menu.ts +22 -22
- package/src/modules/shared/polling-request.ts +2 -2
- package/src/modules/shared/testutils.ts +4 -4
- package/src/modules/shared/useEffectAttr.ts +5 -5
- package/src/modules/tds/appLauncher/__tests__/appLauncher.test.ts +8 -8
- package/src/modules/tds/appLauncher/appLauncher.ts +6 -6
- package/src/modules/tds/avatar/__tests__/avatar.test.ts +1 -1
- package/src/modules/tds/button/__tests__/button.test.ts +5 -5
- package/src/modules/tds/buttonIcon/__tests__/buttonIcon.test.ts +1 -1
- package/src/modules/tds/buttonLink/__tests__/buttonLink.test.ts +1 -1
- package/src/modules/tds/childSummary/childSummary.ts +2 -2
- package/src/modules/tds/contentChildListItem/__tests__/contentChildListItem.test.ts +2 -2
- package/src/modules/tds/contentIcon/contentIcon.ts +1 -1
- package/src/modules/tds/footerLinks/__tests__/footerLinks.test.ts +2 -2
- package/src/modules/tds/headerAvatar/__tests__/headerAvatar.test.ts +4 -4
- package/src/modules/tds/headerAvatar/headerAvatar.ts +5 -5
- package/src/modules/tds/headerHelpButton/__tests__/headerHelpButton.test.ts +2 -2
- package/src/modules/tds/heading/__tests__/heading.test.ts +7 -7
- package/src/modules/tds/icon/icon.ts +11 -11
- package/src/modules/tds/radio/__tests__/radio.test.ts +1 -1
- package/src/modules/tds/search/__tests__/search.test.ts +17 -17
- package/src/modules/tds/search/lib/__tests__/listbox.test.ts +16 -16
- package/src/modules/tds/search/lib/listbox.ts +16 -16
- package/src/modules/tds/search/search.ts +10 -10
- package/src/modules/tds/select/__tests__/select.test.ts +1 -1
- package/src/modules/tds/summary/__tests__/summary.test.ts +16 -16
- package/src/modules/tds/summary/summary.ts +2 -2
- package/src/modules/tds/themeProvider/themeProvider.ts +4 -4
- package/src/modules/th/favoriteButton/__tests__/favoriteButton.test.ts +1 -1
- package/src/modules/th/favoriteButton/mocks/index.ts +2 -2
- package/src/modules/th/search/__tests__/search.test.ts +2 -2
- package/src/modules/th/search/mocks/index.ts +1 -1
- package/src/modules/th/search/search.ts +21 -21
- package/src/modules/tm/card/card.ts +15 -15
- package/src/modules/tm/content/content.ts +11 -11
- package/src/modules/tm/endCapA/__tests__/endCapA.test.ts +2 -2
- package/src/modules/tm/eventsA/eventsA.ts +1 -1
- package/src/modules/tm/faqA/faqA.ts +4 -4
- package/src/modules/tm/featureGridA/__tests__/featureGridA.test.ts +2 -2
- package/src/modules/tm/footnote/footnote.ts +1 -1
- package/src/modules/tm/heroA/__tests__/heroA.test.ts +2 -2
- package/src/modules/tm/heroA/heroA.ts +3 -3
- package/src/modules/tm/promoA/__tests__/promoA.test.ts +3 -3
- package/src/modules/tm/promoA/promoA.ts +4 -4
- package/src/modules/tm/sectionA/sectionA.ts +1 -1
- package/src/modules/tm/utils/utils.ts +5 -5
- package/src/modules/tm/youtube/youtube.ts +2 -2
- package/src/modules/ui/focusTrap/focusTrap.ts +7 -7
- package/src/modules/ui/focusVisible/focusVisible.ts +7 -7
- package/src/modules/th/tbid/__tests__/__snapshots__/tbid.test.ts.snap +0 -3
- package/src/modules/th/tbid/__tests__/tbid.test.ts +0 -242
- package/src/modules/th/tbid/tbid.html +0 -1
- package/src/modules/th/tbid/tbid.stories.mdx +0 -25
- package/src/modules/th/tbid/tbid.ts +0 -215
|
@@ -6,7 +6,7 @@ customElements.define('tds-button', Button.CustomElementConstructor);
|
|
|
6
6
|
|
|
7
7
|
describe('tds-button', () => {
|
|
8
8
|
it('reflects attributes', async () => {
|
|
9
|
-
|
|
9
|
+
const element = renderIntoBody(
|
|
10
10
|
html` <tds-button aria-label="Hello"></tds-button> `
|
|
11
11
|
);
|
|
12
12
|
expect(element.shadowRoot!.querySelector('button')).toHaveAttribute(
|
|
@@ -16,7 +16,7 @@ describe('tds-button', () => {
|
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
it('can show a spinner', () => {
|
|
19
|
-
|
|
19
|
+
const element = renderIntoBody(
|
|
20
20
|
html` <tds-button spinner>Creating...</tds-button> `
|
|
21
21
|
);
|
|
22
22
|
|
|
@@ -24,7 +24,7 @@ describe('tds-button', () => {
|
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
it('applies size small class', async () => {
|
|
27
|
-
|
|
27
|
+
const element = renderIntoBody(
|
|
28
28
|
html` <tds-button size="small"></tds-button> `
|
|
29
29
|
);
|
|
30
30
|
expect(
|
|
@@ -33,7 +33,7 @@ describe('tds-button', () => {
|
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
it('applies size large class', async () => {
|
|
36
|
-
|
|
36
|
+
const element = renderIntoBody(
|
|
37
37
|
html` <tds-button size="large"></tds-button> `
|
|
38
38
|
);
|
|
39
39
|
expect(
|
|
@@ -42,7 +42,7 @@ describe('tds-button', () => {
|
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
it('does not apply invalid size class', async () => {
|
|
45
|
-
|
|
45
|
+
const element = renderIntoBody(
|
|
46
46
|
html` <tds-button size="floogle"></tds-button> `
|
|
47
47
|
);
|
|
48
48
|
expect(
|
|
@@ -6,7 +6,7 @@ customElements.define('tds-button-icon', ButtonIcon.CustomElementConstructor);
|
|
|
6
6
|
|
|
7
7
|
describe('tds-button-icon', () => {
|
|
8
8
|
it('reflects attributes', async () => {
|
|
9
|
-
|
|
9
|
+
const element = renderIntoBody(
|
|
10
10
|
html` <tds-button-icon aria-label="Hello"></tds-button-icon> `
|
|
11
11
|
);
|
|
12
12
|
expect(element.shadowRoot!.querySelector('button')).toHaveAttribute(
|
|
@@ -6,7 +6,7 @@ customElements.define('tds-button-link', ButtonLink.CustomElementConstructor);
|
|
|
6
6
|
|
|
7
7
|
describe('tds-button-link', () => {
|
|
8
8
|
it('reflects attributes', async () => {
|
|
9
|
-
|
|
9
|
+
const element = renderIntoBody(
|
|
10
10
|
html` <tds-button-link aria-label="Hello"></tds-button-link> `
|
|
11
11
|
);
|
|
12
12
|
expect(element.shadowRoot!.querySelector('a')).toHaveAttribute(
|
|
@@ -38,12 +38,12 @@ export default class extends LightningElement {
|
|
|
38
38
|
switch (this.titleMode) {
|
|
39
39
|
case 'anchor': {
|
|
40
40
|
if (e.target && (e.target as HTMLElement).tagName === 'A')
|
|
41
|
-
break;
|
|
41
|
+
{break;}
|
|
42
42
|
window.location.href = this.path!;
|
|
43
43
|
}
|
|
44
44
|
case 'button': {
|
|
45
45
|
if (e.target && (e.target as HTMLElement).tagName === 'BUTTON')
|
|
46
|
-
break;
|
|
46
|
+
{break;}
|
|
47
47
|
this.dispatchEvent(new CustomEvent('navigate'));
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -10,8 +10,8 @@ customElements.define(
|
|
|
10
10
|
|
|
11
11
|
describe('tds-content-child-list-item', () => {
|
|
12
12
|
it('dispatches a navigate event', async () => {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const handler = jest.fn();
|
|
14
|
+
const element = renderIntoBody(html`
|
|
15
15
|
<tds-content-child-list-item
|
|
16
16
|
.summary=${{ title: 'Hello' }}
|
|
17
17
|
title-mode="button"
|
|
@@ -33,7 +33,7 @@ export default class extends LightningElement {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
private get imageContainerStyles() {
|
|
36
|
-
|
|
36
|
+
const styles = `height: ${this.imageSize}px; width: ${this.imageSize}px;`;
|
|
37
37
|
if (this.background) {
|
|
38
38
|
return [styles, `background-color: ${this.color};`].join(' ');
|
|
39
39
|
}
|
|
@@ -92,7 +92,7 @@ describe('tds-footer-links', () => {
|
|
|
92
92
|
`
|
|
93
93
|
);
|
|
94
94
|
|
|
95
|
-
|
|
95
|
+
const handler = jest.fn();
|
|
96
96
|
document.addEventListener('trailhead_track', handler, {
|
|
97
97
|
once: true
|
|
98
98
|
});
|
|
@@ -128,7 +128,7 @@ describe('tds-footer-links', () => {
|
|
|
128
128
|
></tds-footer-links>
|
|
129
129
|
`
|
|
130
130
|
);
|
|
131
|
-
|
|
131
|
+
const handler = jest.fn();
|
|
132
132
|
element.addEventListener('link_click', handler);
|
|
133
133
|
// Columns
|
|
134
134
|
element
|
|
@@ -9,7 +9,7 @@ customElements.define(
|
|
|
9
9
|
|
|
10
10
|
describe('tds-header-avatar', () => {
|
|
11
11
|
it('sets the img src', () => {
|
|
12
|
-
|
|
12
|
+
const element = renderIntoBody(
|
|
13
13
|
html` <tds-header-avatar img-src="image.png"></tds-header-avatar> `
|
|
14
14
|
);
|
|
15
15
|
expect(element.shadowRoot!.querySelector('img')).toHaveAttribute(
|
|
@@ -18,7 +18,7 @@ describe('tds-header-avatar', () => {
|
|
|
18
18
|
);
|
|
19
19
|
});
|
|
20
20
|
it('sets the progress percent', () => {
|
|
21
|
-
|
|
21
|
+
const element = renderIntoBody(
|
|
22
22
|
html` <tds-header-avatar .percent=${50}></tds-header-avatar> `
|
|
23
23
|
);
|
|
24
24
|
expect(
|
|
@@ -26,7 +26,7 @@ describe('tds-header-avatar', () => {
|
|
|
26
26
|
).toHaveAttribute('aria-valuenow', '50');
|
|
27
27
|
});
|
|
28
28
|
it('sets the progress path', () => {
|
|
29
|
-
|
|
29
|
+
const element = renderIntoBody(
|
|
30
30
|
html` <tds-header-avatar .percent=${100}></tds-header-avatar> `
|
|
31
31
|
);
|
|
32
32
|
expect(element.shadowRoot!.querySelector('path')).toHaveAttribute(
|
|
@@ -35,7 +35,7 @@ describe('tds-header-avatar', () => {
|
|
|
35
35
|
);
|
|
36
36
|
});
|
|
37
37
|
it('hides the progress if no percent is passed', () => {
|
|
38
|
-
|
|
38
|
+
const element = renderIntoBody(
|
|
39
39
|
html` <tds-header-avatar></tds-header-avatar> `
|
|
40
40
|
);
|
|
41
41
|
expect(element.shadowRoot!.querySelector('svg')).toBeNull();
|
|
@@ -5,11 +5,11 @@ export default class extends LightningElement {
|
|
|
5
5
|
@api percent: number | null = null;
|
|
6
6
|
|
|
7
7
|
private get d() {
|
|
8
|
-
if (!this.percent) return '';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
if (!this.percent) {return '';}
|
|
9
|
+
const isLong = this.percent > 50 ? 1 : 0;
|
|
10
|
+
const fill = 1 - this.percent / 100;
|
|
11
|
+
const arcX = Math.cos(2 * Math.PI * fill);
|
|
12
|
+
const arcY = Math.sin(2 * Math.PI * fill);
|
|
13
13
|
return `M 1 0 A 1 1 0 ${isLong} 0 ${arcX} ${arcY} L 0 0`;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
@@ -10,12 +10,12 @@ customElements.define(
|
|
|
10
10
|
describe('tds-header-help-button', () => {
|
|
11
11
|
describe('tracking', () => {
|
|
12
12
|
it('header_help_clicked', () => {
|
|
13
|
-
|
|
13
|
+
const element = renderIntoBody(
|
|
14
14
|
html`
|
|
15
15
|
<tds-header-help-button href="/"></tds-header-help-button>
|
|
16
16
|
`
|
|
17
17
|
);
|
|
18
|
-
|
|
18
|
+
const handler = jest.fn();
|
|
19
19
|
document.addEventListener('trailhead_track', handler, {
|
|
20
20
|
once: true
|
|
21
21
|
});
|
|
@@ -6,43 +6,43 @@ customElements.define('tds-heading', Heading.CustomElementConstructor);
|
|
|
6
6
|
|
|
7
7
|
describe('tds-heading', () => {
|
|
8
8
|
it('level 1', () => {
|
|
9
|
-
|
|
9
|
+
const element = renderIntoBody(
|
|
10
10
|
html` <tds-heading level="1"></tds-heading> `
|
|
11
11
|
);
|
|
12
12
|
expect(element.shadowRoot!.querySelector('h1')).toBeTruthy();
|
|
13
13
|
});
|
|
14
14
|
it('level 2', () => {
|
|
15
|
-
|
|
15
|
+
const element = renderIntoBody(
|
|
16
16
|
html` <tds-heading level="2"></tds-heading> `
|
|
17
17
|
);
|
|
18
18
|
expect(element.shadowRoot!.querySelector('h2')).toBeTruthy();
|
|
19
19
|
});
|
|
20
20
|
it('level 3', () => {
|
|
21
|
-
|
|
21
|
+
const element = renderIntoBody(
|
|
22
22
|
html` <tds-heading level="3"></tds-heading> `
|
|
23
23
|
);
|
|
24
24
|
expect(element.shadowRoot!.querySelector('h3')).toBeTruthy();
|
|
25
25
|
});
|
|
26
26
|
it('level 4', () => {
|
|
27
|
-
|
|
27
|
+
const element = renderIntoBody(
|
|
28
28
|
html` <tds-heading level="4"></tds-heading> `
|
|
29
29
|
);
|
|
30
30
|
expect(element.shadowRoot!.querySelector('h4')).toBeTruthy();
|
|
31
31
|
});
|
|
32
32
|
it('level 5', () => {
|
|
33
|
-
|
|
33
|
+
const element = renderIntoBody(
|
|
34
34
|
html` <tds-heading level="5"></tds-heading> `
|
|
35
35
|
);
|
|
36
36
|
expect(element.shadowRoot!.querySelector('h5')).toBeTruthy();
|
|
37
37
|
});
|
|
38
38
|
it('level 6', () => {
|
|
39
|
-
|
|
39
|
+
const element = renderIntoBody(
|
|
40
40
|
html` <tds-heading level="6"></tds-heading> `
|
|
41
41
|
);
|
|
42
42
|
expect(element.shadowRoot!.querySelector('h6')).toBeTruthy();
|
|
43
43
|
});
|
|
44
44
|
it('null', () => {
|
|
45
|
-
|
|
45
|
+
const element = renderIntoBody(html` <tds-heading></tds-heading> `);
|
|
46
46
|
expect(
|
|
47
47
|
Array.from(element.shadowRoot!.children).map((n) => n.tagName)
|
|
48
48
|
).toEqual(['SLOT']);
|
|
@@ -43,32 +43,32 @@ export default class extends LightningElement {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
renderedCallback() {
|
|
46
|
-
if (this.context.crossOriginAssets) this.appendNodes();
|
|
46
|
+
if (this.context.crossOriginAssets) {this.appendNodes();}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
private async appendNodes() {
|
|
50
|
-
if (process.env.NODE_ENV === 'test') return;
|
|
51
|
-
|
|
52
|
-
if (this.node && this.node.id === symbolId) return;
|
|
50
|
+
if (process.env.NODE_ENV === 'test') {return;}
|
|
51
|
+
const { symbolId } = this;
|
|
52
|
+
if (this.node && this.node.id === symbolId) {return;}
|
|
53
53
|
await this.fetchSprite(this.sprite);
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
const svg = this.template.querySelector('svg')!;
|
|
55
|
+
const node = document
|
|
56
56
|
.getElementById(symbolId)!
|
|
57
57
|
.cloneNode(true) as SVGSymbolElement;
|
|
58
|
-
while (svg.firstChild) svg.removeChild(svg.firstChild);
|
|
59
|
-
for (
|
|
58
|
+
while (svg.firstChild) {svg.removeChild(svg.firstChild);}
|
|
59
|
+
for (const n of Array.from(node.childNodes)) {svg.appendChild(n);}
|
|
60
60
|
svg.setAttribute('viewBox', node.getAttribute('viewBox')!);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
private async fetchSprite(sprite: Sprite) {
|
|
64
|
-
if (fetches.has(sprite)) return fetches.get(sprite);
|
|
65
|
-
|
|
64
|
+
if (fetches.has(sprite)) {return fetches.get(sprite);}
|
|
65
|
+
const promise = fetch(
|
|
66
66
|
`${this.context.assetsUrl}/icons/${this.sprite}-sprite/svg/symbols.svg`
|
|
67
67
|
)
|
|
68
68
|
.then((res) => res.text())
|
|
69
69
|
.then((svg) => svg.replace(/id=\"/g, `id="tds__${sprite}__`))
|
|
70
70
|
.then((svg) => {
|
|
71
|
-
|
|
71
|
+
const node = document.createElement('div');
|
|
72
72
|
node.innerHTML = svg;
|
|
73
73
|
node.style.display = 'none';
|
|
74
74
|
document.body.appendChild(node);
|
|
@@ -4,7 +4,7 @@ import { default as Search } from '../search';
|
|
|
4
4
|
|
|
5
5
|
customElements.define('tds-search', Search.CustomElementConstructor);
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const location = {};
|
|
8
8
|
|
|
9
9
|
Object.defineProperty(window, 'location', {
|
|
10
10
|
get: () => location
|
|
@@ -25,7 +25,7 @@ describe('tds-search', () => {
|
|
|
25
25
|
document.body.innerHTML = '';
|
|
26
26
|
});
|
|
27
27
|
it('placeholder', () => {
|
|
28
|
-
|
|
28
|
+
const element = renderIntoBody(
|
|
29
29
|
html` <tds-search placeholder="Search"></tds-search> `
|
|
30
30
|
);
|
|
31
31
|
expect(element.shadowRoot!.querySelector('input')).toHaveAttribute(
|
|
@@ -34,7 +34,7 @@ describe('tds-search', () => {
|
|
|
34
34
|
);
|
|
35
35
|
});
|
|
36
36
|
it('defaultValue', async () => {
|
|
37
|
-
|
|
37
|
+
const element = renderIntoBody(
|
|
38
38
|
html`
|
|
39
39
|
<tds-search
|
|
40
40
|
default-value="lwc"
|
|
@@ -56,7 +56,7 @@ describe('tds-search', () => {
|
|
|
56
56
|
).toBe(null);
|
|
57
57
|
});
|
|
58
58
|
it('sets the icon style', async () => {
|
|
59
|
-
|
|
59
|
+
const element = renderIntoBody(
|
|
60
60
|
html`
|
|
61
61
|
<tds-search
|
|
62
62
|
.recents=${[
|
|
@@ -79,7 +79,7 @@ describe('tds-search', () => {
|
|
|
79
79
|
// Wait a bit more for the listbox to render
|
|
80
80
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
const image = element.shadowRoot!.querySelector('.search-result__image');
|
|
83
83
|
|
|
84
84
|
if (image) {
|
|
85
85
|
expect(image).toHaveStyle('background-color: red;');
|
|
@@ -90,17 +90,17 @@ describe('tds-search', () => {
|
|
|
90
90
|
}, 10000);
|
|
91
91
|
describe('events', () => {
|
|
92
92
|
it('focus', () => {
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
const onFocus = jest.fn();
|
|
94
|
+
const element = renderIntoBody(html` <tds-search></tds-search> `);
|
|
95
95
|
element.addEventListener('focus', onFocus);
|
|
96
96
|
element.shadowRoot!.querySelector('input')!.focus();
|
|
97
97
|
expect(onFocus).toHaveBeenCalled();
|
|
98
98
|
});
|
|
99
99
|
it('change', async () => {
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
const onChange = jest.fn();
|
|
101
|
+
const element = renderIntoBody(html` <tds-search></tds-search> `);
|
|
102
102
|
element.addEventListener('change', onChange);
|
|
103
|
-
|
|
103
|
+
const $input = element.shadowRoot!.querySelector('input')!;
|
|
104
104
|
$input.value = 'test';
|
|
105
105
|
$input.dispatchEvent(new InputEvent('input', { bubbles: true }));
|
|
106
106
|
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
@@ -111,8 +111,8 @@ describe('tds-search', () => {
|
|
|
111
111
|
});
|
|
112
112
|
describe('search', () => {
|
|
113
113
|
it('type=completion', async () => {
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
const onSearch = jest.fn();
|
|
115
|
+
const element = renderIntoBody(
|
|
116
116
|
html`
|
|
117
117
|
<tds-search
|
|
118
118
|
.completions=${[{ value: 'Test' }]}
|
|
@@ -148,10 +148,10 @@ describe('tds-search', () => {
|
|
|
148
148
|
}
|
|
149
149
|
}, 10000);
|
|
150
150
|
it('type=input', async () => {
|
|
151
|
-
|
|
152
|
-
|
|
151
|
+
const onSearch = jest.fn();
|
|
152
|
+
const element = renderIntoBody(html` <tds-search></tds-search> `);
|
|
153
153
|
element.addEventListener('search', onSearch);
|
|
154
|
-
|
|
154
|
+
const $input = element.shadowRoot!.querySelector('input')!;
|
|
155
155
|
$input.value = 'test';
|
|
156
156
|
$input.dispatchEvent(
|
|
157
157
|
new InputEvent('input', { bubbles: true })
|
|
@@ -190,8 +190,8 @@ describe('tds-search', () => {
|
|
|
190
190
|
}
|
|
191
191
|
}, 10000);
|
|
192
192
|
it('type=recent', async () => {
|
|
193
|
-
|
|
194
|
-
|
|
193
|
+
const onSearch = jest.fn();
|
|
194
|
+
const element = renderIntoBody(
|
|
195
195
|
html`
|
|
196
196
|
<tds-search
|
|
197
197
|
.recents=${[
|
|
@@ -18,7 +18,7 @@ describe('Listbox', () => {
|
|
|
18
18
|
onChange = jest.fn();
|
|
19
19
|
onSelect = jest.fn();
|
|
20
20
|
onSubmit = jest.fn();
|
|
21
|
-
|
|
21
|
+
const $element = document.createElement('div');
|
|
22
22
|
$shadow = $element.attachShadow({ mode: 'open' });
|
|
23
23
|
$shadow.innerHTML = createListboxTemplate(createListboxItems());
|
|
24
24
|
listbox = createListbox($shadow, onChange, onSelect, onSubmit);
|
|
@@ -29,7 +29,7 @@ describe('Listbox', () => {
|
|
|
29
29
|
expect($shadow.innerHTML).toMatchSnapshot();
|
|
30
30
|
});
|
|
31
31
|
it('focus', async () => {
|
|
32
|
-
|
|
32
|
+
const focusEvent = new FocusEvent('focus', {
|
|
33
33
|
bubbles: false,
|
|
34
34
|
cancelable: true
|
|
35
35
|
});
|
|
@@ -37,13 +37,13 @@ describe('Listbox', () => {
|
|
|
37
37
|
expect($shadow.innerHTML).toMatchSnapshot();
|
|
38
38
|
});
|
|
39
39
|
it('focus (empty)', async () => {
|
|
40
|
-
|
|
40
|
+
const $element = document.createElement('div');
|
|
41
41
|
$shadow = $element.attachShadow({ mode: 'open' });
|
|
42
42
|
$shadow.innerHTML = createListboxTemplate([]);
|
|
43
43
|
listbox = createListbox($shadow, onChange, onSelect, onSubmit);
|
|
44
44
|
listbox.renderedCallback();
|
|
45
45
|
$input = $shadow.querySelector('input') as HTMLInputElement;
|
|
46
|
-
|
|
46
|
+
const focusEvent = new FocusEvent('focus', {
|
|
47
47
|
bubbles: false,
|
|
48
48
|
cancelable: true
|
|
49
49
|
});
|
|
@@ -51,11 +51,11 @@ describe('Listbox', () => {
|
|
|
51
51
|
expect($shadow.innerHTML).toMatchSnapshot();
|
|
52
52
|
});
|
|
53
53
|
it('submit', async () => {
|
|
54
|
-
|
|
54
|
+
const focusEvent = new FocusEvent('focus', {
|
|
55
55
|
bubbles: false,
|
|
56
56
|
cancelable: true
|
|
57
57
|
});
|
|
58
|
-
|
|
58
|
+
const keydownEvent = new KeyboardEvent('keydown', {
|
|
59
59
|
bubbles: false,
|
|
60
60
|
cancelable: true,
|
|
61
61
|
key: 'Enter'
|
|
@@ -66,11 +66,11 @@ describe('Listbox', () => {
|
|
|
66
66
|
expect(onSubmit).toHaveBeenCalledTimes(1);
|
|
67
67
|
});
|
|
68
68
|
it('arrow down', async () => {
|
|
69
|
-
|
|
69
|
+
const focusEvent = new FocusEvent('focus', {
|
|
70
70
|
bubbles: false,
|
|
71
71
|
cancelable: true
|
|
72
72
|
});
|
|
73
|
-
|
|
73
|
+
const keydownEvent = new KeyboardEvent('keydown', {
|
|
74
74
|
bubbles: false,
|
|
75
75
|
cancelable: true,
|
|
76
76
|
key: 'ArrowDown'
|
|
@@ -86,11 +86,11 @@ describe('Listbox', () => {
|
|
|
86
86
|
expect($input).toHaveAttribute('aria-activedescendant', 'a');
|
|
87
87
|
});
|
|
88
88
|
it('arrow up', async () => {
|
|
89
|
-
|
|
89
|
+
const focusEvent = new FocusEvent('focus', {
|
|
90
90
|
bubbles: false,
|
|
91
91
|
cancelable: true
|
|
92
92
|
});
|
|
93
|
-
|
|
93
|
+
const keydownEvent = new KeyboardEvent('keydown', {
|
|
94
94
|
bubbles: false,
|
|
95
95
|
cancelable: true,
|
|
96
96
|
key: 'ArrowUp'
|
|
@@ -102,11 +102,11 @@ describe('Listbox', () => {
|
|
|
102
102
|
expect($input).toHaveAttribute('aria-activedescendant', 'b');
|
|
103
103
|
});
|
|
104
104
|
it('enter', async () => {
|
|
105
|
-
|
|
105
|
+
const focusEvent = new FocusEvent('focus', {
|
|
106
106
|
bubbles: false,
|
|
107
107
|
cancelable: true
|
|
108
108
|
});
|
|
109
|
-
|
|
109
|
+
const keydownEvent = (key: string) =>
|
|
110
110
|
new KeyboardEvent('keydown', {
|
|
111
111
|
bubbles: false,
|
|
112
112
|
cancelable: true,
|
|
@@ -119,7 +119,7 @@ describe('Listbox', () => {
|
|
|
119
119
|
expect(onSelect).toHaveBeenCalledWith(1);
|
|
120
120
|
});
|
|
121
121
|
it('blur', async () => {
|
|
122
|
-
|
|
122
|
+
const focusEvent = new FocusEvent('blur', {
|
|
123
123
|
bubbles: false,
|
|
124
124
|
cancelable: true
|
|
125
125
|
});
|
|
@@ -127,15 +127,15 @@ describe('Listbox', () => {
|
|
|
127
127
|
expect($shadow.innerHTML).toMatchSnapshot();
|
|
128
128
|
});
|
|
129
129
|
it('click', async () => {
|
|
130
|
-
|
|
130
|
+
const focusEvent = new FocusEvent('blur', {
|
|
131
131
|
bubbles: false,
|
|
132
132
|
cancelable: true
|
|
133
133
|
});
|
|
134
|
-
|
|
134
|
+
const mouseEnterEvent = new MouseEvent('mouseenter', {
|
|
135
135
|
bubbles: false,
|
|
136
136
|
cancelable: true
|
|
137
137
|
});
|
|
138
|
-
|
|
138
|
+
const clickEvent = new MouseEvent('click', {
|
|
139
139
|
bubbles: true,
|
|
140
140
|
cancelable: true
|
|
141
141
|
});
|
|
@@ -55,7 +55,7 @@ export class Listbox {
|
|
|
55
55
|
| Partial<ListboxState>
|
|
56
56
|
| ((state: ListboxState) => Partial<ListboxState>)
|
|
57
57
|
) {
|
|
58
|
-
|
|
58
|
+
const { state } = this;
|
|
59
59
|
this.state = {
|
|
60
60
|
...state,
|
|
61
61
|
...(typeof nextState === 'function' ? nextState(state) : nextState)
|
|
@@ -64,8 +64,8 @@ export class Listbox {
|
|
|
64
64
|
|
|
65
65
|
renderedCallback() {
|
|
66
66
|
if (!this.state.setup) {
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
const $input = this.getElement('input')!;
|
|
68
|
+
const $options = this.getElement(SELECTOR_OPTIONS)!;
|
|
69
69
|
$input.addEventListener('blur', this.onBlur as EventListener);
|
|
70
70
|
$input.addEventListener('focus', this.onFocus as EventListener);
|
|
71
71
|
$input.addEventListener('keydown', this.onKeyDown as EventListener);
|
|
@@ -81,8 +81,8 @@ export class Listbox {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
disconnectedCallback() {
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
const $input = this.getElement(SELECTOR_INPUT)!;
|
|
85
|
+
const $options = this.getElement(SELECTOR_OPTIONS)!;
|
|
86
86
|
if ($input) {
|
|
87
87
|
$input.removeEventListener('blur', this.onBlur as EventListener);
|
|
88
88
|
$input.removeEventListener('focus', this.onFocus as EventListener);
|
|
@@ -100,7 +100,7 @@ export class Listbox {
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
private onClick = (e: MouseEvent) => {
|
|
103
|
-
|
|
103
|
+
const selectedIndex = Array.from(
|
|
104
104
|
this.input.shadowRoot.querySelectorAll(getSelector(SELECTOR_OPTION))
|
|
105
105
|
).findIndex((n) => n.contains(e.target as HTMLElement));
|
|
106
106
|
this.setState({ active: false, selectedIndex });
|
|
@@ -123,7 +123,7 @@ export class Listbox {
|
|
|
123
123
|
this.setState((state) => {
|
|
124
124
|
let { selectedIndex } = state;
|
|
125
125
|
selectedIndex--;
|
|
126
|
-
if (selectedIndex < 0) selectedIndex = this._count - 1;
|
|
126
|
+
if (selectedIndex < 0) {selectedIndex = this._count - 1;}
|
|
127
127
|
return { selectedIndex };
|
|
128
128
|
});
|
|
129
129
|
break;
|
|
@@ -131,7 +131,7 @@ export class Listbox {
|
|
|
131
131
|
this.setState((state) => {
|
|
132
132
|
let { selectedIndex } = state;
|
|
133
133
|
selectedIndex++;
|
|
134
|
-
if (selectedIndex === this._count) selectedIndex = 0;
|
|
134
|
+
if (selectedIndex === this._count) {selectedIndex = 0;}
|
|
135
135
|
return { selectedIndex };
|
|
136
136
|
});
|
|
137
137
|
break;
|
|
@@ -155,18 +155,18 @@ export class Listbox {
|
|
|
155
155
|
};
|
|
156
156
|
|
|
157
157
|
private setRootAttributes() {
|
|
158
|
-
|
|
158
|
+
const $root = this.getElement(SELECTOR_ROOT)!;
|
|
159
159
|
$root.setAttribute('aria-expanded', String(this.isExpanded));
|
|
160
160
|
$root.setAttribute('aria-haspopup', 'listbox');
|
|
161
161
|
$root.setAttribute('role', 'combobox');
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
private setInputAttributes() {
|
|
165
|
-
|
|
165
|
+
const $activeDecendant = this.input.shadowRoot.querySelectorAll(
|
|
166
166
|
getSelector(SELECTOR_OPTION)
|
|
167
167
|
)[this.state.selectedIndex] as HTMLElement | undefined;
|
|
168
|
-
|
|
169
|
-
|
|
168
|
+
const $input = this.getElement(SELECTOR_INPUT)!;
|
|
169
|
+
const $options = this.getElement(SELECTOR_OPTIONS)!;
|
|
170
170
|
$input.setAttribute(
|
|
171
171
|
'aria-activedescendant',
|
|
172
172
|
$activeDecendant ? $activeDecendant.getAttribute('id') || '' : ''
|
|
@@ -177,12 +177,12 @@ export class Listbox {
|
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
private setListboxAttributes() {
|
|
180
|
-
|
|
180
|
+
const $options = this.getElement(SELECTOR_OPTIONS)!;
|
|
181
181
|
$options.setAttribute('role', 'listbox');
|
|
182
182
|
$options.setAttribute('aria-hidden', String(!this.isExpanded));
|
|
183
183
|
this.input.shadowRoot.querySelectorAll('ui,li').forEach((node) => {
|
|
184
|
-
|
|
185
|
-
if (element.hasAttribute('role')) return;
|
|
184
|
+
const element = node as HTMLElement;
|
|
185
|
+
if (element.hasAttribute('role')) {return;}
|
|
186
186
|
element.setAttribute('role', 'presentation');
|
|
187
187
|
});
|
|
188
188
|
}
|
|
@@ -191,7 +191,7 @@ export class Listbox {
|
|
|
191
191
|
this.input.shadowRoot
|
|
192
192
|
.querySelectorAll(getSelector(SELECTOR_OPTION))
|
|
193
193
|
.forEach((node, i) => {
|
|
194
|
-
|
|
194
|
+
const element = node as HTMLElement;
|
|
195
195
|
element.setAttribute(
|
|
196
196
|
'aria-selected',
|
|
197
197
|
String(i === this.state.selectedIndex)
|