@moni-labs/moni-ui 0.4.13 → 0.4.16
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/custom-elements.json +101 -81
- package/dist/browser/moni-ui.iife.min.js +1538 -1384
- package/dist/browser/moni-ui.iife.min.js.br +0 -0
- package/dist/browser/moni-ui.iife.min.js.gz +0 -0
- package/dist/browser/moni-ui.iife.min.js.map +1 -1
- package/dist/browser/moni-ui.min.js +2751 -2501
- package/dist/browser/moni-ui.min.js.br +0 -0
- package/dist/browser/moni-ui.min.js.gz +0 -0
- package/dist/browser/moni-ui.min.js.map +1 -1
- package/dist/cdn/chunks/{class-map-DsL1Jr2T.js → class-map-QyT9W7rZ.js} +1 -1
- package/dist/cdn/chunks/{decorate-DxJYS4gw.js → decorate-B7wZvwrn.js} +629 -543
- package/dist/cdn/chunks/if-defined-5hr_ccFw.js +1 -0
- package/dist/cdn/chunks/{live-D52JqeKf.js → live-Hm1Di_ND.js} +1 -1
- package/dist/cdn/components/moni-app-bar.js +1 -1
- package/dist/cdn/components/moni-badge.js +1 -1
- package/dist/cdn/components/moni-bottom-sheet.js +2 -1
- package/dist/cdn/components/moni-button-group.js +1 -1
- package/dist/cdn/components/moni-button-segment.js +1 -1
- package/dist/cdn/components/moni-button.js +1 -1
- package/dist/cdn/components/moni-card.js +1 -1
- package/dist/cdn/components/moni-carousel.js +1 -1
- package/dist/cdn/components/moni-checkbox.js +1 -1
- package/dist/cdn/components/moni-chip.js +1 -1
- package/dist/cdn/components/moni-color-field.js +1 -1
- package/dist/cdn/components/moni-context-menu.js +1 -1
- package/dist/cdn/components/moni-dialog.js +1 -1
- package/dist/cdn/components/moni-divider.js +1 -1
- package/dist/cdn/components/moni-expansion.js +1 -1
- package/dist/cdn/components/moni-fab-menu.js +1 -1
- package/dist/cdn/components/moni-fab.js +1 -1
- package/dist/cdn/components/moni-file-field.js +1 -1
- package/dist/cdn/components/moni-icon.js +1 -1
- package/dist/cdn/components/moni-list-item.js +1 -1
- package/dist/cdn/components/moni-list.js +1 -1
- package/dist/cdn/components/moni-loading-indicator.js +1 -1
- package/dist/cdn/components/moni-menu-item.js +1 -1
- package/dist/cdn/components/moni-menu.js +1 -1
- package/dist/cdn/components/moni-morph-modal.js +3 -2
- package/dist/cdn/components/moni-nav-item.js +1 -1
- package/dist/cdn/components/moni-nav.js +1 -1
- package/dist/cdn/components/moni-progress.js +1 -1
- package/dist/cdn/components/moni-radio.js +1 -1
- package/dist/cdn/components/moni-ripple.js +1 -1
- package/dist/cdn/components/moni-segmented-button.js +1 -1
- package/dist/cdn/components/moni-select-option.js +1 -1
- package/dist/cdn/components/moni-select.js +512 -473
- package/dist/cdn/components/moni-shape.js +1 -1
- package/dist/cdn/components/moni-side-sheet.js +1 -1
- package/dist/cdn/components/moni-slider.js +1 -1
- package/dist/cdn/components/moni-snackbar.js +1 -1
- package/dist/cdn/components/moni-split-button.js +1 -1
- package/dist/cdn/components/moni-step.js +1 -1
- package/dist/cdn/components/moni-stepper.js +1 -1
- package/dist/cdn/components/moni-switch.js +1 -1
- package/dist/cdn/components/moni-tab.js +1 -1
- package/dist/cdn/components/moni-tabs.js +1 -1
- package/dist/cdn/components/moni-text-field.js +122 -95
- package/dist/cdn/components/moni-textarea.js +52 -52
- package/dist/cdn/components/moni-time-picker.js +1 -1
- package/dist/cdn/components/moni-toolbar.js +1 -1
- package/dist/cdn/components/moni-tooltip.js +1 -1
- package/dist/cdn/components/moni-typography.js +1 -1
- package/dist/cdn/importmap.json +98 -98
- package/dist/components/_base/field-styles.d.ts.map +1 -1
- package/dist/components/_base/field-styles.js +662 -576
- package/dist/components/moni-bottom-sheet.d.ts +19 -5
- package/dist/components/moni-bottom-sheet.d.ts.map +1 -1
- package/dist/components/moni-bottom-sheet.js +111 -30
- package/dist/components/moni-morph-modal.d.ts +10 -0
- package/dist/components/moni-morph-modal.d.ts.map +1 -1
- package/dist/components/moni-morph-modal.js +323 -217
- package/dist/components/moni-select.d.ts +16 -16
- package/dist/components/moni-select.d.ts.map +1 -1
- package/dist/components/moni-select.js +797 -727
- package/dist/components/moni-text-field.d.ts +15 -15
- package/dist/components/moni-text-field.d.ts.map +1 -1
- package/dist/components/moni-text-field.js +224 -180
- package/dist/components/moni-textarea.d.ts +13 -13
- package/dist/components/moni-textarea.d.ts.map +1 -1
- package/dist/components/moni-textarea.js +127 -122
- package/docs/api.json +109 -89
- package/docs/assets/moni-color-field/shape--square.png +0 -0
- package/docs/assets/moni-file-field/shape--square.png +0 -0
- package/docs/assets/moni-morph-modal/autoHeight--false.png +0 -0
- package/docs/assets/moni-morph-modal/autoHeight--true.png +0 -0
- package/docs/components/bottom-sheet.md +2 -1
- package/docs/components/morph-modal.md +16 -7
- package/docs/components/select.md +74 -74
- package/docs/components/text-field.md +75 -66
- package/docs/components/textarea.md +51 -51
- package/docs/llms.txt +3 -3
- package/package.json +1 -1
- package/src/components/_base/field-styles.ts +723 -637
- package/src/components/moni-bottom-sheet.test.ts +331 -0
- package/src/components/moni-bottom-sheet.ts +117 -29
- package/src/components/moni-morph-modal.test.ts +490 -413
- package/src/components/moni-morph-modal.ts +2274 -2162
- package/src/components/moni-select.test.ts +489 -466
- package/src/components/moni-select.ts +1963 -1815
- package/src/components/moni-text-field.test.ts +366 -342
- package/src/components/moni-text-field.ts +717 -645
- package/src/components/moni-textarea.test.ts +201 -197
- package/src/components/moni-textarea.ts +476 -460
- package/dist/cdn/chunks/if-defined-DdzvcoI7.js +0 -1
|
@@ -1,466 +1,489 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach, vi } from
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import type { MoniSelect } from
|
|
5
|
-
|
|
6
|
-
describe(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
|
|
2
|
+
import "./moni-select.js";
|
|
3
|
+
import "./moni-select-option.js";
|
|
4
|
+
import type { MoniSelect } from "./moni-select.js";
|
|
5
|
+
|
|
6
|
+
describe("moni-select", () => {
|
|
7
|
+
let el: MoniSelect;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
el = document.createElement("moni-select") as MoniSelect;
|
|
11
|
+
document.body.appendChild(el);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
el.remove();
|
|
16
|
+
vi.restoreAllMocks();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("renderiza el input activador (trigger)", async () => {
|
|
20
|
+
await el.updateComplete;
|
|
21
|
+
const input = el.shadowRoot?.querySelector("input");
|
|
22
|
+
expect(input).toBeTruthy();
|
|
23
|
+
expect(input?.getAttribute("readonly")).toBe("");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("aplica la clase small-round para un redondeado compacto", async () => {
|
|
27
|
+
el.shape = "small-round";
|
|
28
|
+
await el.updateComplete;
|
|
29
|
+
const field = el.shadowRoot?.querySelector(".field");
|
|
30
|
+
expect(field?.classList.contains("small-round")).toBe(true);
|
|
31
|
+
expect(field?.classList.contains("square")).toBe(false);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("analiza las opciones insertadas en slots (slotted)", async () => {
|
|
35
|
+
const opt1 = document.createElement("moni-select-option");
|
|
36
|
+
opt1.setAttribute("value", "v1");
|
|
37
|
+
opt1.textContent = "Option 1";
|
|
38
|
+
const opt2 = document.createElement("option");
|
|
39
|
+
opt2.setAttribute("value", "v2");
|
|
40
|
+
opt2.textContent = "Option 2";
|
|
41
|
+
|
|
42
|
+
el.appendChild(opt1);
|
|
43
|
+
el.appendChild(opt2);
|
|
44
|
+
|
|
45
|
+
// Esperar a slotchange y actualización
|
|
46
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
47
|
+
await el.updateComplete;
|
|
48
|
+
|
|
49
|
+
const items = el.shadowRoot?.querySelectorAll(".option-item");
|
|
50
|
+
expect(items?.length).toBe(2);
|
|
51
|
+
expect(items?.[0].textContent?.trim()).toBe("Option 1");
|
|
52
|
+
expect(items?.[1].textContent?.trim()).toBe("Option 2");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("alterna abrir/cerrar el dropdown al hacer clic", async () => {
|
|
56
|
+
await el.updateComplete;
|
|
57
|
+
const input = el.shadowRoot?.querySelector("input") as HTMLInputElement;
|
|
58
|
+
const menu = el.shadowRoot?.querySelector(".dropdown-menu");
|
|
59
|
+
|
|
60
|
+
expect(menu?.classList.contains("open")).toBe(false);
|
|
61
|
+
|
|
62
|
+
input.click();
|
|
63
|
+
await el.updateComplete;
|
|
64
|
+
expect(menu?.classList.contains("open")).toBe(true);
|
|
65
|
+
|
|
66
|
+
input.click();
|
|
67
|
+
await el.updateComplete;
|
|
68
|
+
expect(menu?.classList.contains("open")).toBe(false);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("dispara el evento input/change y actualiza el valor al seleccionar", async () => {
|
|
72
|
+
const opt1 = document.createElement("moni-select-option");
|
|
73
|
+
opt1.setAttribute("value", "v1");
|
|
74
|
+
opt1.textContent = "Option 1";
|
|
75
|
+
el.appendChild(opt1);
|
|
76
|
+
|
|
77
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
78
|
+
await el.updateComplete;
|
|
79
|
+
|
|
80
|
+
let eventFired = false;
|
|
81
|
+
el.addEventListener("change", () => {
|
|
82
|
+
eventFired = true;
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const input = el.shadowRoot?.querySelector("input") as HTMLInputElement;
|
|
86
|
+
input.click();
|
|
87
|
+
await el.updateComplete;
|
|
88
|
+
|
|
89
|
+
const item = el.shadowRoot?.querySelector(".option-item") as HTMLElement;
|
|
90
|
+
item.click();
|
|
91
|
+
await el.updateComplete;
|
|
92
|
+
|
|
93
|
+
expect(el.value).toBe("v1");
|
|
94
|
+
expect(eventFired).toBe(true);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("filtra opciones al buscar y escribir (searchable)", async () => {
|
|
98
|
+
el.searchable = true;
|
|
99
|
+
|
|
100
|
+
const opt1 = document.createElement("moni-select-option");
|
|
101
|
+
opt1.setAttribute("value", "apple");
|
|
102
|
+
opt1.textContent = "Apple";
|
|
103
|
+
const opt2 = document.createElement("moni-select-option");
|
|
104
|
+
opt2.setAttribute("value", "banana");
|
|
105
|
+
opt2.textContent = "Banana";
|
|
106
|
+
|
|
107
|
+
el.appendChild(opt1);
|
|
108
|
+
el.appendChild(opt2);
|
|
109
|
+
|
|
110
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
111
|
+
await el.updateComplete;
|
|
112
|
+
|
|
113
|
+
const input = el.shadowRoot?.querySelector("input") as HTMLInputElement;
|
|
114
|
+
input.click();
|
|
115
|
+
await el.updateComplete;
|
|
116
|
+
|
|
117
|
+
input.value = "ap";
|
|
118
|
+
input.dispatchEvent(new Event("input"));
|
|
119
|
+
await el.updateComplete;
|
|
120
|
+
|
|
121
|
+
const items = el.shadowRoot?.querySelectorAll(".option-item");
|
|
122
|
+
expect(items?.length).toBe(1);
|
|
123
|
+
expect(items?.[0].textContent?.trim()).toBe("Apple");
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("autoselecciona la opción cuando se escribe una coincidencia exacta", async () => {
|
|
127
|
+
el.searchable = true;
|
|
128
|
+
|
|
129
|
+
const opt1 = document.createElement("moni-select-option");
|
|
130
|
+
opt1.setAttribute("value", "apple");
|
|
131
|
+
opt1.textContent = "Apple";
|
|
132
|
+
const opt2 = document.createElement("moni-select-option");
|
|
133
|
+
opt2.setAttribute("value", "banana");
|
|
134
|
+
opt2.textContent = "Banana";
|
|
135
|
+
|
|
136
|
+
el.appendChild(opt1);
|
|
137
|
+
el.appendChild(opt2);
|
|
138
|
+
|
|
139
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
140
|
+
await el.updateComplete;
|
|
141
|
+
|
|
142
|
+
const input = el.shadowRoot?.querySelector("input") as HTMLInputElement;
|
|
143
|
+
input.click();
|
|
144
|
+
await el.updateComplete;
|
|
145
|
+
|
|
146
|
+
input.value = "banana";
|
|
147
|
+
input.dispatchEvent(new Event("input"));
|
|
148
|
+
await el.updateComplete;
|
|
149
|
+
|
|
150
|
+
expect(el.value).toBe("banana");
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("renderiza encabezados de subcategoría de grupo", async () => {
|
|
154
|
+
const opt1 = document.createElement("moni-select-option");
|
|
155
|
+
opt1.setAttribute("value", "v1");
|
|
156
|
+
opt1.setAttribute("group", "Fruits");
|
|
157
|
+
opt1.textContent = "Apple";
|
|
158
|
+
|
|
159
|
+
const opt2 = document.createElement("moni-select-option");
|
|
160
|
+
opt2.setAttribute("value", "v2");
|
|
161
|
+
opt2.setAttribute("group", "Vegetables");
|
|
162
|
+
opt2.textContent = "Carrot";
|
|
163
|
+
|
|
164
|
+
el.appendChild(opt1);
|
|
165
|
+
el.appendChild(opt2);
|
|
166
|
+
|
|
167
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
168
|
+
await el.updateComplete;
|
|
169
|
+
|
|
170
|
+
const headers = el.shadowRoot?.querySelectorAll(".group-header");
|
|
171
|
+
expect(headers?.length).toBe(2);
|
|
172
|
+
expect(headers?.[0].querySelector("span")?.textContent?.trim()).toBe(
|
|
173
|
+
"Fruits",
|
|
174
|
+
);
|
|
175
|
+
expect(headers?.[1].querySelector("span")?.textContent?.trim()).toBe(
|
|
176
|
+
"Vegetables",
|
|
177
|
+
);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("mantiene flyouts anidados cuando todos los niveles caben en pantalla", async () => {
|
|
181
|
+
vi.spyOn(window, "innerHeight", "get").mockReturnValue(900);
|
|
182
|
+
vi.spyOn(window, "innerWidth", "get").mockReturnValue(1600);
|
|
183
|
+
vi.spyOn(el, "getBoundingClientRect").mockReturnValue({
|
|
184
|
+
top: 80,
|
|
185
|
+
bottom: 136,
|
|
186
|
+
left: 100,
|
|
187
|
+
right: 300,
|
|
188
|
+
width: 200,
|
|
189
|
+
height: 56,
|
|
190
|
+
x: 100,
|
|
191
|
+
y: 80,
|
|
192
|
+
toJSON: () => ({}),
|
|
193
|
+
} as DOMRect);
|
|
194
|
+
|
|
195
|
+
const option = document.createElement("moni-select-option");
|
|
196
|
+
option.setAttribute("value", "nested");
|
|
197
|
+
option.setAttribute("group", "Nivel 1/Nivel 2");
|
|
198
|
+
option.textContent = "Opción anidada";
|
|
199
|
+
el.appendChild(option);
|
|
200
|
+
|
|
201
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
202
|
+
await el.updateComplete;
|
|
203
|
+
const input = el.shadowRoot?.querySelector("input") as HTMLInputElement;
|
|
204
|
+
input.click();
|
|
205
|
+
await el.updateComplete;
|
|
206
|
+
|
|
207
|
+
const menu = el.shadowRoot?.querySelector(".dropdown-menu") as HTMLElement;
|
|
208
|
+
expect(menu.classList.contains("inline-categories")).toBe(false);
|
|
209
|
+
expect(menu.querySelectorAll(".submenu").length).toBe(2);
|
|
210
|
+
expect(menu.querySelector(".submenu .submenu")).toBeTruthy();
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it("convierte subcategorías profundas en un drilldown navegable sin recortarlas", async () => {
|
|
214
|
+
vi.spyOn(window, "innerHeight", "get").mockReturnValue(800);
|
|
215
|
+
vi.spyOn(window, "innerWidth", "get").mockReturnValue(900);
|
|
216
|
+
vi.spyOn(el, "getBoundingClientRect").mockReturnValue({
|
|
217
|
+
top: 80,
|
|
218
|
+
bottom: 136,
|
|
219
|
+
left: 350,
|
|
220
|
+
right: 550,
|
|
221
|
+
width: 200,
|
|
222
|
+
height: 56,
|
|
223
|
+
x: 350,
|
|
224
|
+
y: 80,
|
|
225
|
+
toJSON: () => ({}),
|
|
226
|
+
} as DOMRect);
|
|
227
|
+
|
|
228
|
+
const option = document.createElement("moni-select-option");
|
|
229
|
+
option.setAttribute("value", "deep");
|
|
230
|
+
option.setAttribute("group", "Nivel 1/Nivel 2/Nivel 3/Nivel 4/Nivel 5");
|
|
231
|
+
option.textContent = "Opción profunda";
|
|
232
|
+
el.appendChild(option);
|
|
233
|
+
|
|
234
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
235
|
+
await el.updateComplete;
|
|
236
|
+
const input = el.shadowRoot?.querySelector("input") as HTMLInputElement;
|
|
237
|
+
input.click();
|
|
238
|
+
await el.updateComplete;
|
|
239
|
+
|
|
240
|
+
const menu = el.shadowRoot?.querySelector(".dropdown-menu") as HTMLElement;
|
|
241
|
+
expect(menu.classList.contains("inline-categories")).toBe(true);
|
|
242
|
+
expect(menu.classList.contains("scrollable")).toBe(true);
|
|
243
|
+
expect(menu.querySelector(".drilldown-wrapper")).toBeTruthy();
|
|
244
|
+
expect(menu.querySelector(".submenu")).toBeNull();
|
|
245
|
+
|
|
246
|
+
const firstGroup = menu.querySelector(".group-header") as HTMLElement;
|
|
247
|
+
firstGroup.click();
|
|
248
|
+
await el.updateComplete;
|
|
249
|
+
expect(menu.textContent).toContain("Regresar");
|
|
250
|
+
expect(menu.textContent).toContain("Nivel 2");
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it("limpia la selección cuando el input se vacía y clearable es true", async () => {
|
|
254
|
+
el.searchable = true;
|
|
255
|
+
el.clearable = true;
|
|
256
|
+
el.value = "apple";
|
|
257
|
+
|
|
258
|
+
const opt1 = document.createElement("moni-select-option");
|
|
259
|
+
opt1.setAttribute("value", "apple");
|
|
260
|
+
opt1.textContent = "Apple";
|
|
261
|
+
el.appendChild(opt1);
|
|
262
|
+
|
|
263
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
264
|
+
await el.updateComplete;
|
|
265
|
+
|
|
266
|
+
const input = el.shadowRoot?.querySelector("input") as HTMLInputElement;
|
|
267
|
+
input.click();
|
|
268
|
+
await el.updateComplete;
|
|
269
|
+
|
|
270
|
+
input.value = "";
|
|
271
|
+
input.dispatchEvent(new Event("input"));
|
|
272
|
+
await el.updateComplete;
|
|
273
|
+
|
|
274
|
+
expect(el.value).toBe("");
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it("renderiza el cajón bottom sheet cuando sheet es true", async () => {
|
|
278
|
+
el.sheet = true;
|
|
279
|
+
await el.updateComplete;
|
|
280
|
+
|
|
281
|
+
const drawer = el.shadowRoot?.querySelector(".sheet-drawer");
|
|
282
|
+
expect(drawer).toBeTruthy();
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it("aplica estilos de posicionamiento fijo cuando positioning es fixed", async () => {
|
|
286
|
+
el.positioning = "fixed";
|
|
287
|
+
await el.updateComplete;
|
|
288
|
+
|
|
289
|
+
const input = el.shadowRoot?.querySelector("input") as HTMLInputElement;
|
|
290
|
+
input.click();
|
|
291
|
+
await el.updateComplete;
|
|
292
|
+
|
|
293
|
+
const menu = el.shadowRoot?.querySelector(".dropdown-menu") as HTMLElement;
|
|
294
|
+
expect(menu?.style.position).toBe("fixed");
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it("cierra cualquier otro select antes de abrir uno nuevo", async () => {
|
|
298
|
+
const other = document.createElement("moni-select") as MoniSelect;
|
|
299
|
+
document.body.appendChild(other);
|
|
300
|
+
|
|
301
|
+
try {
|
|
302
|
+
await Promise.all([el.updateComplete, other.updateComplete]);
|
|
303
|
+
const firstInput = el.shadowRoot?.querySelector(
|
|
304
|
+
"input",
|
|
305
|
+
) as HTMLInputElement;
|
|
306
|
+
const secondInput = other.shadowRoot?.querySelector(
|
|
307
|
+
"input",
|
|
308
|
+
) as HTMLInputElement;
|
|
309
|
+
|
|
310
|
+
firstInput.click();
|
|
311
|
+
await el.updateComplete;
|
|
312
|
+
expect(
|
|
313
|
+
el.shadowRoot
|
|
314
|
+
?.querySelector(".dropdown-menu")
|
|
315
|
+
?.classList.contains("open"),
|
|
316
|
+
).toBe(true);
|
|
317
|
+
|
|
318
|
+
secondInput.click();
|
|
319
|
+
await Promise.all([el.updateComplete, other.updateComplete]);
|
|
320
|
+
expect(
|
|
321
|
+
el.shadowRoot
|
|
322
|
+
?.querySelector(".dropdown-menu")
|
|
323
|
+
?.classList.contains("open"),
|
|
324
|
+
).toBe(false);
|
|
325
|
+
expect(
|
|
326
|
+
other.shadowRoot
|
|
327
|
+
?.querySelector(".dropdown-menu")
|
|
328
|
+
?.classList.contains("open"),
|
|
329
|
+
).toBe(true);
|
|
330
|
+
} finally {
|
|
331
|
+
other.remove();
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
it("reinicia la búsqueda al abrir aunque exista una opción seleccionada", async () => {
|
|
336
|
+
el.searchable = true;
|
|
337
|
+
el.value = "banana";
|
|
338
|
+
|
|
339
|
+
for (const [value, label] of [
|
|
340
|
+
["apple", "Apple"],
|
|
341
|
+
["banana", "Banana"],
|
|
342
|
+
]) {
|
|
343
|
+
const option = document.createElement("moni-select-option");
|
|
344
|
+
option.setAttribute("value", value);
|
|
345
|
+
option.textContent = label;
|
|
346
|
+
el.appendChild(option);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
350
|
+
await el.updateComplete;
|
|
351
|
+
const input = el.shadowRoot?.querySelector("input") as HTMLInputElement;
|
|
352
|
+
expect(input.value).toBe("Banana");
|
|
353
|
+
|
|
354
|
+
input.click();
|
|
355
|
+
await el.updateComplete;
|
|
356
|
+
expect(input.value).toBe("");
|
|
357
|
+
expect(el.shadowRoot?.querySelectorAll(".option-item").length).toBe(2);
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
it("limita la altura según el viewport, permite un máximo manual y habilita scroll", async () => {
|
|
361
|
+
vi.spyOn(window, "innerHeight", "get").mockReturnValue(800);
|
|
362
|
+
vi.spyOn(window, "innerWidth", "get").mockReturnValue(1200);
|
|
363
|
+
vi.spyOn(el, "getBoundingClientRect").mockReturnValue({
|
|
364
|
+
top: 100,
|
|
365
|
+
bottom: 156,
|
|
366
|
+
left: 100,
|
|
367
|
+
right: 300,
|
|
368
|
+
width: 200,
|
|
369
|
+
height: 56,
|
|
370
|
+
x: 100,
|
|
371
|
+
y: 100,
|
|
372
|
+
toJSON: () => ({}),
|
|
373
|
+
} as DOMRect);
|
|
374
|
+
|
|
375
|
+
for (let index = 1; index <= 30; index += 1) {
|
|
376
|
+
const option = document.createElement("moni-select-option");
|
|
377
|
+
option.setAttribute("value", String(index));
|
|
378
|
+
option.textContent = `Option ${index}`;
|
|
379
|
+
el.appendChild(option);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
383
|
+
await el.updateComplete;
|
|
384
|
+
const input = el.shadowRoot?.querySelector("input") as HTMLInputElement;
|
|
385
|
+
input.click();
|
|
386
|
+
await el.updateComplete;
|
|
387
|
+
|
|
388
|
+
let menu = el.shadowRoot?.querySelector(".dropdown-menu") as HTMLElement;
|
|
389
|
+
expect(menu.style.maxHeight).toBe("436px");
|
|
390
|
+
expect(menu.classList.contains("scrollable")).toBe(true);
|
|
391
|
+
|
|
392
|
+
input.click();
|
|
393
|
+
el.dropdownMaxHeight = "120px";
|
|
394
|
+
await el.updateComplete;
|
|
395
|
+
input.click();
|
|
396
|
+
await el.updateComplete;
|
|
397
|
+
menu = el.shadowRoot?.querySelector(".dropdown-menu") as HTMLElement;
|
|
398
|
+
expect(menu.style.maxHeight).toContain("120px");
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
it("cambia hacia arriba y recalcula el alto cuando no hay espacio debajo", async () => {
|
|
402
|
+
vi.spyOn(window, "innerHeight", "get").mockReturnValue(800);
|
|
403
|
+
vi.spyOn(window, "innerWidth", "get").mockReturnValue(1200);
|
|
404
|
+
vi.spyOn(el, "getBoundingClientRect").mockReturnValue({
|
|
405
|
+
top: 650,
|
|
406
|
+
bottom: 706,
|
|
407
|
+
left: 100,
|
|
408
|
+
right: 300,
|
|
409
|
+
width: 200,
|
|
410
|
+
height: 56,
|
|
411
|
+
x: 100,
|
|
412
|
+
y: 650,
|
|
413
|
+
toJSON: () => ({}),
|
|
414
|
+
} as DOMRect);
|
|
415
|
+
|
|
416
|
+
await el.updateComplete;
|
|
417
|
+
const input = el.shadowRoot?.querySelector("input") as HTMLInputElement;
|
|
418
|
+
input.click();
|
|
419
|
+
await el.updateComplete;
|
|
420
|
+
|
|
421
|
+
const menu = el.shadowRoot?.querySelector(".dropdown-menu") as HTMLElement;
|
|
422
|
+
expect(menu.classList.contains("placement-top")).toBe(true);
|
|
423
|
+
expect(menu.style.maxHeight).toBe("442px");
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
it("usa la capa superior cuando positioning=body", async () => {
|
|
427
|
+
el.positioning = "body";
|
|
428
|
+
await el.updateComplete;
|
|
429
|
+
|
|
430
|
+
const menu = el.shadowRoot?.querySelector(".dropdown-menu") as HTMLElement;
|
|
431
|
+
expect(menu.getAttribute("popover")).toBe("manual");
|
|
432
|
+
|
|
433
|
+
const input = el.shadowRoot?.querySelector("input") as HTMLInputElement;
|
|
434
|
+
input.click();
|
|
435
|
+
await el.updateComplete;
|
|
436
|
+
expect(menu.style.position).toBe("fixed");
|
|
437
|
+
expect(menu.classList.contains("open")).toBe(true);
|
|
438
|
+
});
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
describe("moni-select · nombre accesible", () => {
|
|
442
|
+
it("asocia la etiqueta con el input mediante for/id", async () => {
|
|
443
|
+
const el = document.createElement("moni-select") as MoniSelect;
|
|
444
|
+
el.label = "Estado";
|
|
445
|
+
document.body.appendChild(el);
|
|
446
|
+
await el.updateComplete;
|
|
447
|
+
|
|
448
|
+
const input = el.shadowRoot?.querySelector("input");
|
|
449
|
+
const label = el.shadowRoot?.querySelector("label");
|
|
450
|
+
expect(input?.id).toBe("input");
|
|
451
|
+
expect(label?.getAttribute("for")).toBe("input");
|
|
452
|
+
expect(input?.nextElementSibling).toBe(label);
|
|
453
|
+
el.remove();
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
describe("moni-select · required", () => {
|
|
458
|
+
/*
|
|
459
|
+
* Su input visible es readonly y por tanto queda fuera de la validación de
|
|
460
|
+
* restricciones, así que `required` se declara en el host.
|
|
461
|
+
*/
|
|
462
|
+
it("declara valueMissing mientras no haya valor", async () => {
|
|
463
|
+
// Igual que en text-field: jsdom no expone checkValidity() aquí.
|
|
464
|
+
const calls: Array<Record<string, unknown>> = [];
|
|
465
|
+
const originalAttach = HTMLElement.prototype.attachInternals;
|
|
466
|
+
HTMLElement.prototype.attachInternals = function spy(this: HTMLElement) {
|
|
467
|
+
const internals = originalAttach.call(this);
|
|
468
|
+
const setValidity = internals.setValidity.bind(internals);
|
|
469
|
+
internals.setValidity = ((flags, message, anchor) => {
|
|
470
|
+
calls.push({ valueMissing: flags?.valueMissing === true });
|
|
471
|
+
return setValidity(flags, message, anchor);
|
|
472
|
+
}) as typeof internals.setValidity;
|
|
473
|
+
return internals;
|
|
474
|
+
};
|
|
475
|
+
const el = document.createElement("moni-select") as MoniSelect;
|
|
476
|
+
HTMLElement.prototype.attachInternals = originalAttach;
|
|
477
|
+
|
|
478
|
+
el.required = true;
|
|
479
|
+
document.body.appendChild(el);
|
|
480
|
+
await el.updateComplete;
|
|
481
|
+
expect(calls.some((c) => c.valueMissing === true)).toBe(true);
|
|
482
|
+
|
|
483
|
+
calls.length = 0;
|
|
484
|
+
el.value = "uno";
|
|
485
|
+
await el.updateComplete;
|
|
486
|
+
expect(calls.at(-1)).toEqual({ valueMissing: false });
|
|
487
|
+
el.remove();
|
|
488
|
+
});
|
|
489
|
+
});
|