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