@spectrum-web-components/swatch 0.1.2 → 0.1.3-devmode.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.
- package/package.json +33 -13
- package/sp-swatch-group.dev.js +3 -0
- package/sp-swatch-group.dev.js.map +7 -0
- package/sp-swatch-group.js +3 -14
- package/sp-swatch-group.js.map +7 -1
- package/sp-swatch.dev.js +3 -0
- package/sp-swatch.dev.js.map +7 -0
- package/sp-swatch.js +3 -14
- package/sp-swatch.js.map +7 -1
- package/src/Swatch.dev.js +219 -0
- package/src/Swatch.dev.js.map +7 -0
- package/src/Swatch.js +165 -170
- package/src/Swatch.js.map +7 -1
- package/src/SwatchGroup.dev.js +220 -0
- package/src/SwatchGroup.dev.js.map +7 -0
- package/src/SwatchGroup.js +201 -216
- package/src/SwatchGroup.js.map +7 -1
- package/src/index.dev.js +3 -0
- package/src/index.dev.js.map +7 -0
- package/src/index.js +3 -14
- package/src/index.js.map +7 -1
- package/src/spectrum-swatch-group.css.dev.js +10 -0
- package/src/spectrum-swatch-group.css.dev.js.map +7 -0
- package/src/spectrum-swatch-group.css.js +3 -14
- package/src/spectrum-swatch-group.css.js.map +7 -1
- package/src/spectrum-swatch.css.dev.js +66 -0
- package/src/spectrum-swatch.css.dev.js.map +7 -0
- package/src/spectrum-swatch.css.js +3 -14
- package/src/spectrum-swatch.css.js.map +7 -1
- package/src/swatch-group.css.dev.js +10 -0
- package/src/swatch-group.css.dev.js.map +7 -0
- package/src/swatch-group.css.js +3 -14
- package/src/swatch-group.css.js.map +7 -1
- package/src/swatch.css.dev.js +66 -0
- package/src/swatch.css.dev.js.map +7 -0
- package/src/swatch.css.js +3 -14
- package/src/swatch.css.js.map +7 -1
- package/stories/swatch-group.stories.js +124 -133
- package/stories/swatch-group.stories.js.map +7 -1
- package/stories/swatch-sizes.stories.js +15 -21
- package/stories/swatch-sizes.stories.js.map +7 -1
- package/stories/swatch.stories.js +69 -73
- package/stories/swatch.stories.js.map +7 -1
- package/test/benchmark/basic-test.js +5 -16
- package/test/benchmark/basic-test.js.map +7 -1
- package/test/swatch-group.test-vrt.js +4 -15
- package/test/swatch-group.test-vrt.js.map +7 -1
- package/test/swatch-group.test.js +229 -240
- package/test/swatch-group.test.js.map +7 -1
- package/test/swatch-sizes.test-vrt.js +4 -15
- package/test/swatch-sizes.test-vrt.js.map +7 -1
- package/test/swatch.test-vrt.js +4 -15
- package/test/swatch.test-vrt.js.map +7 -1
- package/test/swatch.test.js +124 -135
- package/test/swatch.test.js.map +7 -1
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["swatch.stories.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { html, TemplateResult } from '@spectrum-web-components/base';\nimport { ifDefined } from '@spectrum-web-components/base/src/directives.js';\n\nimport '../sp-swatch.js';\nimport type {\n SwatchBorder,\n SwatchRounding,\n SwatchShape,\n} from '../src/Swatch.js';\n\ntype Properties = {\n color: string;\n border: SwatchBorder | 'normal';\n rounding: SwatchRounding | 'normal';\n shape: SwatchShape | 'normal';\n mixedValue?: boolean;\n nothing?: boolean;\n};\n\nexport default {\n title: 'Swatch',\n component: 'sp-swatch',\n args: {\n color: '#ff0000',\n },\n argTypes: {\n color: { control: 'color' },\n border: {\n name: 'border',\n type: { name: 'string', required: false },\n description: 'The border to apply to the Swatch children.',\n table: {\n defaultValue: { summary: '' },\n },\n control: {\n type: 'inline-radio',\n options: ['normal', 'light', 'none'],\n },\n },\n rounding: {\n name: 'rounding',\n type: { name: 'string', required: false },\n description: 'The rounding to apply to the Swatch children.',\n table: {\n defaultValue: { summary: '' },\n },\n control: {\n type: 'inline-radio',\n options: ['normal', 'none', 'full'],\n },\n },\n shape: {\n name: 'shape',\n type: { name: 'string', required: false },\n description: 'The shape to apply to the Swatch children.',\n table: {\n defaultValue: { summary: '' },\n },\n control: {\n type: 'inline-radio',\n options: ['normal', 'rectangle'],\n },\n },\n },\n};\n\nconst template = ({\n color,\n border,\n rounding,\n shape,\n mixedValue,\n nothing,\n}: Properties): TemplateResult => {\n return html`\n <sp-swatch\n border=${ifDefined(border === 'normal' ? undefined : border)}\n rounding=${ifDefined(rounding === 'normal' ? undefined : rounding)}\n shape=${ifDefined(shape === 'normal' ? undefined : shape)}\n color=${color}\n ?mixed-value=${mixedValue}\n ?nothing=${nothing}\n ></sp-swatch>\n `;\n};\n\nexport const Default = (args: Properties): TemplateResult => template(args);\nexport const mixedValue = (args: Properties): TemplateResult => template(args);\nmixedValue.args = {\n mixedValue: true,\n color: '',\n};\nexport const nothing = (args: Properties): TemplateResult => template(args);\nnothing.args = {\n nothing: true,\n color: '',\n};\nexport const borderLight = (args: Properties): TemplateResult => template(args);\nborderLight.args = {\n border: 'light',\n};\nexport const borderNone = (args: Properties): TemplateResult => template(args);\nborderNone.args = {\n border: 'none',\n};\nexport const roundingNone = (args: Properties): TemplateResult =>\n template(args);\nroundingNone.args = {\n rounding: 'none',\n};\nexport const roundingFull = (args: Properties): TemplateResult =>\n template(args);\nroundingFull.args = {\n rounding: 'full',\n};\nexport const shapeRectangle = (args: Properties): TemplateResult =>\n template(args);\nshapeRectangle.args = {\n shape: 'rectangle',\n};\n"],
|
|
5
|
+
"mappings": "AAWA;AACA;AAEA;AAgBA,eAAe;AAAA,EACX,OAAO;AAAA,EACP,WAAW;AAAA,EACX,MAAM;AAAA,IACF,OAAO;AAAA,EACX;AAAA,EACA,UAAU;AAAA,IACN,OAAO,EAAE,SAAS,QAAQ;AAAA,IAC1B,QAAQ;AAAA,MACJ,MAAM;AAAA,MACN,MAAM,EAAE,MAAM,UAAU,UAAU,MAAM;AAAA,MACxC,aAAa;AAAA,MACb,OAAO;AAAA,QACH,cAAc,EAAE,SAAS,GAAG;AAAA,MAChC;AAAA,MACA,SAAS;AAAA,QACL,MAAM;AAAA,QACN,SAAS,CAAC,UAAU,SAAS,MAAM;AAAA,MACvC;AAAA,IACJ;AAAA,IACA,UAAU;AAAA,MACN,MAAM;AAAA,MACN,MAAM,EAAE,MAAM,UAAU,UAAU,MAAM;AAAA,MACxC,aAAa;AAAA,MACb,OAAO;AAAA,QACH,cAAc,EAAE,SAAS,GAAG;AAAA,MAChC;AAAA,MACA,SAAS;AAAA,QACL,MAAM;AAAA,QACN,SAAS,CAAC,UAAU,QAAQ,MAAM;AAAA,MACtC;AAAA,IACJ;AAAA,IACA,OAAO;AAAA,MACH,MAAM;AAAA,MACN,MAAM,EAAE,MAAM,UAAU,UAAU,MAAM;AAAA,MACxC,aAAa;AAAA,MACb,OAAO;AAAA,QACH,cAAc,EAAE,SAAS,GAAG;AAAA,MAChC;AAAA,MACA,SAAS;AAAA,QACL,MAAM;AAAA,QACN,SAAS,CAAC,UAAU,WAAW;AAAA,MACnC;AAAA,IACJ;AAAA,EACJ;AACJ;AAEA,MAAM,WAAW,CAAC;AAAA,EACd;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,MAC8B;AAC9B,SAAO;AAAA;AAAA,qBAEU,UAAU,WAAW,WAAW,SAAY,MAAM;AAAA,uBAChD,UAAU,aAAa,WAAW,SAAY,QAAQ;AAAA,oBACzD,UAAU,UAAU,WAAW,SAAY,KAAK;AAAA,oBAChD;AAAA,2BACO;AAAA,uBACJ;AAAA;AAAA;AAGvB;AAEO,aAAM,UAAU,CAAC,SAAqC,SAAS,IAAI;AACnE,aAAM,aAAa,CAAC,SAAqC,SAAS,IAAI;AAC7E,WAAW,OAAO;AAAA,EACd,YAAY;AAAA,EACZ,OAAO;AACX;AACO,aAAM,UAAU,CAAC,SAAqC,SAAS,IAAI;AAC1E,QAAQ,OAAO;AAAA,EACX,SAAS;AAAA,EACT,OAAO;AACX;AACO,aAAM,cAAc,CAAC,SAAqC,SAAS,IAAI;AAC9E,YAAY,OAAO;AAAA,EACf,QAAQ;AACZ;AACO,aAAM,aAAa,CAAC,SAAqC,SAAS,IAAI;AAC7E,WAAW,OAAO;AAAA,EACd,QAAQ;AACZ;AACO,aAAM,eAAe,CAAC,SACzB,SAAS,IAAI;AACjB,aAAa,OAAO;AAAA,EAChB,UAAU;AACd;AACO,aAAM,eAAe,CAAC,SACzB,SAAS,IAAI;AACjB,aAAa,OAAO;AAAA,EAChB,UAAU;AACd;AACO,aAAM,iBAAiB,CAAC,SAC3B,SAAS,IAAI;AACjB,eAAe,OAAO;AAAA,EAClB,OAAO;AACX;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,18 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
|
|
7
|
-
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
import '@spectrum-web-components/swatch/sp-swatch.js';
|
|
13
|
-
import { html } from '@spectrum-web-components/base';
|
|
14
|
-
import { measureFixtureCreation } from '../../../../test/benchmark/helpers.js';
|
|
15
|
-
measureFixtureCreation(html `
|
|
1
|
+
import "@spectrum-web-components/swatch/sp-swatch.js";
|
|
2
|
+
import { html } from "@spectrum-web-components/base";
|
|
3
|
+
import { measureFixtureCreation } from "../../../../test/benchmark/helpers.js";
|
|
4
|
+
measureFixtureCreation(html`
|
|
16
5
|
<sp-swatch></sp-swatch>
|
|
17
6
|
`);
|
|
18
|
-
//# sourceMappingURL=basic-test.js.map
|
|
7
|
+
//# sourceMappingURL=basic-test.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["basic-test.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport '@spectrum-web-components/swatch/sp-swatch.js';\nimport { html } from '@spectrum-web-components/base';\nimport { measureFixtureCreation } from '../../../../test/benchmark/helpers.js';\n\nmeasureFixtureCreation(html`\n <sp-swatch></sp-swatch>\n`);\n"],
|
|
5
|
+
"mappings": "AAWA;AACA;AACA;AAEA,uBAAuB;AAAA;AAAA,CAEtB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
|
|
7
|
-
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
import * as stories from '../stories/swatch-group.stories.js';
|
|
13
|
-
import { regressVisuals } from '../../../test/visual/test.js';
|
|
14
|
-
regressVisuals('SwatchGroupStories', stories);
|
|
15
|
-
//# sourceMappingURL=swatch-group.test-vrt.js.map
|
|
1
|
+
import * as stories from "../stories/swatch-group.stories.js";
|
|
2
|
+
import { regressVisuals } from "../../../test/visual/test.js";
|
|
3
|
+
regressVisuals("SwatchGroupStories", stories);
|
|
4
|
+
//# sourceMappingURL=swatch-group.test-vrt.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["swatch-group.test-vrt.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport * as stories from '../stories/swatch-group.stories.js';\nimport { regressVisuals } from '../../../test/visual/test.js';\n\nregressVisuals('SwatchGroupStories', stories);\n"],
|
|
5
|
+
"mappings": "AAYA;AACA;AAEA,eAAe,sBAAsB,OAAO;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,225 +1,214 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
it('focus()es to the first selected Swatch', async () => {
|
|
209
|
-
const selectedChild = el.querySelector(':scope > sp-swatch:nth-child(4)');
|
|
210
|
-
expect(selectedChild.selected).to.be.false;
|
|
211
|
-
el.selects = 'single';
|
|
212
|
-
el.selected = [selectedChild.value];
|
|
213
|
-
await elementUpdated(el);
|
|
214
|
-
await nextFrame();
|
|
215
|
-
expect(selectedChild.selected).to.be.true;
|
|
216
|
-
el.focus();
|
|
217
|
-
expect(document.activeElement === selectedChild).to.be.true;
|
|
218
|
-
});
|
|
1
|
+
import { elementUpdated, expect, fixture, nextFrame } from "@open-wc/testing";
|
|
2
|
+
import { sendKeys } from "@web/test-runner-commands";
|
|
3
|
+
import "../sp-swatch.js";
|
|
4
|
+
import { Default } from "../stories/swatch-group.stories.js";
|
|
5
|
+
import { spy } from "sinon";
|
|
6
|
+
import { html } from "@spectrum-web-components/base";
|
|
7
|
+
describe("Swatch Group", () => {
|
|
8
|
+
let el;
|
|
9
|
+
beforeEach(async () => {
|
|
10
|
+
el = await fixture(Default(Default.args));
|
|
11
|
+
await elementUpdated(el);
|
|
12
|
+
});
|
|
13
|
+
it("loads default swatch accessibly", async () => {
|
|
14
|
+
await expect(el).to.be.accessible();
|
|
15
|
+
});
|
|
16
|
+
it("forwards `border` to children", async () => {
|
|
17
|
+
el.border = "light";
|
|
18
|
+
await elementUpdated(el);
|
|
19
|
+
[...el.children].forEach((child) => {
|
|
20
|
+
expect(child.border).to.equal("light");
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
it("forwards `rounding` to children", async () => {
|
|
24
|
+
el.rounding = "full";
|
|
25
|
+
await elementUpdated(el);
|
|
26
|
+
[...el.children].forEach((child) => {
|
|
27
|
+
expect(child.rounding).to.equal("full");
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
it("forwards `size` to children", async () => {
|
|
31
|
+
el.size = "xs";
|
|
32
|
+
await elementUpdated(el);
|
|
33
|
+
[...el.children].forEach((child) => {
|
|
34
|
+
expect(child.size).to.equal("xs");
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
it("forwards `shape` to children", async () => {
|
|
38
|
+
el.shape = "rectangle";
|
|
39
|
+
await elementUpdated(el);
|
|
40
|
+
[...el.children].forEach((child) => {
|
|
41
|
+
expect(child.shape).to.equal("rectangle");
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
it("unsets forwarding", async () => {
|
|
45
|
+
el.border = "light";
|
|
46
|
+
el.rounding = "full";
|
|
47
|
+
el.size = "xs";
|
|
48
|
+
el.shape = "rectangle";
|
|
49
|
+
await elementUpdated(el);
|
|
50
|
+
[...el.children].forEach((child) => {
|
|
51
|
+
expect(child.border).to.not.be.undefined;
|
|
52
|
+
expect(child.rounding).to.not.be.undefined;
|
|
53
|
+
expect(child.size).to.not.equal("m");
|
|
54
|
+
expect(child.shape).to.not.be.undefined;
|
|
55
|
+
});
|
|
56
|
+
el.border = void 0;
|
|
57
|
+
el.rounding = void 0;
|
|
58
|
+
el.removeAttribute("size");
|
|
59
|
+
el.shape = void 0;
|
|
60
|
+
await elementUpdated(el);
|
|
61
|
+
[...el.children].forEach((child) => {
|
|
62
|
+
expect(child.border).to.equal(void 0);
|
|
63
|
+
expect(child.rounding).to.equal(void 0);
|
|
64
|
+
expect(child.size).to.equal("m");
|
|
65
|
+
expect(child.shape).to.equal(void 0);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
it("does not dispatch `change` events without `selects` attribute", async () => {
|
|
69
|
+
const selectedChild = el.querySelector(":scope > sp-swatch:nth-child(4)");
|
|
70
|
+
const changeSpy = spy();
|
|
71
|
+
el.addEventListener("change", () => changeSpy());
|
|
72
|
+
expect(el.selected).to.deep.equal([]);
|
|
73
|
+
selectedChild.click();
|
|
74
|
+
expect(changeSpy.called).to.be.false;
|
|
75
|
+
expect(el.selected).to.deep.equal([]);
|
|
76
|
+
});
|
|
77
|
+
it('dispatches `change` events as [selects="single"]', async () => {
|
|
78
|
+
el.selects = "single";
|
|
79
|
+
const selectedChild = el.querySelector(":scope > sp-swatch:nth-child(4)");
|
|
80
|
+
const changeSpy = spy();
|
|
81
|
+
el.addEventListener("change", () => changeSpy());
|
|
82
|
+
expect(el.selected).to.deep.equal([]);
|
|
83
|
+
expect(selectedChild.selected).to.be.false;
|
|
84
|
+
selectedChild.click();
|
|
85
|
+
expect(changeSpy.calledOnce).to.be.true;
|
|
86
|
+
expect(el.selected).to.deep.equal([selectedChild.value]);
|
|
87
|
+
expect(selectedChild.selected).to.be.true;
|
|
88
|
+
});
|
|
89
|
+
it("can have `change` events prevented", async () => {
|
|
90
|
+
el.selects = "single";
|
|
91
|
+
const selectedChild = el.querySelector(":scope > sp-swatch:nth-child(4)");
|
|
92
|
+
el.addEventListener("change", (event) => event.preventDefault());
|
|
93
|
+
expect(el.selected).to.deep.equal([]);
|
|
94
|
+
expect(selectedChild.selected).to.be.false;
|
|
95
|
+
selectedChild.click();
|
|
96
|
+
expect(el.selected).to.deep.equal([]);
|
|
97
|
+
expect(selectedChild.selected).to.be.false;
|
|
98
|
+
});
|
|
99
|
+
it('dispatches `change` events as [selects="multiple"]', async () => {
|
|
100
|
+
el.selects = "multiple";
|
|
101
|
+
const selectedChild0 = el.querySelector(":scope > sp-swatch:nth-child(1)");
|
|
102
|
+
const selectedChild1 = el.querySelector(":scope > sp-swatch:nth-child(4)");
|
|
103
|
+
const selectedChild2 = el.querySelector(":scope > sp-swatch:nth-child(6)");
|
|
104
|
+
await elementUpdated(selectedChild0);
|
|
105
|
+
const changeSpy = spy();
|
|
106
|
+
el.addEventListener("change", () => changeSpy());
|
|
107
|
+
expect(el.selected).to.deep.equal([]);
|
|
108
|
+
selectedChild0.click();
|
|
109
|
+
selectedChild1.click();
|
|
110
|
+
selectedChild2.click();
|
|
111
|
+
expect(changeSpy.callCount).to.equal(3);
|
|
112
|
+
expect(el.selected).to.deep.equal([
|
|
113
|
+
selectedChild0.value,
|
|
114
|
+
selectedChild1.value,
|
|
115
|
+
selectedChild2.value
|
|
116
|
+
]);
|
|
117
|
+
});
|
|
118
|
+
it("filters `selected` when a selected Swatch is removed from the DOM", async () => {
|
|
119
|
+
el.selects = "multiple";
|
|
120
|
+
const selectedChild0 = el.querySelector(":scope > sp-swatch:nth-child(1)");
|
|
121
|
+
const selectedChild1 = el.querySelector(":scope > sp-swatch:nth-child(4)");
|
|
122
|
+
const selectedChild2 = el.querySelector(":scope > sp-swatch:nth-child(6)");
|
|
123
|
+
await elementUpdated(selectedChild0);
|
|
124
|
+
expect(el.selected).to.deep.equal([]);
|
|
125
|
+
selectedChild0.click();
|
|
126
|
+
selectedChild1.click();
|
|
127
|
+
selectedChild2.click();
|
|
128
|
+
expect(el.selected).to.deep.equal([
|
|
129
|
+
selectedChild0.value,
|
|
130
|
+
selectedChild1.value,
|
|
131
|
+
selectedChild2.value
|
|
132
|
+
]);
|
|
133
|
+
selectedChild0.remove();
|
|
134
|
+
await elementUpdated(el);
|
|
135
|
+
expect(el.selected).to.deep.equal([
|
|
136
|
+
selectedChild1.value,
|
|
137
|
+
selectedChild2.value
|
|
138
|
+
]);
|
|
139
|
+
selectedChild2.remove();
|
|
140
|
+
await elementUpdated(el);
|
|
141
|
+
expect(el.selected).to.deep.equal([selectedChild1.value]);
|
|
142
|
+
selectedChild1.remove();
|
|
143
|
+
await elementUpdated(el);
|
|
144
|
+
expect(el.selected).to.deep.equal([]);
|
|
145
|
+
});
|
|
146
|
+
it("maintains a single tab stop", async () => {
|
|
147
|
+
const inputBefore = document.createElement("input");
|
|
148
|
+
const inputAfter = document.createElement("input");
|
|
149
|
+
el.insertAdjacentElement("beforebegin", inputBefore);
|
|
150
|
+
el.insertAdjacentElement("afterend", inputAfter);
|
|
151
|
+
inputBefore.focus();
|
|
152
|
+
expect(document.activeElement === el.children[0]).to.be.false;
|
|
153
|
+
await sendKeys({
|
|
154
|
+
press: "Tab"
|
|
155
|
+
});
|
|
156
|
+
expect(document.activeElement === el.children[0]).to.be.true;
|
|
157
|
+
await sendKeys({
|
|
158
|
+
press: "Tab"
|
|
159
|
+
});
|
|
160
|
+
expect(document.activeElement === el.children[0]).to.be.false;
|
|
161
|
+
await sendKeys({
|
|
162
|
+
press: "Shift+Tab"
|
|
163
|
+
});
|
|
164
|
+
expect(document.activeElement === el.children[0]).to.be.true;
|
|
165
|
+
});
|
|
166
|
+
it("makes the first selected child the single tab stop", async () => {
|
|
167
|
+
const selectedChild = el.querySelector(":scope > sp-swatch:nth-child(4)");
|
|
168
|
+
expect(selectedChild.selected).to.be.false;
|
|
169
|
+
const inputBefore = document.createElement("input");
|
|
170
|
+
const inputAfter = document.createElement("input");
|
|
171
|
+
el.insertAdjacentElement("beforebegin", inputBefore);
|
|
172
|
+
el.insertAdjacentElement("afterend", inputAfter);
|
|
173
|
+
inputBefore.focus();
|
|
174
|
+
el.selects = "single";
|
|
175
|
+
el.selected = [selectedChild.value];
|
|
176
|
+
await elementUpdated(el);
|
|
177
|
+
await nextFrame();
|
|
178
|
+
expect(selectedChild.selected).to.be.true;
|
|
179
|
+
expect(document.activeElement === selectedChild).to.be.false;
|
|
180
|
+
await sendKeys({
|
|
181
|
+
press: "Tab"
|
|
182
|
+
});
|
|
183
|
+
expect(document.activeElement === selectedChild).to.be.true;
|
|
184
|
+
await sendKeys({
|
|
185
|
+
press: "Tab"
|
|
186
|
+
});
|
|
187
|
+
expect(document.activeElement === selectedChild).to.be.false;
|
|
188
|
+
await sendKeys({
|
|
189
|
+
press: "Shift+Tab"
|
|
190
|
+
});
|
|
191
|
+
expect(document.activeElement === selectedChild).to.be.true;
|
|
192
|
+
});
|
|
193
|
+
it("focus()es to the first Swatch", async () => {
|
|
194
|
+
el.focus();
|
|
195
|
+
expect(document.activeElement === el.children[0]).to.be.true;
|
|
196
|
+
});
|
|
197
|
+
it("focus()es to the first selected Swatch", async () => {
|
|
198
|
+
const selectedChild = el.querySelector(":scope > sp-swatch:nth-child(4)");
|
|
199
|
+
expect(selectedChild.selected).to.be.false;
|
|
200
|
+
el.selects = "single";
|
|
201
|
+
el.selected = [selectedChild.value];
|
|
202
|
+
await elementUpdated(el);
|
|
203
|
+
await nextFrame();
|
|
204
|
+
expect(selectedChild.selected).to.be.true;
|
|
205
|
+
el.focus();
|
|
206
|
+
expect(document.activeElement === selectedChild).to.be.true;
|
|
207
|
+
});
|
|
219
208
|
});
|
|
220
|
-
describe(
|
|
221
|
-
|
|
222
|
-
|
|
209
|
+
describe("Swatch Group - DOM selected", () => {
|
|
210
|
+
it("accepts selection from DOM", async () => {
|
|
211
|
+
const el = await fixture(html`
|
|
223
212
|
<sp-swatch-group selects="multiple">
|
|
224
213
|
<sp-swatch value="color-0" color="red"></sp-swatch>
|
|
225
214
|
<sp-swatch value="color-1" color="green" selected></sp-swatch>
|
|
@@ -227,23 +216,23 @@ describe('Swatch Group - DOM selected', () => {
|
|
|
227
216
|
<sp-swatch value="color-3" color="yellow" selected></sp-swatch>
|
|
228
217
|
</sp-swatch-group>
|
|
229
218
|
`);
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
<sp-swatch-group selects="multiple" .selected=${[
|
|
219
|
+
await elementUpdated(el);
|
|
220
|
+
expect(el.selected).to.deep.equal(["color-1", "color-3"]);
|
|
221
|
+
});
|
|
222
|
+
it("merges `selected` and selection from DOM", async () => {
|
|
223
|
+
const el = await fixture(html`
|
|
224
|
+
<sp-swatch-group selects="multiple" .selected=${["color-1"]}>
|
|
236
225
|
<sp-swatch value="color-0" color="red"></sp-swatch>
|
|
237
226
|
<sp-swatch value="color-1" color="green"></sp-swatch>
|
|
238
227
|
<sp-swatch value="color-2" color="blue"></sp-swatch>
|
|
239
228
|
<sp-swatch value="color-3" color="yellow" selected></sp-swatch>
|
|
240
229
|
</sp-swatch-group>
|
|
241
230
|
`);
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
231
|
+
await elementUpdated(el);
|
|
232
|
+
expect(el.selected).to.deep.equal(["color-1", "color-3"]);
|
|
233
|
+
});
|
|
234
|
+
it("lazily accepts selection from DOM", async () => {
|
|
235
|
+
const el = await fixture(html`
|
|
247
236
|
<sp-swatch-group selects="multiple">
|
|
248
237
|
<sp-swatch value="color-0" color="red"></sp-swatch>
|
|
249
238
|
<sp-swatch value="color-1" color="green"></sp-swatch>
|
|
@@ -251,12 +240,12 @@ describe('Swatch Group - DOM selected', () => {
|
|
|
251
240
|
<sp-swatch value="color-3" color="yellow" selected></sp-swatch>
|
|
252
241
|
</sp-swatch-group>
|
|
253
242
|
`);
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
243
|
+
await elementUpdated(el);
|
|
244
|
+
const color1 = el.querySelector('[value="color-1"]');
|
|
245
|
+
expect(el.selected).to.deep.equal(["color-3"]);
|
|
246
|
+
color1.selected = true;
|
|
247
|
+
await elementUpdated(el);
|
|
248
|
+
expect(el.selected).to.deep.equal(["color-3", "color-1"]);
|
|
249
|
+
});
|
|
261
250
|
});
|
|
262
|
-
//# sourceMappingURL=swatch-group.test.js.map
|
|
251
|
+
//# sourceMappingURL=swatch-group.test.js.map
|