@spectrum-web-components/textfield 0.11.10 → 0.12.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.
@@ -1,106 +1,105 @@
1
- import { __asyncValues } from "tslib";
2
- import { elementUpdated, expect, html, litFixture } from '@open-wc/testing';
3
- import { sendKeys } from '@web/test-runner-commands';
4
- import { sendMouse } from '../../../test/plugins/browser.js';
5
- import { findDescribedNode } from '../../../test/testing-helpers-a11y.js';
6
- import '@spectrum-web-components/help-text/sp-help-text.js';
7
- import '../sp-textfield.js';
8
- describe('Textfield', () => {
9
- it('loads default textfield accessibly', async () => {
10
- const el = await litFixture(html `
1
+ import { elementUpdated, expect, html, litFixture } from "@open-wc/testing";
2
+ import { sendKeys } from "@web/test-runner-commands";
3
+ import { sendMouse } from "../../../test/plugins/browser.js";
4
+ import { findDescribedNode } from "../../../test/testing-helpers-a11y.js";
5
+ import "@spectrum-web-components/help-text/sp-help-text.js";
6
+ import "@spectrum-web-components/textfield/sp-textfield.js";
7
+ import { testForLitDevWarnings } from "../../../test/testing-helpers.js";
8
+ describe("Textfield", () => {
9
+ testForLitDevWarnings(async () => await litFixture(html`
10
+ <sp-textfield label="Enter Your Name"></sp-textfield>
11
+ `));
12
+ it("loads default textfield accessibly", async () => {
13
+ const el = await litFixture(html`
11
14
  <sp-textfield label="Enter Your Name"></sp-textfield>
12
15
  `);
13
- await elementUpdated(el);
14
- await expect(el).to.be.accessible();
15
- });
16
- it('loads multiline textfield accessibly', async () => {
17
- const el = await litFixture(html `
16
+ await elementUpdated(el);
17
+ await expect(el).to.be.accessible();
18
+ });
19
+ it("loads multiline textfield accessibly", async () => {
20
+ const el = await litFixture(html`
18
21
  <sp-textfield label="Enter your name" multiline></sp-textfield>
19
22
  `);
20
- await elementUpdated(el);
21
- await expect(el).to.be.accessible();
22
- });
23
- it('manages tabIndex while disabled', async () => {
24
- const el = await litFixture(html `
23
+ await elementUpdated(el);
24
+ await expect(el).to.be.accessible();
25
+ });
26
+ it("manages tabIndex while disabled", async () => {
27
+ const el = await litFixture(html`
25
28
  <sp-textfield placeholder="Enter Your Name"></sp-textfield>
26
29
  `);
27
- await elementUpdated(el);
28
- expect(el.tabIndex).to.equal(0);
29
- el.disabled = true;
30
- await elementUpdated(el);
31
- expect(el.tabIndex).to.equal(-1);
32
- el.tabIndex = 2;
33
- await elementUpdated(el);
34
- expect(el.tabIndex).to.equal(-1);
35
- el.disabled = false;
36
- await elementUpdated(el);
37
- expect(el.tabIndex).to.equal(2);
38
- });
39
- it('manages tabIndex before first render', async () => {
40
- const el = document.createElement('sp-textfield');
41
- expect(el.focusElement).to.be.null;
42
- expect(el.tabIndex).to.equal(0);
43
- el.remove();
44
- });
45
- it('loads', async () => {
46
- const testPlaceholder = 'Enter your name';
47
- const el = await litFixture(html `
30
+ await elementUpdated(el);
31
+ expect(el.tabIndex).to.equal(0);
32
+ el.disabled = true;
33
+ await elementUpdated(el);
34
+ expect(el.tabIndex).to.equal(-1);
35
+ el.tabIndex = 2;
36
+ await elementUpdated(el);
37
+ expect(el.tabIndex).to.equal(-1);
38
+ el.disabled = false;
39
+ await elementUpdated(el);
40
+ expect(el.tabIndex).to.equal(2);
41
+ });
42
+ it("manages tabIndex before first render", async () => {
43
+ const el = document.createElement("sp-textfield");
44
+ expect(el.focusElement).to.be.null;
45
+ expect(el.tabIndex).to.equal(0);
46
+ el.remove();
47
+ });
48
+ it("loads", async () => {
49
+ const testPlaceholder = "Enter your name";
50
+ const el = await litFixture(html`
48
51
  <sp-textfield placeholder=${testPlaceholder}></sp-textfield>
49
52
  `);
50
- expect(el).to.not.equal(undefined);
51
- const input = el.shadowRoot
52
- ? el.shadowRoot.querySelector('input')
53
- : null;
54
- expect(input).to.not.be.null;
55
- const placeholder = input ? input.placeholder : null;
56
- expect(placeholder).to.equal(testPlaceholder);
57
- });
58
- it('multiline', async () => {
59
- const el = await litFixture(html `
53
+ expect(el).to.not.equal(void 0);
54
+ const input = el.shadowRoot ? el.shadowRoot.querySelector("input") : null;
55
+ expect(input).to.not.be.null;
56
+ const placeholder = input ? input.placeholder : null;
57
+ expect(placeholder).to.equal(testPlaceholder);
58
+ });
59
+ it("multiline", async () => {
60
+ const el = await litFixture(html`
60
61
  <sp-textfield
61
62
  placeholder="Enter your name"
62
63
  multiline
63
64
  ></sp-textfield>
64
65
  `);
65
- expect(el).to.not.equal(undefined);
66
- const input = el.shadowRoot
67
- ? el.shadowRoot.querySelector('textarea')
68
- : null;
69
- expect(input).to.not.be.null;
70
- });
71
- it('resizes by default', async () => {
72
- const el = await litFixture(html `
66
+ expect(el).to.not.equal(void 0);
67
+ const input = el.shadowRoot ? el.shadowRoot.querySelector("textarea") : null;
68
+ expect(input).to.not.be.null;
69
+ });
70
+ it("resizes by default", async () => {
71
+ const el = await litFixture(html`
73
72
  <sp-textfield
74
73
  multiline
75
74
  label="No resize control"
76
75
  placeholder="No resize control"
77
76
  ></sp-textfield>
78
77
  `);
79
- const startBounds = el.getBoundingClientRect();
80
- await sendMouse({
81
- steps: [
82
- {
83
- type: 'move',
84
- position: [startBounds.right - 2, startBounds.bottom - 2],
85
- },
86
- {
87
- type: 'down',
88
- },
89
- {
90
- type: 'move',
91
- position: [startBounds.right + 50, startBounds.bottom + 50],
92
- },
93
- {
94
- type: 'up',
95
- },
96
- ],
97
- });
98
- const endBounds = el.getBoundingClientRect();
99
- expect(endBounds.width).to.be.greaterThan(startBounds.width);
100
- expect(endBounds.height).to.be.greaterThan(startBounds.height);
101
- });
102
- it('accepts resize styling', async () => {
103
- const el = await litFixture(html `
78
+ const startBounds = el.getBoundingClientRect();
79
+ await sendMouse({
80
+ steps: [
81
+ {
82
+ type: "move",
83
+ position: [startBounds.right - 2, startBounds.bottom - 2]
84
+ },
85
+ {
86
+ type: "down"
87
+ },
88
+ {
89
+ type: "move",
90
+ position: [startBounds.right + 50, startBounds.bottom + 50]
91
+ },
92
+ {
93
+ type: "up"
94
+ }
95
+ ]
96
+ });
97
+ const endBounds = el.getBoundingClientRect();
98
+ expect(endBounds.width).to.be.greaterThan(startBounds.width);
99
+ expect(endBounds.height).to.be.greaterThan(startBounds.height);
100
+ });
101
+ it("accepts resize styling", async () => {
102
+ const el = await litFixture(html`
104
103
  <sp-textfield
105
104
  multiline
106
105
  style="resize: none;"
@@ -108,45 +107,43 @@ describe('Textfield', () => {
108
107
  placeholder="No resize control"
109
108
  ></sp-textfield>
110
109
  `);
111
- const startBounds = el.getBoundingClientRect();
112
- await sendMouse({
113
- steps: [
114
- {
115
- type: 'move',
116
- position: [startBounds.right - 2, startBounds.bottom - 2],
117
- },
118
- {
119
- type: 'down',
120
- },
121
- {
122
- type: 'move',
123
- position: [startBounds.right + 50, startBounds.bottom + 50],
124
- },
125
- {
126
- type: 'up',
127
- },
128
- ],
129
- });
130
- const endBounds = el.getBoundingClientRect();
131
- expect(endBounds.width).equals(startBounds.width);
132
- expect(endBounds.height).equals(startBounds.height);
133
- });
134
- it('grows', async () => {
135
- const el = await litFixture(html `
110
+ const startBounds = el.getBoundingClientRect();
111
+ await sendMouse({
112
+ steps: [
113
+ {
114
+ type: "move",
115
+ position: [startBounds.right - 2, startBounds.bottom - 2]
116
+ },
117
+ {
118
+ type: "down"
119
+ },
120
+ {
121
+ type: "move",
122
+ position: [startBounds.right + 50, startBounds.bottom + 50]
123
+ },
124
+ {
125
+ type: "up"
126
+ }
127
+ ]
128
+ });
129
+ const endBounds = el.getBoundingClientRect();
130
+ expect(endBounds.width).equals(startBounds.width);
131
+ expect(endBounds.height).equals(startBounds.height);
132
+ });
133
+ it("grows", async () => {
134
+ const el = await litFixture(html`
136
135
  <sp-textfield
137
136
  placeholder="Enter your name"
138
137
  multiline
139
138
  grows
140
139
  ></sp-textfield>
141
140
  `);
142
- expect(el).to.not.equal(undefined);
143
- const sizer = el.shadowRoot
144
- ? el.shadowRoot.querySelector('#sizer')
145
- : null;
146
- expect(sizer).to.not.be.null;
147
- });
148
- it('valid', async () => {
149
- const el = await litFixture(html `
141
+ expect(el).to.not.equal(void 0);
142
+ const sizer = el.shadowRoot ? el.shadowRoot.querySelector("#sizer") : null;
143
+ expect(sizer).to.not.be.null;
144
+ });
145
+ it("valid", async () => {
146
+ const el = await litFixture(html`
150
147
  <sp-textfield
151
148
  placeholder="Enter your number"
152
149
  pattern="[\\d]+"
@@ -154,15 +151,13 @@ describe('Textfield', () => {
154
151
  required
155
152
  ></sp-textfield>
156
153
  `);
157
- await elementUpdated(el);
158
- expect(el).to.not.equal(undefined);
159
- const input = el.shadowRoot
160
- ? el.shadowRoot.querySelector('#valid')
161
- : null;
162
- expect(input).to.not.be.null;
163
- });
164
- it('valid - multiline', async () => {
165
- const el = await litFixture(html `
154
+ await elementUpdated(el);
155
+ expect(el).to.not.equal(void 0);
156
+ const input = el.shadowRoot ? el.shadowRoot.querySelector("#valid") : null;
157
+ expect(input).to.not.be.null;
158
+ });
159
+ it("valid - multiline", async () => {
160
+ const el = await litFixture(html`
166
161
  <sp-textfield
167
162
  placeholder="Enter your number"
168
163
  pattern="[\\d]+"
@@ -171,30 +166,26 @@ describe('Textfield', () => {
171
166
  multiline
172
167
  ></sp-textfield>
173
168
  `);
174
- await elementUpdated(el);
175
- expect(el).to.not.equal(undefined);
176
- const input = el.shadowRoot
177
- ? el.shadowRoot.querySelector('#valid')
178
- : null;
179
- expect(input).to.not.be.null;
180
- });
181
- it('valid - required', async () => {
182
- const el = await litFixture(html `
169
+ await elementUpdated(el);
170
+ expect(el).to.not.equal(void 0);
171
+ const input = el.shadowRoot ? el.shadowRoot.querySelector("#valid") : null;
172
+ expect(input).to.not.be.null;
173
+ });
174
+ it("valid - required", async () => {
175
+ const el = await litFixture(html`
183
176
  <sp-textfield
184
177
  placeholder="Enter your number"
185
178
  value="123"
186
179
  required
187
180
  ></sp-textfield>
188
181
  `);
189
- await elementUpdated(el);
190
- expect(el).to.not.equal(undefined);
191
- const input = el.shadowRoot
192
- ? el.shadowRoot.querySelector('#valid')
193
- : null;
194
- expect(input).to.not.be.null;
195
- });
196
- it('valid - multiline - required', async () => {
197
- const el = await litFixture(html `
182
+ await elementUpdated(el);
183
+ expect(el).to.not.equal(void 0);
184
+ const input = el.shadowRoot ? el.shadowRoot.querySelector("#valid") : null;
185
+ expect(input).to.not.be.null;
186
+ });
187
+ it("valid - multiline - required", async () => {
188
+ const el = await litFixture(html`
198
189
  <sp-textfield
199
190
  placeholder="Enter your number"
200
191
  value="123"
@@ -202,15 +193,13 @@ describe('Textfield', () => {
202
193
  multiline
203
194
  ></sp-textfield>
204
195
  `);
205
- await elementUpdated(el);
206
- expect(el).to.not.equal(undefined);
207
- const input = el.shadowRoot
208
- ? el.shadowRoot.querySelector('#valid')
209
- : null;
210
- expect(input).to.not.be.null;
211
- });
212
- it('valid - boundary-type assertions', async () => {
213
- const el = await litFixture(html `
196
+ await elementUpdated(el);
197
+ expect(el).to.not.equal(void 0);
198
+ const input = el.shadowRoot ? el.shadowRoot.querySelector("#valid") : null;
199
+ expect(input).to.not.be.null;
200
+ });
201
+ it("valid - boundary-type assertions", async () => {
202
+ const el = await litFixture(html`
214
203
  <sp-textfield
215
204
  placeholder="Enter your number"
216
205
  pattern="^[\\d]+$"
@@ -218,15 +207,13 @@ describe('Textfield', () => {
218
207
  required
219
208
  ></sp-textfield>
220
209
  `);
221
- await elementUpdated(el);
222
- expect(el).to.not.equal(undefined);
223
- const input = el.shadowRoot
224
- ? el.shadowRoot.querySelector('#valid')
225
- : null;
226
- expect(input).to.not.be.null;
227
- });
228
- it('valid - multiline - boundary-type assertions', async () => {
229
- const el = await litFixture(html `
210
+ await elementUpdated(el);
211
+ expect(el).to.not.equal(void 0);
212
+ const input = el.shadowRoot ? el.shadowRoot.querySelector("#valid") : null;
213
+ expect(input).to.not.be.null;
214
+ });
215
+ it("valid - multiline - boundary-type assertions", async () => {
216
+ const el = await litFixture(html`
230
217
  <sp-textfield
231
218
  placeholder="Enter your number"
232
219
  pattern="^[\\d]+$"
@@ -235,15 +222,13 @@ describe('Textfield', () => {
235
222
  multiline
236
223
  ></sp-textfield>
237
224
  `);
238
- await elementUpdated(el);
239
- expect(el).to.not.equal(undefined);
240
- const input = el.shadowRoot
241
- ? el.shadowRoot.querySelector('#valid')
242
- : null;
243
- expect(input).to.not.be.null;
244
- });
245
- it('valid - unicode', async () => {
246
- const el = await litFixture(html `
225
+ await elementUpdated(el);
226
+ expect(el).to.not.equal(void 0);
227
+ const input = el.shadowRoot ? el.shadowRoot.querySelector("#valid") : null;
228
+ expect(input).to.not.be.null;
229
+ });
230
+ it("valid - unicode", async () => {
231
+ const el = await litFixture(html`
247
232
  <sp-textfield
248
233
  placeholder="Enter your name"
249
234
  pattern="\\p{L}{4,8}"
@@ -251,15 +236,13 @@ describe('Textfield', () => {
251
236
  required
252
237
  ></sp-textfield>
253
238
  `);
254
- await elementUpdated(el);
255
- expect(el).to.not.equal(undefined);
256
- const input = el.shadowRoot
257
- ? el.shadowRoot.querySelector('#valid')
258
- : null;
259
- expect(input).to.not.be.null;
260
- });
261
- it('valid - multiline - unicode', async () => {
262
- const el = await litFixture(html `
239
+ await elementUpdated(el);
240
+ expect(el).to.not.equal(void 0);
241
+ const input = el.shadowRoot ? el.shadowRoot.querySelector("#valid") : null;
242
+ expect(input).to.not.be.null;
243
+ });
244
+ it("valid - multiline - unicode", async () => {
245
+ const el = await litFixture(html`
263
246
  <sp-textfield
264
247
  placeholder="Enter your name"
265
248
  pattern="\\p{L}{4,8}"
@@ -268,15 +251,13 @@ describe('Textfield', () => {
268
251
  multiline
269
252
  ></sp-textfield>
270
253
  `);
271
- await elementUpdated(el);
272
- expect(el).to.not.equal(undefined);
273
- const input = el.shadowRoot
274
- ? el.shadowRoot.querySelector('#valid')
275
- : null;
276
- expect(input).to.not.be.null;
277
- });
278
- it('invalid', async () => {
279
- const el = await litFixture(html `
254
+ await elementUpdated(el);
255
+ expect(el).to.not.equal(void 0);
256
+ const input = el.shadowRoot ? el.shadowRoot.querySelector("#valid") : null;
257
+ expect(input).to.not.be.null;
258
+ });
259
+ it("invalid", async () => {
260
+ const el = await litFixture(html`
280
261
  <sp-textfield
281
262
  placeholder="Enter your number"
282
263
  pattern="[\\d]+"
@@ -284,15 +265,13 @@ describe('Textfield', () => {
284
265
  required
285
266
  ></sp-textfield>
286
267
  `);
287
- await elementUpdated(el);
288
- expect(el).to.not.equal(undefined);
289
- const input = el.shadowRoot
290
- ? el.shadowRoot.querySelector('#invalid')
291
- : null;
292
- expect(input).to.not.be.null;
293
- });
294
- it('invalid - multiline', async () => {
295
- const el = await litFixture(html `
268
+ await elementUpdated(el);
269
+ expect(el).to.not.equal(void 0);
270
+ const input = el.shadowRoot ? el.shadowRoot.querySelector("#invalid") : null;
271
+ expect(input).to.not.be.null;
272
+ });
273
+ it("invalid - multiline", async () => {
274
+ const el = await litFixture(html`
296
275
  <sp-textfield
297
276
  placeholder="Enter your number"
298
277
  pattern="[\\d]+"
@@ -301,30 +280,26 @@ describe('Textfield', () => {
301
280
  multiline
302
281
  ></sp-textfield>
303
282
  `);
304
- await elementUpdated(el);
305
- expect(el).to.not.equal(undefined);
306
- const input = el.shadowRoot
307
- ? el.shadowRoot.querySelector('#invalid')
308
- : null;
309
- expect(input).to.not.be.null;
310
- });
311
- it('invalid - required', async () => {
312
- const el = await litFixture(html `
283
+ await elementUpdated(el);
284
+ expect(el).to.not.equal(void 0);
285
+ const input = el.shadowRoot ? el.shadowRoot.querySelector("#invalid") : null;
286
+ expect(input).to.not.be.null;
287
+ });
288
+ it("invalid - required", async () => {
289
+ const el = await litFixture(html`
313
290
  <sp-textfield
314
291
  placeholder="Enter your number"
315
292
  value=""
316
293
  required
317
294
  ></sp-textfield>
318
295
  `);
319
- await elementUpdated(el);
320
- expect(el).to.not.equal(undefined);
321
- const input = el.shadowRoot
322
- ? el.shadowRoot.querySelector('#invalid')
323
- : null;
324
- expect(input).to.not.be.null;
325
- });
326
- it('invalid - multiline - required', async () => {
327
- const el = await litFixture(html `
296
+ await elementUpdated(el);
297
+ expect(el).to.not.equal(void 0);
298
+ const input = el.shadowRoot ? el.shadowRoot.querySelector("#invalid") : null;
299
+ expect(input).to.not.be.null;
300
+ });
301
+ it("invalid - multiline - required", async () => {
302
+ const el = await litFixture(html`
328
303
  <sp-textfield
329
304
  placeholder="Enter your number"
330
305
  value=""
@@ -332,15 +307,13 @@ describe('Textfield', () => {
332
307
  multiline
333
308
  ></sp-textfield>
334
309
  `);
335
- await elementUpdated(el);
336
- expect(el).to.not.equal(undefined);
337
- const input = el.shadowRoot
338
- ? el.shadowRoot.querySelector('#invalid')
339
- : null;
340
- expect(input).to.not.be.null;
341
- });
342
- it('invalid - unicode', async () => {
343
- const el = await litFixture(html `
310
+ await elementUpdated(el);
311
+ expect(el).to.not.equal(void 0);
312
+ const input = el.shadowRoot ? el.shadowRoot.querySelector("#invalid") : null;
313
+ expect(input).to.not.be.null;
314
+ });
315
+ it("invalid - unicode", async () => {
316
+ const el = await litFixture(html`
344
317
  <sp-textfield
345
318
  placeholder="Enter your number"
346
319
  pattern="\\p{N}+"
@@ -348,15 +321,13 @@ describe('Textfield', () => {
348
321
  required
349
322
  ></sp-textfield>
350
323
  `);
351
- await elementUpdated(el);
352
- expect(el).to.not.equal(undefined);
353
- const input = el.shadowRoot
354
- ? el.shadowRoot.querySelector('#invalid')
355
- : null;
356
- expect(input).to.not.be.null;
357
- });
358
- it('invalid - multiline - unicode', async () => {
359
- const el = await litFixture(html `
324
+ await elementUpdated(el);
325
+ expect(el).to.not.equal(void 0);
326
+ const input = el.shadowRoot ? el.shadowRoot.querySelector("#invalid") : null;
327
+ expect(input).to.not.be.null;
328
+ });
329
+ it("invalid - multiline - unicode", async () => {
330
+ const el = await litFixture(html`
360
331
  <sp-textfield
361
332
  placeholder="Enter your number"
362
333
  pattern="\\p{N}+"
@@ -365,15 +336,13 @@ describe('Textfield', () => {
365
336
  multiline
366
337
  ></sp-textfield>
367
338
  `);
368
- await elementUpdated(el);
369
- expect(el).to.not.equal(undefined);
370
- const input = el.shadowRoot
371
- ? el.shadowRoot.querySelector('#invalid')
372
- : null;
373
- expect(input).to.not.be.null;
374
- });
375
- it('invalid - boundary-type assertions', async () => {
376
- const el = await litFixture(html `
339
+ await elementUpdated(el);
340
+ expect(el).to.not.equal(void 0);
341
+ const input = el.shadowRoot ? el.shadowRoot.querySelector("#invalid") : null;
342
+ expect(input).to.not.be.null;
343
+ });
344
+ it("invalid - boundary-type assertions", async () => {
345
+ const el = await litFixture(html`
377
346
  <sp-textfield
378
347
  placeholder="Enter your number"
379
348
  pattern="^\\p{N}+$"
@@ -381,15 +350,13 @@ describe('Textfield', () => {
381
350
  required
382
351
  ></sp-textfield>
383
352
  `);
384
- await elementUpdated(el);
385
- expect(el).to.not.equal(undefined);
386
- const input = el.shadowRoot
387
- ? el.shadowRoot.querySelector('#invalid')
388
- : null;
389
- expect(input).to.not.be.null;
390
- });
391
- it('invalid - multiline - boundary-type assertions', async () => {
392
- const el = await litFixture(html `
353
+ await elementUpdated(el);
354
+ expect(el).to.not.equal(void 0);
355
+ const input = el.shadowRoot ? el.shadowRoot.querySelector("#invalid") : null;
356
+ expect(input).to.not.be.null;
357
+ });
358
+ it("invalid - multiline - boundary-type assertions", async () => {
359
+ const el = await litFixture(html`
393
360
  <sp-textfield
394
361
  placeholder="Enter your number"
395
362
  pattern="^\\p{N}+$"
@@ -398,90 +365,88 @@ describe('Textfield', () => {
398
365
  multiline
399
366
  ></sp-textfield>
400
367
  `);
401
- await elementUpdated(el);
402
- expect(el).to.not.equal(undefined);
403
- const input = el.shadowRoot
404
- ? el.shadowRoot.querySelector('#invalid')
405
- : null;
406
- expect(input).to.not.be.null;
407
- });
408
- it('receives focus', async () => {
409
- let activeElement = null;
410
- const onFocusIn = (event) => {
411
- const path = event.composedPath();
412
- activeElement = path[0];
413
- };
414
- document.addEventListener('focusin', onFocusIn);
415
- const el = await litFixture(html `
368
+ await elementUpdated(el);
369
+ expect(el).to.not.equal(void 0);
370
+ const input = el.shadowRoot ? el.shadowRoot.querySelector("#invalid") : null;
371
+ expect(input).to.not.be.null;
372
+ });
373
+ it("receives focus", async () => {
374
+ let activeElement = null;
375
+ const onFocusIn = (event) => {
376
+ const path = event.composedPath();
377
+ activeElement = path[0];
378
+ };
379
+ document.addEventListener("focusin", onFocusIn);
380
+ const el = await litFixture(html`
416
381
  <sp-textfield placeholder="Enter your name"></sp-textfield>
417
382
  `);
418
- await elementUpdated(el);
419
- el.focus();
420
- await elementUpdated(el);
421
- expect(activeElement === el.focusElement).to.be.true;
422
- document.removeEventListener('focusin', onFocusIn);
423
- });
424
- it('does not receive focus when disabled', async () => {
425
- let activeElement = null;
426
- const onFocusIn = (event) => {
427
- const path = event.composedPath();
428
- activeElement = path[0];
429
- };
430
- document.addEventListener('focusin', onFocusIn);
431
- const el = await litFixture(html `
383
+ await elementUpdated(el);
384
+ el.focus();
385
+ await elementUpdated(el);
386
+ expect(activeElement === el.focusElement).to.be.true;
387
+ document.removeEventListener("focusin", onFocusIn);
388
+ });
389
+ it("does not receive focus when disabled", async () => {
390
+ let activeElement = null;
391
+ const onFocusIn = (event) => {
392
+ const path = event.composedPath();
393
+ activeElement = path[0];
394
+ };
395
+ document.addEventListener("focusin", onFocusIn);
396
+ const el = await litFixture(html`
432
397
  <sp-textfield
433
398
  disabled
434
399
  placeholder="Enter your name"
435
400
  ></sp-textfield>
436
401
  `);
437
- await elementUpdated(el);
438
- el.focus();
439
- await elementUpdated(el);
440
- expect(activeElement === el.focusElement).to.be.false;
441
- expect(document.activeElement === el).to.be.false;
442
- document.removeEventListener('focusin', onFocusIn);
443
- el.click();
444
- await elementUpdated(el);
445
- expect(activeElement === el.focusElement).to.be.false;
446
- expect(document.activeElement === el).to.be.false;
447
- document.removeEventListener('focusin', onFocusIn);
448
- });
449
- it('accepts input', async () => {
450
- const testValue = 'Test Name';
451
- const el = await litFixture(html `
402
+ await elementUpdated(el);
403
+ el.focus();
404
+ await elementUpdated(el);
405
+ expect(activeElement === el.focusElement).to.be.false;
406
+ expect(document.activeElement === el).to.be.false;
407
+ document.removeEventListener("focusin", onFocusIn);
408
+ el.click();
409
+ await elementUpdated(el);
410
+ expect(activeElement === el.focusElement).to.be.false;
411
+ expect(document.activeElement === el).to.be.false;
412
+ document.removeEventListener("focusin", onFocusIn);
413
+ });
414
+ it("accepts input", async () => {
415
+ const testValue = "Test Name";
416
+ const el = await litFixture(html`
452
417
  <sp-textfield placeholder="Enter your name"></sp-textfield>
453
418
  `);
454
- await elementUpdated(el);
455
- el.focusElement.value = testValue;
456
- el.focusElement.dispatchEvent(new Event('input'));
457
- expect(el.value).to.equal(testValue);
458
- });
459
- it('selects', async () => {
460
- const testValue = 'Test Name';
461
- const el = await litFixture(html `
419
+ await elementUpdated(el);
420
+ el.focusElement.value = testValue;
421
+ el.focusElement.dispatchEvent(new Event("input"));
422
+ expect(el.value).to.equal(testValue);
423
+ });
424
+ it("selects", async () => {
425
+ const testValue = "Test Name";
426
+ const el = await litFixture(html`
462
427
  <sp-textfield value=${testValue}></sp-textfield>
463
428
  `);
464
- await elementUpdated(el);
465
- expect(el.value).to.equal(testValue);
466
- el.focus();
467
- el.select();
468
- await sendKeys({ press: 'Backspace' });
469
- expect(el.value).to.equal('');
470
- });
471
- it('setSelectionRange', async () => {
472
- const testValue = 'Test Name';
473
- const el = await litFixture(html `
429
+ await elementUpdated(el);
430
+ expect(el.value).to.equal(testValue);
431
+ el.focus();
432
+ el.select();
433
+ await sendKeys({ press: "Backspace" });
434
+ expect(el.value).to.equal("");
435
+ });
436
+ it("setSelectionRange", async () => {
437
+ const testValue = "Test Name";
438
+ const el = await litFixture(html`
474
439
  <sp-textfield value=${testValue}></sp-textfield>
475
440
  `);
476
- await elementUpdated(el);
477
- expect(el.value).to.equal(testValue);
478
- el.focus();
479
- el.setSelectionRange(0, 'Test '.length);
480
- await sendKeys({ press: 'Backspace' });
481
- expect(el.value).to.equal('Name');
482
- });
483
- it('accepts maxlength', async () => {
484
- const el = await litFixture(html `
441
+ await elementUpdated(el);
442
+ expect(el.value).to.equal(testValue);
443
+ el.focus();
444
+ el.setSelectionRange(0, "Test ".length);
445
+ await sendKeys({ press: "Backspace" });
446
+ expect(el.value).to.equal("Name");
447
+ });
448
+ it("accepts maxlength", async () => {
449
+ const el = await litFixture(html`
485
450
  <sp-textfield
486
451
  placeholder="Enter your name"
487
452
  maxlength="3"
@@ -489,211 +454,194 @@ describe('Textfield', () => {
489
454
  required
490
455
  ></sp-textfield>
491
456
  `);
492
- await elementUpdated(el);
493
- el.focus();
494
- await sendKeys({
495
- type: 'a',
496
- });
497
- await elementUpdated(el);
498
- expect(el.value).to.equal('a');
499
- expect(el.checkValidity()).to.be.false;
500
- await sendKeys({
501
- type: 'b',
502
- });
503
- await elementUpdated(el);
504
- expect(el.value).to.equal('ab');
505
- expect(el.checkValidity());
506
- await sendKeys({
507
- type: 'c',
508
- });
509
- await elementUpdated(el);
510
- expect(el.value).to.equal('abc');
511
- expect(el.checkValidity());
512
- await sendKeys({
513
- type: 'd',
514
- });
515
- await elementUpdated(el);
516
- expect(el.value).to.equal('abc');
517
- expect(el.checkValidity());
518
- await sendKeys({
519
- press: 'Backspace',
520
- });
521
- await elementUpdated(el);
522
- expect(el.value).to.equal('ab');
523
- expect(el.checkValidity());
524
- await sendKeys({
525
- press: 'Backspace',
526
- });
527
- await elementUpdated(el);
528
- expect(el.value).to.equal('a');
529
- expect(el.checkValidity()).to.be.false;
530
- });
531
- it('dispatches a `change` event', async () => {
532
- const testValue = 'Test Name';
533
- let eventSource = null;
534
- const onChange = (event) => {
535
- eventSource = event.composedPath()[0];
536
- };
537
- const el = await litFixture(html `
457
+ await elementUpdated(el);
458
+ el.focus();
459
+ await sendKeys({
460
+ type: "a"
461
+ });
462
+ await elementUpdated(el);
463
+ expect(el.value).to.equal("a");
464
+ expect(el.checkValidity()).to.be.false;
465
+ await sendKeys({
466
+ type: "b"
467
+ });
468
+ await elementUpdated(el);
469
+ expect(el.value).to.equal("ab");
470
+ expect(el.checkValidity());
471
+ await sendKeys({
472
+ type: "c"
473
+ });
474
+ await elementUpdated(el);
475
+ expect(el.value).to.equal("abc");
476
+ expect(el.checkValidity());
477
+ await sendKeys({
478
+ type: "d"
479
+ });
480
+ await elementUpdated(el);
481
+ expect(el.value).to.equal("abc");
482
+ expect(el.checkValidity());
483
+ await sendKeys({
484
+ press: "Backspace"
485
+ });
486
+ await elementUpdated(el);
487
+ expect(el.value).to.equal("ab");
488
+ expect(el.checkValidity());
489
+ await sendKeys({
490
+ press: "Backspace"
491
+ });
492
+ await elementUpdated(el);
493
+ expect(el.value).to.equal("a");
494
+ expect(el.checkValidity()).to.be.false;
495
+ });
496
+ it("dispatches a `change` event", async () => {
497
+ const testValue = "Test Name";
498
+ let eventSource = null;
499
+ const onChange = (event) => {
500
+ eventSource = event.composedPath()[0];
501
+ };
502
+ const el = await litFixture(html`
538
503
  <sp-textfield
539
504
  placeholder="Enter your name"
540
505
  @change=${onChange}
541
506
  ></sp-textfield>
542
507
  `);
543
- await elementUpdated(el);
544
- el.focusElement.value = testValue;
545
- el.focusElement.dispatchEvent(new Event('input'));
546
- el.focusElement.dispatchEvent(new Event('change'));
547
- expect(el.value).to.equal(testValue);
548
- const testSource = eventSource;
549
- expect(testSource).to.equal(el);
550
- });
551
- it('passes through `autocomplete` attribute', async () => {
552
- let el = await litFixture(html `
508
+ await elementUpdated(el);
509
+ el.focusElement.value = testValue;
510
+ el.focusElement.dispatchEvent(new Event("input"));
511
+ el.focusElement.dispatchEvent(new Event("change"));
512
+ expect(el.value).to.equal(testValue);
513
+ const testSource = eventSource;
514
+ expect(testSource).to.equal(el);
515
+ });
516
+ it("passes through `autocomplete` attribute", async () => {
517
+ let el = await litFixture(html`
553
518
  <sp-textfield autocomplete="off"></sp-textfield>
554
519
  `);
555
- await elementUpdated(el);
556
- let input = el.shadowRoot ? el.shadowRoot.querySelector('input') : null;
557
- expect(input).to.exist;
558
- if (input) {
559
- expect(input.getAttribute('autocomplete')).to.equal('off');
560
- }
561
- el = await litFixture(html `
520
+ await elementUpdated(el);
521
+ let input = el.shadowRoot ? el.shadowRoot.querySelector("input") : null;
522
+ expect(input).to.exist;
523
+ if (input) {
524
+ expect(input.getAttribute("autocomplete")).to.equal("off");
525
+ }
526
+ el = await litFixture(html`
562
527
  <sp-textfield></sp-textfield>
563
528
  `);
564
- await elementUpdated(el);
565
- input = el.shadowRoot ? el.shadowRoot.querySelector('input') : null;
566
- expect(input).to.exist;
567
- if (input) {
568
- expect(input.getAttribute('autocomplete')).to.not.exist;
569
- }
570
- });
571
- it('tests on `required` changes', async () => {
572
- const el = await litFixture(html `
529
+ await elementUpdated(el);
530
+ input = el.shadowRoot ? el.shadowRoot.querySelector("input") : null;
531
+ expect(input).to.exist;
532
+ if (input) {
533
+ expect(input.getAttribute("autocomplete")).to.not.exist;
534
+ }
535
+ });
536
+ it("tests on `required` changes", async () => {
537
+ const el = await litFixture(html`
573
538
  <sp-textfield value=""></sp-textfield>
574
539
  `);
575
- await elementUpdated(el);
576
- expect(el.invalid).to.be.false;
577
- el.required = true;
578
- await elementUpdated(el);
579
- expect(el.invalid).to.be.true;
580
- });
581
- it('manages `allowed-keys`', async () => {
582
- const el = await litFixture(html `
540
+ await elementUpdated(el);
541
+ expect(el.invalid).to.be.false;
542
+ el.required = true;
543
+ await elementUpdated(el);
544
+ expect(el.invalid).to.be.true;
545
+ });
546
+ it("manages `allowed-keys`", async () => {
547
+ const el = await litFixture(html`
583
548
  <sp-textfield allowed-keys="asdf"></sp-textfield>
584
549
  `);
585
- await elementUpdated(el);
586
- expect(el.value).to.equal('');
587
- const inputElement = el.focusElement;
588
- el.focusElement.value = 'asdf';
589
- inputElement.dispatchEvent(new InputEvent('input'));
590
- await elementUpdated(el);
591
- expect(el.value).to.equal('asdf');
592
- inputElement.value = `asdff`;
593
- inputElement.setSelectionRange(1, 1);
594
- inputElement.dispatchEvent(new InputEvent('input'));
595
- await elementUpdated(el);
596
- expect(el.value).to.equal('asdff');
597
- expect(inputElement.selectionStart).to.equal(1);
598
- inputElement.value = `asdoff`;
599
- inputElement.setSelectionRange(4, 4);
600
- inputElement.dispatchEvent(new InputEvent('input'));
601
- await elementUpdated(el);
602
- expect(el.value).to.equal('asdff');
603
- expect(inputElement.selectionStart).to.equal(3);
604
- });
605
- describe('type attribute', () => {
606
- // references:
607
- // https://developer.mozilla.org/en-US/docs/Glossary/IDL#content_versus_idl_attributes
608
- // https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#reflecting-content-attributes-in-idl-attributes
609
- // https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#keywords-and-enumerated-attributes
610
- it('assigns valid attributes to the property', async () => {
611
- var e_1, _a;
612
- const types = [
613
- 'text',
614
- 'url',
615
- 'tel',
616
- 'email',
617
- 'password',
618
- ];
619
- try {
620
- for (var types_1 = __asyncValues(types), types_1_1; types_1_1 = await types_1.next(), !types_1_1.done;) {
621
- const t = types_1_1.value;
622
- const el = await litFixture(html `
550
+ await elementUpdated(el);
551
+ expect(el.value).to.equal("");
552
+ const inputElement = el.focusElement;
553
+ el.focusElement.value = "asdf";
554
+ inputElement.dispatchEvent(new InputEvent("input"));
555
+ await elementUpdated(el);
556
+ expect(el.value).to.equal("asdf");
557
+ inputElement.value = `asdff`;
558
+ inputElement.setSelectionRange(1, 1);
559
+ inputElement.dispatchEvent(new InputEvent("input"));
560
+ await elementUpdated(el);
561
+ expect(el.value).to.equal("asdff");
562
+ expect(inputElement.selectionStart).to.equal(1);
563
+ inputElement.value = `asdoff`;
564
+ inputElement.setSelectionRange(4, 4);
565
+ inputElement.dispatchEvent(new InputEvent("input"));
566
+ await elementUpdated(el);
567
+ expect(el.value).to.equal("asdff");
568
+ expect(inputElement.selectionStart).to.equal(3);
569
+ });
570
+ describe("type attribute", () => {
571
+ it("assigns valid attributes to the property", async () => {
572
+ const types = [
573
+ "text",
574
+ "url",
575
+ "tel",
576
+ "email",
577
+ "password"
578
+ ];
579
+ for await (const t of types) {
580
+ const el = await litFixture(html`
623
581
  <sp-textfield type=${t}></sp-textfield>
624
582
  `);
625
- expect(el.type).equals(t);
626
- el.setAttribute('type', 'url');
627
- expect(el.type).equals('url');
628
- }
629
- }
630
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
631
- finally {
632
- try {
633
- if (types_1_1 && !types_1_1.done && (_a = types_1.return)) await _a.call(types_1);
634
- }
635
- finally { if (e_1) throw e_1.error; }
636
- }
637
- });
638
- it('represents invalid and missing attributes as "text"', async () => {
639
- const el1 = await litFixture(html `
583
+ expect(el.type).equals(t);
584
+ el.setAttribute("type", "url");
585
+ expect(el.type).equals("url");
586
+ }
587
+ });
588
+ it('represents invalid and missing attributes as "text"', async () => {
589
+ const el1 = await litFixture(html`
640
590
  <sp-textfield></sp-textfield>
641
591
  `);
642
- const el2 = await litFixture(html `
592
+ const el2 = await litFixture(html`
643
593
  <sp-textfield type="time"></sp-textfield>
644
594
  `);
645
- expect(el1.type).equals('text');
646
- expect(el2.type).equals('text');
647
- el1.setAttribute('type', 'submit');
648
- expect(el1.type).equals('text');
649
- });
650
- it('reflects valid property assignments', async () => {
651
- const el = await litFixture(html `
595
+ expect(el1.type).equals("text");
596
+ expect(el2.type).equals("text");
597
+ el1.setAttribute("type", "submit");
598
+ expect(el1.type).equals("text");
599
+ });
600
+ it("reflects valid property assignments", async () => {
601
+ const el = await litFixture(html`
652
602
  <sp-textfield type="url"></sp-textfield>
653
603
  `);
654
- el.type = 'email';
655
- await elementUpdated(el);
656
- expect(el.getAttribute('type')).equals('email');
657
- expect(el.type).equals('email');
658
- });
659
- it('reflects invalid assignments but sets state to "text"', async () => {
660
- const el = await litFixture(html `
604
+ el.type = "email";
605
+ await elementUpdated(el);
606
+ expect(el.getAttribute("type")).equals("email");
607
+ expect(el.type).equals("email");
608
+ });
609
+ it('reflects invalid assignments but sets state to "text"', async () => {
610
+ const el = await litFixture(html`
661
611
  <sp-textfield type="url"></sp-textfield>
662
612
  `);
663
- // eslint-disable-next-line
664
- // @ts-ignore
665
- el.type = 'range';
666
- await elementUpdated(el);
667
- expect(el.getAttribute('type')).equals('range');
668
- expect(el.type).equals('text');
669
- });
670
- });
671
- describe('help text', () => {
672
- const name = 'This is a textfield';
673
- const description = 'This text helps you fill it out';
674
- const descriptionNegative = 'This text helps you when invalid';
675
- it('accepts help text in `slot="help-text"`', async () => {
676
- const el = await litFixture(html `
613
+ el.type = "range";
614
+ await elementUpdated(el);
615
+ expect(el.getAttribute("type")).equals("range");
616
+ expect(el.type).equals("text");
617
+ });
618
+ });
619
+ describe("help text", () => {
620
+ const name = "This is a textfield";
621
+ const description = "This text helps you fill it out";
622
+ const descriptionNegative = "This text helps you when invalid";
623
+ it('accepts help text in `slot="help-text"`', async () => {
624
+ const el = await litFixture(html`
677
625
  <sp-textfield label=${name}>
678
626
  <sp-help-text slot="help-text">${description}</sp-help-text>
679
627
  </sp-textfield>
680
628
  `);
681
- await elementUpdated(el);
682
- await findDescribedNode(name, description);
683
- });
684
- it('accepts help text in `slot="help-text"` w/ own ID', async () => {
685
- const el = await litFixture(html `
629
+ await elementUpdated(el);
630
+ await findDescribedNode(name, description);
631
+ });
632
+ it('accepts help text in `slot="help-text"` w/ own ID', async () => {
633
+ const el = await litFixture(html`
686
634
  <sp-textfield label=${name}>
687
635
  <sp-help-text slot="help-text" id="help-text-id-1">
688
636
  ${description}
689
637
  </sp-help-text>
690
638
  </sp-textfield>
691
639
  `);
692
- await elementUpdated(el);
693
- await findDescribedNode(name, description);
694
- });
695
- it('manages neutral/negative help text pairs', async () => {
696
- const el = await litFixture(html `
640
+ await elementUpdated(el);
641
+ await findDescribedNode(name, description);
642
+ });
643
+ it("manages neutral/negative help text pairs", async () => {
644
+ const el = await litFixture(html`
697
645
  <sp-textfield label=${name}>
698
646
  <sp-help-text slot="help-text">${description}</sp-help-text>
699
647
  <sp-help-text slot="negative-help-text">
@@ -701,17 +649,17 @@ describe('Textfield', () => {
701
649
  </sp-help-text>
702
650
  </sp-textfield>
703
651
  `);
704
- const negativeHelpText = el.querySelector('[slot="negative-help-text"]');
705
- await elementUpdated(el);
706
- expect(negativeHelpText.variant).to.equal('neutral');
707
- await findDescribedNode(name, description);
708
- el.invalid = true;
709
- await elementUpdated(el);
710
- expect(negativeHelpText.variant).to.equal('negative');
711
- await findDescribedNode(name, descriptionNegative);
712
- });
713
- it('manages neutral/negative help text pairs w/ own IDs', async () => {
714
- const el = await litFixture(html `
652
+ const negativeHelpText = el.querySelector('[slot="negative-help-text"]');
653
+ await elementUpdated(el);
654
+ expect(negativeHelpText.variant).to.equal("neutral");
655
+ await findDescribedNode(name, description);
656
+ el.invalid = true;
657
+ await elementUpdated(el);
658
+ expect(negativeHelpText.variant).to.equal("negative");
659
+ await findDescribedNode(name, descriptionNegative);
660
+ });
661
+ it("manages neutral/negative help text pairs w/ own IDs", async () => {
662
+ const el = await litFixture(html`
715
663
  <sp-textfield label=${name}>
716
664
  <sp-help-text slot="help-text" id="help-text-id-2">
717
665
  ${description}
@@ -721,15 +669,15 @@ describe('Textfield', () => {
721
669
  </sp-help-text>
722
670
  </sp-textfield>
723
671
  `);
724
- const negativeHelpText = el.querySelector('[slot="negative-help-text"]');
725
- await elementUpdated(el);
726
- expect(negativeHelpText.variant).to.equal('neutral');
727
- await findDescribedNode(name, description);
728
- el.invalid = true;
729
- await elementUpdated(el);
730
- expect(negativeHelpText.variant).to.equal('negative');
731
- await findDescribedNode(name, descriptionNegative);
732
- });
672
+ const negativeHelpText = el.querySelector('[slot="negative-help-text"]');
673
+ await elementUpdated(el);
674
+ expect(negativeHelpText.variant).to.equal("neutral");
675
+ await findDescribedNode(name, description);
676
+ el.invalid = true;
677
+ await elementUpdated(el);
678
+ expect(negativeHelpText.variant).to.equal("negative");
679
+ await findDescribedNode(name, descriptionNegative);
733
680
  });
681
+ });
734
682
  });
735
- //# sourceMappingURL=textfield.test.js.map
683
+ //# sourceMappingURL=textfield.test.js.map