@spectrum-web-components/textfield 0.46.0 → 0.47.1
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 +8 -8
- package/test/textfield.test.js +319 -430
- package/test/textfield.test.js.map +2 -2
package/test/textfield.test.js
CHANGED
|
@@ -13,36 +13,28 @@ import {
|
|
|
13
13
|
import { fixture } from "../../../test/testing-helpers.js";
|
|
14
14
|
describe("Textfield", () => {
|
|
15
15
|
testForLitDevWarnings(
|
|
16
|
-
async () => await litFixture(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
`
|
|
20
|
-
)
|
|
16
|
+
async () => await litFixture(html`
|
|
17
|
+
<sp-textfield label="Enter Your Name"></sp-textfield>
|
|
18
|
+
`)
|
|
21
19
|
);
|
|
22
20
|
it("loads default textfield accessibly", async () => {
|
|
23
|
-
const el = await litFixture(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
`
|
|
27
|
-
);
|
|
21
|
+
const el = await litFixture(html`
|
|
22
|
+
<sp-textfield label="Enter Your Name"></sp-textfield>
|
|
23
|
+
`);
|
|
28
24
|
await elementUpdated(el);
|
|
29
25
|
await expect(el).to.be.accessible();
|
|
30
26
|
});
|
|
31
27
|
it("loads multiline textfield accessibly", async () => {
|
|
32
|
-
const el = await litFixture(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
`
|
|
36
|
-
);
|
|
28
|
+
const el = await litFixture(html`
|
|
29
|
+
<sp-textfield label="Enter your name" multiline></sp-textfield>
|
|
30
|
+
`);
|
|
37
31
|
await elementUpdated(el);
|
|
38
32
|
await expect(el).to.be.accessible();
|
|
39
33
|
});
|
|
40
34
|
it("manages tabIndex while disabled", async () => {
|
|
41
|
-
const el = await litFixture(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
`
|
|
45
|
-
);
|
|
35
|
+
const el = await litFixture(html`
|
|
36
|
+
<sp-textfield placeholder="Enter Your Name"></sp-textfield>
|
|
37
|
+
`);
|
|
46
38
|
await elementUpdated(el);
|
|
47
39
|
expect(el.tabIndex).to.equal(0);
|
|
48
40
|
el.disabled = true;
|
|
@@ -63,11 +55,9 @@ describe("Textfield", () => {
|
|
|
63
55
|
});
|
|
64
56
|
it("loads", async () => {
|
|
65
57
|
const testPlaceholder = "Enter your name";
|
|
66
|
-
const el = await litFixture(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
`
|
|
70
|
-
);
|
|
58
|
+
const el = await litFixture(html`
|
|
59
|
+
<sp-textfield placeholder=${testPlaceholder}></sp-textfield>
|
|
60
|
+
`);
|
|
71
61
|
expect(el).to.not.equal(void 0);
|
|
72
62
|
const input = el.shadowRoot ? el.shadowRoot.querySelector("input") : null;
|
|
73
63
|
expect(input).to.not.be.null;
|
|
@@ -75,28 +65,24 @@ describe("Textfield", () => {
|
|
|
75
65
|
expect(placeholder).to.equal(testPlaceholder);
|
|
76
66
|
});
|
|
77
67
|
it("multiline", async () => {
|
|
78
|
-
const el = await litFixture(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
`
|
|
85
|
-
);
|
|
68
|
+
const el = await litFixture(html`
|
|
69
|
+
<sp-textfield
|
|
70
|
+
placeholder="Enter your name"
|
|
71
|
+
multiline
|
|
72
|
+
></sp-textfield>
|
|
73
|
+
`);
|
|
86
74
|
expect(el).to.not.equal(void 0);
|
|
87
75
|
const input = el.shadowRoot ? el.shadowRoot.querySelector("textarea") : null;
|
|
88
76
|
expect(input).to.not.be.null;
|
|
89
77
|
});
|
|
90
78
|
it("multiline with rows", async () => {
|
|
91
|
-
const el = await litFixture(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
`
|
|
99
|
-
);
|
|
79
|
+
const el = await litFixture(html`
|
|
80
|
+
<sp-textfield
|
|
81
|
+
placeholder="Enter your name"
|
|
82
|
+
multiline
|
|
83
|
+
rows="5"
|
|
84
|
+
></sp-textfield>
|
|
85
|
+
`);
|
|
100
86
|
expect(el).to.not.equal(void 0);
|
|
101
87
|
const input = el.shadowRoot ? el.shadowRoot.querySelector("textarea") : null;
|
|
102
88
|
expect(input).to.not.be.null;
|
|
@@ -104,27 +90,23 @@ describe("Textfield", () => {
|
|
|
104
90
|
});
|
|
105
91
|
it("multiline with 1 row has smaller height than multiline without explicit rows", async () => {
|
|
106
92
|
var _a;
|
|
107
|
-
const oneRowEl = await litFixture(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
`
|
|
115
|
-
);
|
|
93
|
+
const oneRowEl = await litFixture(html`
|
|
94
|
+
<sp-textfield
|
|
95
|
+
placeholder="Enter your name"
|
|
96
|
+
multiline
|
|
97
|
+
rows="1"
|
|
98
|
+
></sp-textfield>
|
|
99
|
+
`);
|
|
116
100
|
expect(oneRowEl).to.not.equal(void 0);
|
|
117
101
|
const oneRowTextarea = oneRowEl.shadowRoot ? oneRowEl.shadowRoot.querySelector("textarea") : null;
|
|
118
102
|
expect(oneRowTextarea).to.not.be.null;
|
|
119
103
|
expect(oneRowTextarea == null ? void 0 : oneRowTextarea.getAttribute("rows")).to.equal("1");
|
|
120
|
-
const defaultEL = await litFixture(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
`
|
|
127
|
-
);
|
|
104
|
+
const defaultEL = await litFixture(html`
|
|
105
|
+
<sp-textfield
|
|
106
|
+
placeholder="Enter your name"
|
|
107
|
+
multiline
|
|
108
|
+
></sp-textfield>
|
|
109
|
+
`);
|
|
128
110
|
expect(defaultEL).to.not.equal(void 0);
|
|
129
111
|
const defaultTextarea = oneRowEl.shadowRoot ? defaultEL.shadowRoot.querySelector("textarea") : null;
|
|
130
112
|
expect(defaultTextarea).to.not.be.null;
|
|
@@ -136,16 +118,14 @@ describe("Textfield", () => {
|
|
|
136
118
|
);
|
|
137
119
|
});
|
|
138
120
|
it("multiline with rows does not resize", async () => {
|
|
139
|
-
const el = await litFixture(
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
`
|
|
148
|
-
);
|
|
121
|
+
const el = await litFixture(html`
|
|
122
|
+
<sp-textfield
|
|
123
|
+
multiline
|
|
124
|
+
rows="5"
|
|
125
|
+
label="No resize control"
|
|
126
|
+
placeholder="No resize control"
|
|
127
|
+
></sp-textfield>
|
|
128
|
+
`);
|
|
149
129
|
const sizedElement = el.focusElement;
|
|
150
130
|
const startBounds = sizedElement.getBoundingClientRect();
|
|
151
131
|
await sendMouse({
|
|
@@ -174,15 +154,13 @@ describe("Textfield", () => {
|
|
|
174
154
|
if (isWebKit()) {
|
|
175
155
|
this.skip();
|
|
176
156
|
}
|
|
177
|
-
const el = await fixture(
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
`
|
|
185
|
-
);
|
|
157
|
+
const el = await fixture(html`
|
|
158
|
+
<sp-textfield
|
|
159
|
+
multiline
|
|
160
|
+
label="No resize control"
|
|
161
|
+
placeholder="No resize control"
|
|
162
|
+
></sp-textfield>
|
|
163
|
+
`);
|
|
186
164
|
const sizedElement = el.focusElement;
|
|
187
165
|
const startBounds = sizedElement.getBoundingClientRect();
|
|
188
166
|
await sendMouse({
|
|
@@ -208,16 +186,14 @@ describe("Textfield", () => {
|
|
|
208
186
|
expect(endBounds.width).to.be.greaterThan(startBounds.width);
|
|
209
187
|
});
|
|
210
188
|
it("accepts resize styling", async () => {
|
|
211
|
-
const el = await litFixture(
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
`
|
|
220
|
-
);
|
|
189
|
+
const el = await litFixture(html`
|
|
190
|
+
<sp-textfield
|
|
191
|
+
multiline
|
|
192
|
+
style="resize: none;"
|
|
193
|
+
label="No resize control"
|
|
194
|
+
placeholder="No resize control"
|
|
195
|
+
></sp-textfield>
|
|
196
|
+
`);
|
|
221
197
|
const startBounds = el.getBoundingClientRect();
|
|
222
198
|
await sendMouse({
|
|
223
199
|
steps: [
|
|
@@ -242,44 +218,38 @@ describe("Textfield", () => {
|
|
|
242
218
|
expect(endBounds.height).equals(startBounds.height);
|
|
243
219
|
});
|
|
244
220
|
it("grows", async () => {
|
|
245
|
-
const el = await litFixture(
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
`
|
|
253
|
-
);
|
|
221
|
+
const el = await litFixture(html`
|
|
222
|
+
<sp-textfield
|
|
223
|
+
placeholder="Enter your name"
|
|
224
|
+
multiline
|
|
225
|
+
grows
|
|
226
|
+
></sp-textfield>
|
|
227
|
+
`);
|
|
254
228
|
expect(el).to.not.equal(void 0);
|
|
255
229
|
const sizer = el.shadowRoot ? el.shadowRoot.querySelector("#sizer") : null;
|
|
256
230
|
expect(sizer).to.not.be.null;
|
|
257
231
|
});
|
|
258
232
|
it("multiline with rows and grows does not grow", async () => {
|
|
259
|
-
const el = await litFixture(
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
`
|
|
268
|
-
);
|
|
233
|
+
const el = await litFixture(html`
|
|
234
|
+
<sp-textfield
|
|
235
|
+
placeholder="Enter your name"
|
|
236
|
+
multiline
|
|
237
|
+
grows
|
|
238
|
+
rows="5"
|
|
239
|
+
></sp-textfield>
|
|
240
|
+
`);
|
|
269
241
|
expect(el).to.not.equal(void 0);
|
|
270
242
|
const sizer = el.shadowRoot ? el.shadowRoot.querySelector("#sizer") : null;
|
|
271
243
|
expect(sizer).to.be.null;
|
|
272
244
|
});
|
|
273
245
|
it("multiline with grows actually grow", async () => {
|
|
274
|
-
const el = await litFixture(
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
`
|
|
282
|
-
);
|
|
246
|
+
const el = await litFixture(html`
|
|
247
|
+
<sp-textfield
|
|
248
|
+
placeholder="Enter your name"
|
|
249
|
+
multiline
|
|
250
|
+
grows
|
|
251
|
+
></sp-textfield>
|
|
252
|
+
`);
|
|
283
253
|
expect(el).to.not.equal(void 0);
|
|
284
254
|
const textArea = el.shadowRoot.querySelector("textarea");
|
|
285
255
|
expect(textArea).to.not.be.null;
|
|
@@ -298,137 +268,119 @@ describe("Textfield", () => {
|
|
|
298
268
|
}
|
|
299
269
|
});
|
|
300
270
|
it("valid", async () => {
|
|
301
|
-
const el = await litFixture(
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
`
|
|
310
|
-
);
|
|
271
|
+
const el = await litFixture(html`
|
|
272
|
+
<sp-textfield
|
|
273
|
+
placeholder="Enter your number"
|
|
274
|
+
pattern="[\\d]+"
|
|
275
|
+
value="123"
|
|
276
|
+
required
|
|
277
|
+
></sp-textfield>
|
|
278
|
+
`);
|
|
311
279
|
await elementUpdated(el);
|
|
312
280
|
expect(el).to.not.equal(void 0);
|
|
313
281
|
const input = el.shadowRoot ? el.shadowRoot.querySelector("#valid") : null;
|
|
314
282
|
expect(input).to.not.be.null;
|
|
315
283
|
});
|
|
316
284
|
it("handles `name` attribute", async () => {
|
|
317
|
-
const el = await litFixture(
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
`
|
|
321
|
-
);
|
|
285
|
+
const el = await litFixture(html`
|
|
286
|
+
<sp-textfield placeholder="Enter your name"></sp-textfield>
|
|
287
|
+
`);
|
|
322
288
|
expect(el).to.not.equal(void 0);
|
|
323
289
|
expect(el.name).to.be.undefined;
|
|
324
290
|
el.setAttribute("name", "test");
|
|
325
291
|
expect(el.name).to.be.equal("test");
|
|
326
292
|
});
|
|
327
293
|
it("handles `name` attribute with multiline", async () => {
|
|
328
|
-
const el = await litFixture(
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
`
|
|
336
|
-
);
|
|
294
|
+
const el = await litFixture(html`
|
|
295
|
+
<sp-textfield
|
|
296
|
+
name="name"
|
|
297
|
+
placeholder="Enter your name"
|
|
298
|
+
multiline
|
|
299
|
+
></sp-textfield>
|
|
300
|
+
`);
|
|
337
301
|
expect(el).to.not.equal(void 0);
|
|
338
302
|
const input = el.shadowRoot ? el.shadowRoot.querySelector("textarea") : null;
|
|
339
303
|
expect(input == null ? void 0 : input.name).to.equal("name");
|
|
340
304
|
});
|
|
341
305
|
it("valid - multiline", async () => {
|
|
342
|
-
const el = await litFixture(
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
`
|
|
352
|
-
);
|
|
306
|
+
const el = await litFixture(html`
|
|
307
|
+
<sp-textfield
|
|
308
|
+
placeholder="Enter your number"
|
|
309
|
+
pattern="[\\d]+"
|
|
310
|
+
value="123"
|
|
311
|
+
required
|
|
312
|
+
multiline
|
|
313
|
+
></sp-textfield>
|
|
314
|
+
`);
|
|
353
315
|
await elementUpdated(el);
|
|
354
316
|
expect(el).to.not.equal(void 0);
|
|
355
317
|
const input = el.shadowRoot ? el.shadowRoot.querySelector("#valid") : null;
|
|
356
318
|
expect(input).to.not.be.null;
|
|
357
319
|
});
|
|
358
320
|
it("valid - required", async () => {
|
|
359
|
-
const el = await litFixture(
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
`
|
|
367
|
-
);
|
|
321
|
+
const el = await litFixture(html`
|
|
322
|
+
<sp-textfield
|
|
323
|
+
placeholder="Enter your number"
|
|
324
|
+
value="123"
|
|
325
|
+
required
|
|
326
|
+
></sp-textfield>
|
|
327
|
+
`);
|
|
368
328
|
await elementUpdated(el);
|
|
369
329
|
expect(el).to.not.equal(void 0);
|
|
370
330
|
const input = el.shadowRoot ? el.shadowRoot.querySelector("#valid") : null;
|
|
371
331
|
expect(input).to.not.be.null;
|
|
372
332
|
});
|
|
373
333
|
it("valid - multiline - required", async () => {
|
|
374
|
-
const el = await litFixture(
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
`
|
|
383
|
-
);
|
|
334
|
+
const el = await litFixture(html`
|
|
335
|
+
<sp-textfield
|
|
336
|
+
placeholder="Enter your number"
|
|
337
|
+
value="123"
|
|
338
|
+
required
|
|
339
|
+
multiline
|
|
340
|
+
></sp-textfield>
|
|
341
|
+
`);
|
|
384
342
|
await elementUpdated(el);
|
|
385
343
|
expect(el).to.not.equal(void 0);
|
|
386
344
|
const input = el.shadowRoot ? el.shadowRoot.querySelector("#valid") : null;
|
|
387
345
|
expect(input).to.not.be.null;
|
|
388
346
|
});
|
|
389
347
|
it("valid - boundary-type assertions", async () => {
|
|
390
|
-
const el = await litFixture(
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
`
|
|
399
|
-
);
|
|
348
|
+
const el = await litFixture(html`
|
|
349
|
+
<sp-textfield
|
|
350
|
+
placeholder="Enter your number"
|
|
351
|
+
pattern="^[\\d]+$"
|
|
352
|
+
value="123"
|
|
353
|
+
required
|
|
354
|
+
></sp-textfield>
|
|
355
|
+
`);
|
|
400
356
|
await elementUpdated(el);
|
|
401
357
|
expect(el).to.not.equal(void 0);
|
|
402
358
|
const input = el.shadowRoot ? el.shadowRoot.querySelector("#valid") : null;
|
|
403
359
|
expect(input).to.not.be.null;
|
|
404
360
|
});
|
|
405
361
|
it("valid - multiline - boundary-type assertions", async () => {
|
|
406
|
-
const el = await litFixture(
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
`
|
|
416
|
-
);
|
|
362
|
+
const el = await litFixture(html`
|
|
363
|
+
<sp-textfield
|
|
364
|
+
placeholder="Enter your number"
|
|
365
|
+
pattern="^[\\d]+$"
|
|
366
|
+
value="123"
|
|
367
|
+
required
|
|
368
|
+
multiline
|
|
369
|
+
></sp-textfield>
|
|
370
|
+
`);
|
|
417
371
|
await elementUpdated(el);
|
|
418
372
|
expect(el).to.not.equal(void 0);
|
|
419
373
|
const input = el.shadowRoot ? el.shadowRoot.querySelector("#valid") : null;
|
|
420
374
|
expect(input).to.not.be.null;
|
|
421
375
|
});
|
|
422
376
|
it("valid - boundary-type assertions and title", async () => {
|
|
423
|
-
const el = await litFixture(
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
`
|
|
431
|
-
);
|
|
377
|
+
const el = await litFixture(html`
|
|
378
|
+
<sp-textfield
|
|
379
|
+
placeholder="Enter your number"
|
|
380
|
+
pattern="^[\\d]+$"
|
|
381
|
+
value="123"
|
|
382
|
+
></sp-textfield>
|
|
383
|
+
`);
|
|
432
384
|
await elementUpdated(el);
|
|
433
385
|
expect(el).to.not.equal(void 0);
|
|
434
386
|
const input = el.shadowRoot.querySelector("#valid");
|
|
@@ -436,16 +388,14 @@ describe("Textfield", () => {
|
|
|
436
388
|
expect(el.focusElement).to.not.have.attribute("title");
|
|
437
389
|
});
|
|
438
390
|
it("valid - multiline - boundary-type assertions and title", async () => {
|
|
439
|
-
const el = await litFixture(
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
`
|
|
448
|
-
);
|
|
391
|
+
const el = await litFixture(html`
|
|
392
|
+
<sp-textfield
|
|
393
|
+
multiline
|
|
394
|
+
placeholder="Enter your number"
|
|
395
|
+
pattern="^[\\d]+$"
|
|
396
|
+
value="123"
|
|
397
|
+
></sp-textfield>
|
|
398
|
+
`);
|
|
449
399
|
await elementUpdated(el);
|
|
450
400
|
expect(el).to.not.equal(void 0);
|
|
451
401
|
const input = el.shadowRoot.querySelector("#valid");
|
|
@@ -453,162 +403,142 @@ describe("Textfield", () => {
|
|
|
453
403
|
expect(el.focusElement).to.not.have.attribute("title");
|
|
454
404
|
});
|
|
455
405
|
it("valid - unicode", async () => {
|
|
456
|
-
const el = await litFixture(
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
`
|
|
465
|
-
);
|
|
406
|
+
const el = await litFixture(html`
|
|
407
|
+
<sp-textfield
|
|
408
|
+
placeholder="Enter your name"
|
|
409
|
+
pattern="\\p{L}{4,8}"
|
|
410
|
+
value="你的名字"
|
|
411
|
+
required
|
|
412
|
+
></sp-textfield>
|
|
413
|
+
`);
|
|
466
414
|
await elementUpdated(el);
|
|
467
415
|
expect(el).to.not.equal(void 0);
|
|
468
416
|
const input = el.shadowRoot ? el.shadowRoot.querySelector("#valid") : null;
|
|
469
417
|
expect(input).to.not.be.null;
|
|
470
418
|
});
|
|
471
419
|
it("valid - multiline - unicode", async () => {
|
|
472
|
-
const el = await litFixture(
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
`
|
|
482
|
-
);
|
|
420
|
+
const el = await litFixture(html`
|
|
421
|
+
<sp-textfield
|
|
422
|
+
placeholder="Enter your name"
|
|
423
|
+
pattern="\\p{L}{4,8}"
|
|
424
|
+
value="你的名字"
|
|
425
|
+
required
|
|
426
|
+
multiline
|
|
427
|
+
></sp-textfield>
|
|
428
|
+
`);
|
|
483
429
|
await elementUpdated(el);
|
|
484
430
|
expect(el).to.not.equal(void 0);
|
|
485
431
|
const input = el.shadowRoot ? el.shadowRoot.querySelector("#valid") : null;
|
|
486
432
|
expect(input).to.not.be.null;
|
|
487
433
|
});
|
|
488
434
|
it("invalid", async () => {
|
|
489
|
-
const el = await litFixture(
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
`
|
|
498
|
-
);
|
|
435
|
+
const el = await litFixture(html`
|
|
436
|
+
<sp-textfield
|
|
437
|
+
placeholder="Enter your number"
|
|
438
|
+
pattern="[\\d]+"
|
|
439
|
+
value="123 not valid"
|
|
440
|
+
required
|
|
441
|
+
></sp-textfield>
|
|
442
|
+
`);
|
|
499
443
|
await elementUpdated(el);
|
|
500
444
|
expect(el).to.not.equal(void 0);
|
|
501
445
|
const input = el.shadowRoot ? el.shadowRoot.querySelector("#invalid") : null;
|
|
502
446
|
expect(input).to.not.be.null;
|
|
503
447
|
});
|
|
504
448
|
it("invalid - multiline", async () => {
|
|
505
|
-
const el = await litFixture(
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
`
|
|
515
|
-
);
|
|
449
|
+
const el = await litFixture(html`
|
|
450
|
+
<sp-textfield
|
|
451
|
+
placeholder="Enter your number"
|
|
452
|
+
pattern="[\\d]+"
|
|
453
|
+
value="123 not valid"
|
|
454
|
+
required
|
|
455
|
+
multiline
|
|
456
|
+
></sp-textfield>
|
|
457
|
+
`);
|
|
516
458
|
await elementUpdated(el);
|
|
517
459
|
expect(el).to.not.equal(void 0);
|
|
518
460
|
const input = el.shadowRoot ? el.shadowRoot.querySelector("#invalid") : null;
|
|
519
461
|
expect(input).to.not.be.null;
|
|
520
462
|
});
|
|
521
463
|
it("invalid - required", async () => {
|
|
522
|
-
const el = await litFixture(
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
`
|
|
530
|
-
);
|
|
464
|
+
const el = await litFixture(html`
|
|
465
|
+
<sp-textfield
|
|
466
|
+
placeholder="Enter your number"
|
|
467
|
+
value=""
|
|
468
|
+
required
|
|
469
|
+
></sp-textfield>
|
|
470
|
+
`);
|
|
531
471
|
await elementUpdated(el);
|
|
532
472
|
expect(el).to.not.equal(void 0);
|
|
533
473
|
const input = el.shadowRoot ? el.shadowRoot.querySelector("#invalid") : null;
|
|
534
474
|
expect(input).to.not.be.null;
|
|
535
475
|
});
|
|
536
476
|
it("invalid - multiline - required", async () => {
|
|
537
|
-
const el = await litFixture(
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
`
|
|
546
|
-
);
|
|
477
|
+
const el = await litFixture(html`
|
|
478
|
+
<sp-textfield
|
|
479
|
+
placeholder="Enter your number"
|
|
480
|
+
value=""
|
|
481
|
+
required
|
|
482
|
+
multiline
|
|
483
|
+
></sp-textfield>
|
|
484
|
+
`);
|
|
547
485
|
await elementUpdated(el);
|
|
548
486
|
expect(el).to.not.equal(void 0);
|
|
549
487
|
const input = el.shadowRoot ? el.shadowRoot.querySelector("#invalid") : null;
|
|
550
488
|
expect(input).to.not.be.null;
|
|
551
489
|
});
|
|
552
490
|
it("invalid - unicode", async () => {
|
|
553
|
-
const el = await litFixture(
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
`
|
|
562
|
-
);
|
|
491
|
+
const el = await litFixture(html`
|
|
492
|
+
<sp-textfield
|
|
493
|
+
placeholder="Enter your number"
|
|
494
|
+
pattern="\\p{N}+"
|
|
495
|
+
value="123 not valid"
|
|
496
|
+
required
|
|
497
|
+
></sp-textfield>
|
|
498
|
+
`);
|
|
563
499
|
await elementUpdated(el);
|
|
564
500
|
expect(el).to.not.equal(void 0);
|
|
565
501
|
const input = el.shadowRoot ? el.shadowRoot.querySelector("#invalid") : null;
|
|
566
502
|
expect(input).to.not.be.null;
|
|
567
503
|
});
|
|
568
504
|
it("invalid - multiline - unicode", async () => {
|
|
569
|
-
const el = await litFixture(
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
`
|
|
579
|
-
);
|
|
505
|
+
const el = await litFixture(html`
|
|
506
|
+
<sp-textfield
|
|
507
|
+
placeholder="Enter your number"
|
|
508
|
+
pattern="\\p{N}+"
|
|
509
|
+
value="123 not valid"
|
|
510
|
+
required
|
|
511
|
+
multiline
|
|
512
|
+
></sp-textfield>
|
|
513
|
+
`);
|
|
580
514
|
await elementUpdated(el);
|
|
581
515
|
expect(el).to.not.equal(void 0);
|
|
582
516
|
const input = el.shadowRoot ? el.shadowRoot.querySelector("#invalid") : null;
|
|
583
517
|
expect(input).to.not.be.null;
|
|
584
518
|
});
|
|
585
519
|
it("invalid - boundary-type assertions", async () => {
|
|
586
|
-
const el = await litFixture(
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
`
|
|
595
|
-
);
|
|
520
|
+
const el = await litFixture(html`
|
|
521
|
+
<sp-textfield
|
|
522
|
+
placeholder="Enter your number"
|
|
523
|
+
pattern="^\\p{N}+$"
|
|
524
|
+
value="123 not valid"
|
|
525
|
+
required
|
|
526
|
+
></sp-textfield>
|
|
527
|
+
`);
|
|
596
528
|
await elementUpdated(el);
|
|
597
529
|
expect(el).to.not.equal(void 0);
|
|
598
530
|
const input = el.shadowRoot ? el.shadowRoot.querySelector("#invalid") : null;
|
|
599
531
|
expect(input).to.not.be.null;
|
|
600
532
|
});
|
|
601
533
|
it("invalid - boundary-type assertions and title", async () => {
|
|
602
|
-
const el = await litFixture(
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
`
|
|
611
|
-
);
|
|
534
|
+
const el = await litFixture(html`
|
|
535
|
+
<sp-textfield
|
|
536
|
+
placeholder="Enter your number"
|
|
537
|
+
type="url"
|
|
538
|
+
value="invalid-email"
|
|
539
|
+
invalid
|
|
540
|
+
></sp-textfield>
|
|
541
|
+
`);
|
|
612
542
|
await elementUpdated(el);
|
|
613
543
|
expect(el).to.not.equal(void 0);
|
|
614
544
|
const input = el.shadowRoot.querySelector("#invalid");
|
|
@@ -616,17 +546,15 @@ describe("Textfield", () => {
|
|
|
616
546
|
expect(el.focusElement).to.have.attribute("title");
|
|
617
547
|
});
|
|
618
548
|
it("invalid - multiline - boundary-type assertions and title", async () => {
|
|
619
|
-
const el = await litFixture(
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
`
|
|
629
|
-
);
|
|
549
|
+
const el = await litFixture(html`
|
|
550
|
+
<sp-textfield
|
|
551
|
+
multiline
|
|
552
|
+
placeholder="Enter your number"
|
|
553
|
+
type="url"
|
|
554
|
+
value="invalid-email"
|
|
555
|
+
invalid
|
|
556
|
+
></sp-textfield>
|
|
557
|
+
`);
|
|
630
558
|
await elementUpdated(el);
|
|
631
559
|
expect(el).to.not.equal(void 0);
|
|
632
560
|
const input = el.shadowRoot.querySelector("#invalid");
|
|
@@ -634,17 +562,15 @@ describe("Textfield", () => {
|
|
|
634
562
|
expect(el.focusElement).to.have.attribute("title");
|
|
635
563
|
});
|
|
636
564
|
it("invalid - multiline - boundary-type assertions", async () => {
|
|
637
|
-
const el = await litFixture(
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
`
|
|
647
|
-
);
|
|
565
|
+
const el = await litFixture(html`
|
|
566
|
+
<sp-textfield
|
|
567
|
+
placeholder="Enter your number"
|
|
568
|
+
pattern="^\\p{N}+$"
|
|
569
|
+
value="123 not valid"
|
|
570
|
+
required
|
|
571
|
+
multiline
|
|
572
|
+
></sp-textfield>
|
|
573
|
+
`);
|
|
648
574
|
await elementUpdated(el);
|
|
649
575
|
expect(el).to.not.equal(void 0);
|
|
650
576
|
const input = el.shadowRoot ? el.shadowRoot.querySelector("#invalid") : null;
|
|
@@ -657,11 +583,9 @@ describe("Textfield", () => {
|
|
|
657
583
|
activeElement = path[0];
|
|
658
584
|
};
|
|
659
585
|
document.addEventListener("focusin", onFocusIn);
|
|
660
|
-
const el = await litFixture(
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
`
|
|
664
|
-
);
|
|
586
|
+
const el = await litFixture(html`
|
|
587
|
+
<sp-textfield placeholder="Enter your name"></sp-textfield>
|
|
588
|
+
`);
|
|
665
589
|
await elementUpdated(el);
|
|
666
590
|
el.focus();
|
|
667
591
|
await elementUpdated(el);
|
|
@@ -675,14 +599,9 @@ describe("Textfield", () => {
|
|
|
675
599
|
activeElement = path[0];
|
|
676
600
|
};
|
|
677
601
|
document.addEventListener("focusin", onFocusIn);
|
|
678
|
-
const el = await litFixture(
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
disabled
|
|
682
|
-
placeholder="Enter your name"
|
|
683
|
-
></sp-textfield>
|
|
684
|
-
`
|
|
685
|
-
);
|
|
602
|
+
const el = await litFixture(html`
|
|
603
|
+
<sp-textfield disabled placeholder="Enter your name"></sp-textfield>
|
|
604
|
+
`);
|
|
686
605
|
await elementUpdated(el);
|
|
687
606
|
el.focus();
|
|
688
607
|
await elementUpdated(el);
|
|
@@ -697,11 +616,9 @@ describe("Textfield", () => {
|
|
|
697
616
|
});
|
|
698
617
|
it("accepts input", async () => {
|
|
699
618
|
const testValue = "Test Name";
|
|
700
|
-
const el = await litFixture(
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
`
|
|
704
|
-
);
|
|
619
|
+
const el = await litFixture(html`
|
|
620
|
+
<sp-textfield placeholder="Enter your name"></sp-textfield>
|
|
621
|
+
`);
|
|
705
622
|
await elementUpdated(el);
|
|
706
623
|
el.focusElement.value = testValue;
|
|
707
624
|
el.focusElement.dispatchEvent(new Event("input"));
|
|
@@ -709,11 +626,9 @@ describe("Textfield", () => {
|
|
|
709
626
|
});
|
|
710
627
|
it("selects", async () => {
|
|
711
628
|
const testValue = "Test Name";
|
|
712
|
-
const el = await litFixture(
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
`
|
|
716
|
-
);
|
|
629
|
+
const el = await litFixture(html`
|
|
630
|
+
<sp-textfield value=${testValue}></sp-textfield>
|
|
631
|
+
`);
|
|
717
632
|
await elementUpdated(el);
|
|
718
633
|
expect(el.value).to.equal(testValue);
|
|
719
634
|
el.focus();
|
|
@@ -723,11 +638,9 @@ describe("Textfield", () => {
|
|
|
723
638
|
});
|
|
724
639
|
it("setSelectionRange", async () => {
|
|
725
640
|
const testValue = "Test Name";
|
|
726
|
-
const el = await litFixture(
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
`
|
|
730
|
-
);
|
|
641
|
+
const el = await litFixture(html`
|
|
642
|
+
<sp-textfield value=${testValue}></sp-textfield>
|
|
643
|
+
`);
|
|
731
644
|
await elementUpdated(el);
|
|
732
645
|
expect(el.value).to.equal(testValue);
|
|
733
646
|
el.focus();
|
|
@@ -736,11 +649,9 @@ describe("Textfield", () => {
|
|
|
736
649
|
expect(el.value).to.equal("Name");
|
|
737
650
|
});
|
|
738
651
|
it("handles minlength with required", async () => {
|
|
739
|
-
const el = await litFixture(
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
`
|
|
743
|
-
);
|
|
652
|
+
const el = await litFixture(html`
|
|
653
|
+
<sp-textfield required minlength="3"></sp-textfield>
|
|
654
|
+
`);
|
|
744
655
|
el.focus();
|
|
745
656
|
await sendKeys({
|
|
746
657
|
type: "ab"
|
|
@@ -756,16 +667,14 @@ describe("Textfield", () => {
|
|
|
756
667
|
expect(el.checkValidity()).to.be.true;
|
|
757
668
|
});
|
|
758
669
|
it("accepts maxlength", async () => {
|
|
759
|
-
const el = await litFixture(
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
`
|
|
768
|
-
);
|
|
670
|
+
const el = await litFixture(html`
|
|
671
|
+
<sp-textfield
|
|
672
|
+
placeholder="Enter your name"
|
|
673
|
+
maxlength="3"
|
|
674
|
+
minlength="2"
|
|
675
|
+
required
|
|
676
|
+
></sp-textfield>
|
|
677
|
+
`);
|
|
769
678
|
await elementUpdated(el);
|
|
770
679
|
el.focus();
|
|
771
680
|
await sendKeys({
|
|
@@ -811,14 +720,12 @@ describe("Textfield", () => {
|
|
|
811
720
|
const onChange = (event) => {
|
|
812
721
|
eventSource = event.composedPath()[0];
|
|
813
722
|
};
|
|
814
|
-
const el = await litFixture(
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
`
|
|
821
|
-
);
|
|
723
|
+
const el = await litFixture(html`
|
|
724
|
+
<sp-textfield
|
|
725
|
+
placeholder="Enter your name"
|
|
726
|
+
@change=${onChange}
|
|
727
|
+
></sp-textfield>
|
|
728
|
+
`);
|
|
822
729
|
await elementUpdated(el);
|
|
823
730
|
el.focusElement.value = testValue;
|
|
824
731
|
el.focusElement.dispatchEvent(new Event("input"));
|
|
@@ -828,22 +735,18 @@ describe("Textfield", () => {
|
|
|
828
735
|
expect(testSource).to.equal(el);
|
|
829
736
|
});
|
|
830
737
|
it("passes through `autocomplete` attribute", async () => {
|
|
831
|
-
let el = await litFixture(
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
`
|
|
835
|
-
);
|
|
738
|
+
let el = await litFixture(html`
|
|
739
|
+
<sp-textfield autocomplete="off"></sp-textfield>
|
|
740
|
+
`);
|
|
836
741
|
await elementUpdated(el);
|
|
837
742
|
let input = el.shadowRoot ? el.shadowRoot.querySelector("input") : null;
|
|
838
743
|
expect(input).to.exist;
|
|
839
744
|
if (input) {
|
|
840
745
|
expect(input.getAttribute("autocomplete")).to.equal("off");
|
|
841
746
|
}
|
|
842
|
-
el = await litFixture(
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
`
|
|
846
|
-
);
|
|
747
|
+
el = await litFixture(html`
|
|
748
|
+
<sp-textfield></sp-textfield>
|
|
749
|
+
`);
|
|
847
750
|
await elementUpdated(el);
|
|
848
751
|
input = el.shadowRoot ? el.shadowRoot.querySelector("input") : null;
|
|
849
752
|
expect(input).to.exist;
|
|
@@ -852,11 +755,9 @@ describe("Textfield", () => {
|
|
|
852
755
|
}
|
|
853
756
|
});
|
|
854
757
|
it("tests on `required` changes", async () => {
|
|
855
|
-
const el = await litFixture(
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
`
|
|
859
|
-
);
|
|
758
|
+
const el = await litFixture(html`
|
|
759
|
+
<sp-textfield value=""></sp-textfield>
|
|
760
|
+
`);
|
|
860
761
|
await elementUpdated(el);
|
|
861
762
|
expect(el.invalid).to.be.false;
|
|
862
763
|
el.required = true;
|
|
@@ -864,11 +765,9 @@ describe("Textfield", () => {
|
|
|
864
765
|
expect(el.invalid).to.be.true;
|
|
865
766
|
});
|
|
866
767
|
it("manages `allowed-keys`", async () => {
|
|
867
|
-
const el = await litFixture(
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
`
|
|
871
|
-
);
|
|
768
|
+
const el = await litFixture(html`
|
|
769
|
+
<sp-textfield allowed-keys="asdf"></sp-textfield>
|
|
770
|
+
`);
|
|
872
771
|
await elementUpdated(el);
|
|
873
772
|
expect(el.value).to.equal("");
|
|
874
773
|
const inputElement = el.focusElement;
|
|
@@ -899,49 +798,39 @@ describe("Textfield", () => {
|
|
|
899
798
|
"password"
|
|
900
799
|
];
|
|
901
800
|
for await (const t of types) {
|
|
902
|
-
const el = await litFixture(
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
`
|
|
906
|
-
);
|
|
801
|
+
const el = await litFixture(html`
|
|
802
|
+
<sp-textfield type=${t}></sp-textfield>
|
|
803
|
+
`);
|
|
907
804
|
expect(el.type).equals(t);
|
|
908
805
|
el.setAttribute("type", "url");
|
|
909
806
|
expect(el.type).equals("url");
|
|
910
807
|
}
|
|
911
808
|
});
|
|
912
809
|
it('represents invalid and missing attributes as "text"', async () => {
|
|
913
|
-
const el1 = await litFixture(
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
html`
|
|
920
|
-
<sp-textfield type="time"></sp-textfield>
|
|
921
|
-
`
|
|
922
|
-
);
|
|
810
|
+
const el1 = await litFixture(html`
|
|
811
|
+
<sp-textfield></sp-textfield>
|
|
812
|
+
`);
|
|
813
|
+
const el2 = await litFixture(html`
|
|
814
|
+
<sp-textfield type="time"></sp-textfield>
|
|
815
|
+
`);
|
|
923
816
|
expect(el1.type).equals("text");
|
|
924
817
|
expect(el2.type).equals("text");
|
|
925
818
|
el1.setAttribute("type", "submit");
|
|
926
819
|
expect(el1.type).equals("text");
|
|
927
820
|
});
|
|
928
821
|
it("reflects valid property assignments", async () => {
|
|
929
|
-
const el = await litFixture(
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
`
|
|
933
|
-
);
|
|
822
|
+
const el = await litFixture(html`
|
|
823
|
+
<sp-textfield type="url"></sp-textfield>
|
|
824
|
+
`);
|
|
934
825
|
el.type = "email";
|
|
935
826
|
await elementUpdated(el);
|
|
936
827
|
expect(el.getAttribute("type")).equals("email");
|
|
937
828
|
expect(el.type).equals("email");
|
|
938
829
|
});
|
|
939
830
|
it('reflects invalid assignments but sets state to "text"', async () => {
|
|
940
|
-
const el = await litFixture(
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
`
|
|
944
|
-
);
|
|
831
|
+
const el = await litFixture(html`
|
|
832
|
+
<sp-textfield type="url"></sp-textfield>
|
|
833
|
+
`);
|
|
945
834
|
el.type = "range";
|
|
946
835
|
await elementUpdated(el);
|
|
947
836
|
expect(el.getAttribute("type")).equals("range");
|