@aquera/nile-elements 2.0.12 → 2.0.14
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/README.md +13 -0
- package/dist/index.js +132 -134
- package/dist/nile-auto-complete/nile-auto-complete.css.cjs.js +1 -1
- package/dist/nile-auto-complete/nile-auto-complete.css.cjs.js.map +1 -1
- package/dist/nile-auto-complete/nile-auto-complete.css.esm.js +5 -2
- package/dist/nile-chip/nile-chip.css.cjs.js +1 -1
- package/dist/nile-chip/nile-chip.css.cjs.js.map +1 -1
- package/dist/nile-chip/nile-chip.css.esm.js +2 -0
- package/dist/nile-combobox/nile-combobox.css.cjs.js +1 -1
- package/dist/nile-combobox/nile-combobox.css.cjs.js.map +1 -1
- package/dist/nile-combobox/nile-combobox.css.esm.js +9 -9
- package/dist/nile-command-menu/nile-command-menu.css.cjs.js +1 -1
- package/dist/nile-command-menu/nile-command-menu.css.cjs.js.map +1 -1
- package/dist/nile-command-menu/nile-command-menu.css.esm.js +5 -5
- package/dist/nile-command-menu-item/nile-command-menu-item.css.cjs.js +1 -1
- package/dist/nile-command-menu-item/nile-command-menu-item.css.cjs.js.map +1 -1
- package/dist/nile-command-menu-item/nile-command-menu-item.css.esm.js +2 -2
- package/dist/nile-option/nile-option.css.cjs.js +1 -1
- package/dist/nile-option/nile-option.css.cjs.js.map +1 -1
- package/dist/nile-option/nile-option.css.esm.js +1 -1
- package/dist/nile-select/nile-select.cjs.js +2 -2
- package/dist/nile-select/nile-select.cjs.js.map +1 -1
- package/dist/nile-select/nile-select.css.cjs.js +1 -1
- package/dist/nile-select/nile-select.css.cjs.js.map +1 -1
- package/dist/nile-select/nile-select.css.esm.js +19 -24
- package/dist/nile-select/nile-select.esm.js +43 -42
- package/dist/nile-select/virtual-scroll-helper.cjs.js +1 -1
- package/dist/nile-select/virtual-scroll-helper.cjs.js.map +1 -1
- package/dist/nile-select/virtual-scroll-helper.esm.js +2 -0
- package/dist/nile-virtual-select/nile-virtual-select.cjs.js +4 -4
- package/dist/nile-virtual-select/nile-virtual-select.cjs.js.map +1 -1
- package/dist/nile-virtual-select/nile-virtual-select.css.cjs.js +1 -1
- package/dist/nile-virtual-select/nile-virtual-select.css.cjs.js.map +1 -1
- package/dist/nile-virtual-select/nile-virtual-select.css.esm.js +20 -25
- package/dist/nile-virtual-select/nile-virtual-select.esm.js +26 -26
- package/dist/src/nile-auto-complete/nile-auto-complete.css.js +3 -0
- package/dist/src/nile-auto-complete/nile-auto-complete.css.js.map +1 -1
- package/dist/src/nile-chip/nile-chip.css.js +2 -0
- package/dist/src/nile-chip/nile-chip.css.js.map +1 -1
- package/dist/src/nile-combobox/nile-combobox.css.js +9 -9
- package/dist/src/nile-combobox/nile-combobox.css.js.map +1 -1
- package/dist/src/nile-command-menu/nile-command-menu.css.js +5 -5
- package/dist/src/nile-command-menu/nile-command-menu.css.js.map +1 -1
- package/dist/src/nile-command-menu-item/nile-command-menu-item.css.js +2 -2
- package/dist/src/nile-command-menu-item/nile-command-menu-item.css.js.map +1 -1
- package/dist/src/nile-option/nile-option.css.js +1 -1
- package/dist/src/nile-option/nile-option.css.js.map +1 -1
- package/dist/src/nile-select/nile-select.css.js +19 -24
- package/dist/src/nile-select/nile-select.css.js.map +1 -1
- package/dist/src/nile-select/nile-select.d.ts +18 -2
- package/dist/src/nile-select/nile-select.js +226 -64
- package/dist/src/nile-select/nile-select.js.map +1 -1
- package/dist/src/nile-select/nile-select.test.d.ts +1 -0
- package/dist/src/nile-select/nile-select.test.js +896 -17
- package/dist/src/nile-select/nile-select.test.js.map +1 -1
- package/dist/src/nile-select/virtual-scroll-helper.js +2 -0
- package/dist/src/nile-select/virtual-scroll-helper.js.map +1 -1
- package/dist/src/nile-virtual-select/nile-virtual-select.css.js +20 -25
- package/dist/src/nile-virtual-select/nile-virtual-select.css.js.map +1 -1
- package/dist/src/nile-virtual-select/nile-virtual-select.d.ts +10 -2
- package/dist/src/nile-virtual-select/nile-virtual-select.js +142 -30
- package/dist/src/nile-virtual-select/nile-virtual-select.js.map +1 -1
- package/dist/src/nile-virtual-select/nile-virtual-select.test.d.ts +1 -0
- package/dist/src/nile-virtual-select/nile-virtual-select.test.js +331 -16
- package/dist/src/nile-virtual-select/nile-virtual-select.test.js.map +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/nile-auto-complete/nile-auto-complete.css.ts +3 -0
- package/src/nile-chip/nile-chip.css.ts +2 -0
- package/src/nile-combobox/nile-combobox.css.ts +9 -9
- package/src/nile-command-menu/nile-command-menu.css.ts +5 -5
- package/src/nile-command-menu-item/nile-command-menu-item.css.ts +2 -2
- package/src/nile-option/nile-option.css.ts +1 -1
- package/src/nile-select/nile-select.css.ts +19 -24
- package/src/nile-select/nile-select.test.ts +1112 -17
- package/src/nile-select/nile-select.ts +237 -67
- package/src/nile-select/virtual-scroll-helper.ts +2 -0
- package/src/nile-virtual-select/nile-virtual-select.css.ts +20 -25
- package/src/nile-virtual-select/nile-virtual-select.test.ts +404 -16
- package/src/nile-virtual-select/nile-virtual-select.ts +200 -79
- package/vscode-html-custom-data.json +9 -4
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { aTimeout, expect, fixture, html, nextFrame } from '@open-wc/testing';
|
|
1
|
+
import { aTimeout, expect, fixture, html, nextFrame, waitUntil } from '@open-wc/testing';
|
|
2
2
|
import './nile-virtual-select';
|
|
3
|
+
import '../nile-input/nile-input';
|
|
3
4
|
describe('NileVirtualSelect', () => {
|
|
4
5
|
it('1. renders', async () => { const el = await fixture(html `<nile-virtual-select></nile-virtual-select>`); expect(el).to.exist; });
|
|
5
6
|
it('2. shadow root', async () => { const el = await fixture(html `<nile-virtual-select></nile-virtual-select>`); expect(el.shadowRoot).to.not.be.null; });
|
|
@@ -131,7 +132,7 @@ describe('NileVirtualSelect chip fitting behaviour matrix', () => {
|
|
|
131
132
|
}
|
|
132
133
|
it('V1. multiple + no max-options-visible + autoResize=false renders fitted chips', async () => {
|
|
133
134
|
const host = await fixture(html `<div style="width: 320px">
|
|
134
|
-
<nile-virtual-select multiple .data=${DATA} .value=${LABELS}>
|
|
135
|
+
<nile-virtual-select showtooltip multiple .data=${DATA} .value=${LABELS}>
|
|
135
136
|
</nile-virtual-select>
|
|
136
137
|
</div>`);
|
|
137
138
|
const el = host.querySelector('nile-virtual-select');
|
|
@@ -143,7 +144,7 @@ describe('NileVirtualSelect chip fitting behaviour matrix', () => {
|
|
|
143
144
|
});
|
|
144
145
|
it('V2. multiple + no max-options-visible + autoResize=true refits when the container resizes', async () => {
|
|
145
146
|
const host = await fixture(html `<div style="width: 480px">
|
|
146
|
-
<nile-virtual-select multiple autoresize .data=${DATA} .value=${LABELS}>
|
|
147
|
+
<nile-virtual-select showtooltip multiple autoresize .data=${DATA} .value=${LABELS}>
|
|
147
148
|
</nile-virtual-select>
|
|
148
149
|
</div>`);
|
|
149
150
|
const el = host.querySelector('nile-virtual-select');
|
|
@@ -158,7 +159,7 @@ describe('NileVirtualSelect chip fitting behaviour matrix', () => {
|
|
|
158
159
|
});
|
|
159
160
|
it('V3. explicit max-options-visible switches to fixed-count layout', async () => {
|
|
160
161
|
const host = await fixture(html `<div style="width: 320px">
|
|
161
|
-
<nile-virtual-select
|
|
162
|
+
<nile-virtual-select showtooltip
|
|
162
163
|
multiple
|
|
163
164
|
max-options-visible="2"
|
|
164
165
|
.data=${DATA}
|
|
@@ -174,7 +175,7 @@ describe('NileVirtualSelect chip fitting behaviour matrix', () => {
|
|
|
174
175
|
});
|
|
175
176
|
it('V3b. max-options-visible set as a property also switches to fixed-count layout', async () => {
|
|
176
177
|
const host = await fixture(html `<div style="width: 320px">
|
|
177
|
-
<nile-virtual-select multiple .data=${DATA} .value=${LABELS}>
|
|
178
|
+
<nile-virtual-select showtooltip multiple .data=${DATA} .value=${LABELS}>
|
|
178
179
|
</nile-virtual-select>
|
|
179
180
|
</div>`);
|
|
180
181
|
const el = host.querySelector('nile-virtual-select');
|
|
@@ -187,7 +188,7 @@ describe('NileVirtualSelect chip fitting behaviour matrix', () => {
|
|
|
187
188
|
});
|
|
188
189
|
it('V3c. the default max-options-visible is still 3 and reading it does not opt out', async () => {
|
|
189
190
|
const host = await fixture(html `<div style="width: 320px">
|
|
190
|
-
<nile-virtual-select multiple .data=${DATA} .value=${LABELS}>
|
|
191
|
+
<nile-virtual-select showtooltip multiple .data=${DATA} .value=${LABELS}>
|
|
191
192
|
</nile-virtual-select>
|
|
192
193
|
</div>`);
|
|
193
194
|
const el = host.querySelector('nile-virtual-select');
|
|
@@ -226,9 +227,9 @@ describe('NileVirtualSelect chip fitting behaviour matrix', () => {
|
|
|
226
227
|
});
|
|
227
228
|
it('V7. nile-select and nile-virtual-select agree on when fitting is active', async () => {
|
|
228
229
|
const host = await fixture(html `<div style="width: 320px">
|
|
229
|
-
<nile-virtual-select multiple .data=${DATA} .value=${LABELS}>
|
|
230
|
+
<nile-virtual-select showtooltip multiple .data=${DATA} .value=${LABELS}>
|
|
230
231
|
</nile-virtual-select>
|
|
231
|
-
<nile-virtual-select
|
|
232
|
+
<nile-virtual-select showtooltip
|
|
232
233
|
multiple
|
|
233
234
|
max-options-visible="2"
|
|
234
235
|
.data=${DATA}
|
|
@@ -264,16 +265,21 @@ describe('NileVirtualSelect chip fitting behaviour matrix', () => {
|
|
|
264
265
|
return content.scrollWidth > content.clientWidth + 1;
|
|
265
266
|
}).length;
|
|
266
267
|
}
|
|
267
|
-
it('V12. without showtooltip
|
|
268
|
+
it('V12. without showtooltip the pre-2.0.9 chip row is used', async () => {
|
|
268
269
|
const host = await fixture(html `<div style="width: 480px">
|
|
269
270
|
<nile-virtual-select multiple .data=${DATA} .value=${LABELS}></nile-virtual-select>
|
|
270
271
|
</div>`);
|
|
271
272
|
const el = host.querySelector('nile-virtual-select');
|
|
272
273
|
await settle(el);
|
|
274
|
+
await aTimeout(20);
|
|
275
|
+
await settle(el);
|
|
273
276
|
expect(el.showTooltip).to.be.false;
|
|
274
|
-
expect(
|
|
275
|
-
|
|
276
|
-
expect(
|
|
277
|
+
expect(tagsRoot(el).classList.contains('select__tags--fitted')).to.be.false;
|
|
278
|
+
expect(el.shadowRoot.querySelector('button.select__tags-count')).to.not.exist;
|
|
279
|
+
expect(chips(el).every(chip => !chip.style.maxWidth)).to.be.true;
|
|
280
|
+
const overflowCount = el.shadowRoot.querySelector('span.select__tags-count');
|
|
281
|
+
expect(overflowCount).to.exist;
|
|
282
|
+
expect(overflowCount.textContent).to.contain('More');
|
|
277
283
|
});
|
|
278
284
|
it('V13. showtooltip is what allows a fitted chip to be truncated', async () => {
|
|
279
285
|
const host = await fixture(html `<div style="width: 480px">
|
|
@@ -289,7 +295,7 @@ describe('NileVirtualSelect chip fitting behaviour matrix', () => {
|
|
|
289
295
|
expect(el.showTooltip).to.be.true;
|
|
290
296
|
expect(clippedChipCount(el)).to.be.greaterThan(0);
|
|
291
297
|
});
|
|
292
|
-
it('V8. no showtooltip attribute
|
|
298
|
+
it('V8. no showtooltip attribute renders no chip tooltips', async () => {
|
|
293
299
|
const host = await fixture(html `<div style="width: 200px">
|
|
294
300
|
<nile-virtual-select multiple .data=${DATA} .value=${LABELS}></nile-virtual-select>
|
|
295
301
|
</div>`);
|
|
@@ -297,8 +303,7 @@ describe('NileVirtualSelect chip fitting behaviour matrix', () => {
|
|
|
297
303
|
await settle(el);
|
|
298
304
|
expect(el.showTooltip).to.be.false;
|
|
299
305
|
expect(el.hasAttribute('showtooltip')).to.be.false;
|
|
300
|
-
expect(tips(el).length).to.
|
|
301
|
-
expect(liveTips(el).length).to.equal(0);
|
|
306
|
+
expect(tips(el).length).to.equal(0);
|
|
302
307
|
});
|
|
303
308
|
it('V9. showtooltip shows the chip tooltip', async () => {
|
|
304
309
|
const host = await fixture(html `<div style="width: 200px">
|
|
@@ -327,7 +332,7 @@ describe('NileVirtualSelect chip fitting behaviour matrix', () => {
|
|
|
327
332
|
});
|
|
328
333
|
it('V11. the overflow button label and text never disagree, including first paint', async () => {
|
|
329
334
|
const host = await fixture(html `<div style="width: 220px">
|
|
330
|
-
<nile-virtual-select multiple .data=${DATA} .value=${LABELS}>
|
|
335
|
+
<nile-virtual-select showtooltip multiple .data=${DATA} .value=${LABELS}>
|
|
331
336
|
</nile-virtual-select>
|
|
332
337
|
</div>`);
|
|
333
338
|
const el = host.querySelector('nile-virtual-select');
|
|
@@ -356,5 +361,315 @@ describe('NileVirtualSelect chip fitting behaviour matrix', () => {
|
|
|
356
361
|
expect(el.shadowRoot.querySelector('button.select__tags-count')).to.not
|
|
357
362
|
.exist;
|
|
358
363
|
});
|
|
364
|
+
it('G1. default chips are not capped by the 2.0.9 chip styles; showtooltip caps them', async () => {
|
|
365
|
+
const host = await fixture(html `<div style="width: 480px">
|
|
366
|
+
<nile-virtual-select multiple .data=${DATA} .value=${LABELS.slice(0, 2)}></nile-virtual-select>
|
|
367
|
+
<nile-virtual-select multiple showtooltip .data=${DATA} .value=${LABELS.slice(0, 2)}></nile-virtual-select>
|
|
368
|
+
</div>`);
|
|
369
|
+
const [plain, tooltip] = Array.from(host.querySelectorAll('nile-virtual-select'));
|
|
370
|
+
await settle(plain);
|
|
371
|
+
await settle(tooltip);
|
|
372
|
+
const [plainChip] = chips(plain);
|
|
373
|
+
const [tooltipChip] = chips(tooltip);
|
|
374
|
+
expect(plainChip, 'plain select rendered no chips').to.exist;
|
|
375
|
+
expect(tooltipChip, 'tooltip select rendered no chips').to.exist;
|
|
376
|
+
expect(getComputedStyle(plainChip).maxWidth).to.equal('none');
|
|
377
|
+
expect(getComputedStyle(tooltipChip).maxWidth).to.not.equal('none');
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
describe('NileVirtualSelect chipMinWidth / chipMaxWidth attributes', () => {
|
|
381
|
+
const LABELS = ['Engineering Operations Team', 'Human Resources Department'];
|
|
382
|
+
const DATA = LABELS.map(label => ({ label, value: label }));
|
|
383
|
+
async function settle(el) {
|
|
384
|
+
await el.updateComplete;
|
|
385
|
+
await nextFrame();
|
|
386
|
+
await nextFrame();
|
|
387
|
+
await el.updateComplete;
|
|
388
|
+
}
|
|
389
|
+
const firstChip = (el) => el.shadowRoot.querySelector('.select__tags nile-tag');
|
|
390
|
+
it('R4a. defaults are 110 / 180 and are not written to the host', async () => {
|
|
391
|
+
const el = await fixture(html `<nile-virtual-select multiple .data=${DATA}></nile-virtual-select>`);
|
|
392
|
+
await settle(el);
|
|
393
|
+
expect(el.chipMinWidth).to.equal(110);
|
|
394
|
+
expect(el.chipMaxWidth).to.equal(180);
|
|
395
|
+
expect(el.hasAttribute('chipminwidth')).to.be.false;
|
|
396
|
+
expect(el.hasAttribute('chipmaxwidth')).to.be.false;
|
|
397
|
+
});
|
|
398
|
+
it('R4b. attributes still set the properties; properties do not add attributes', async () => {
|
|
399
|
+
const el = await fixture(html `<nile-virtual-select multiple .data=${DATA} chipminwidth="90" chipmaxwidth="150"></nile-virtual-select>`);
|
|
400
|
+
await settle(el);
|
|
401
|
+
expect(el.chipMinWidth).to.equal(90);
|
|
402
|
+
expect(el.chipMaxWidth).to.equal(150);
|
|
403
|
+
const plain = await fixture(html `<nile-virtual-select multiple .data=${DATA}></nile-virtual-select>`);
|
|
404
|
+
plain.chipMaxWidth = 140;
|
|
405
|
+
await settle(plain);
|
|
406
|
+
expect(plain.chipMaxWidth).to.equal(140);
|
|
407
|
+
expect(plain.hasAttribute('chipmaxwidth')).to.be.false;
|
|
408
|
+
});
|
|
409
|
+
it('R4c. showtooltip still caps squeezed chips at chipMaxWidth', async () => {
|
|
410
|
+
const host = await fixture(html `<div style="width: 300px">
|
|
411
|
+
<nile-virtual-select multiple showtooltip chipmaxwidth="150" .data=${DATA} .value=${LABELS}></nile-virtual-select>
|
|
412
|
+
</div>`);
|
|
413
|
+
const el = host.querySelector('nile-virtual-select');
|
|
414
|
+
await settle(el);
|
|
415
|
+
const chip = firstChip(el);
|
|
416
|
+
expect(chip, 'select rendered no chips').to.exist;
|
|
417
|
+
expect(chip.getBoundingClientRect().width).to.be.within(1, 150.5);
|
|
418
|
+
el.chipMaxWidth = 120;
|
|
419
|
+
await settle(el);
|
|
420
|
+
await nextFrame();
|
|
421
|
+
expect(firstChip(el).getBoundingClientRect().width).to.be.within(1, 120.5);
|
|
422
|
+
});
|
|
423
|
+
});
|
|
424
|
+
describe('NileVirtualSelect footer width with and without noWidthSync', () => {
|
|
425
|
+
const DATA = [{ label: 'a', value: 'a' }, { label: 'b', value: 'b' }];
|
|
426
|
+
async function openSelect(width, noWidthSync, portal = false) {
|
|
427
|
+
const host = await fixture(html `<div style="width: ${width}px">
|
|
428
|
+
<nile-virtual-select multiple .noWidthSync=${noWidthSync} .portal=${portal} .data=${DATA} .value=${['a']}></nile-virtual-select>
|
|
429
|
+
</div>`);
|
|
430
|
+
const el = host.querySelector('nile-virtual-select');
|
|
431
|
+
await el.updateComplete;
|
|
432
|
+
el.open = true;
|
|
433
|
+
const listbox = () => (portal
|
|
434
|
+
? document.body.querySelector('.nile-virtual-select-portal-append #listbox')
|
|
435
|
+
: el.shadowRoot.querySelector('#listbox'));
|
|
436
|
+
await waitUntil(() => (listbox()?.getBoundingClientRect().width ?? 0) > 0, 'listbox never opened');
|
|
437
|
+
await nextFrame();
|
|
438
|
+
const box = listbox();
|
|
439
|
+
const footer = box.querySelector('.select__footer');
|
|
440
|
+
const combobox = el.shadowRoot.querySelector('[part~="combobox"]');
|
|
441
|
+
return { el, listbox: box, footer, combobox };
|
|
442
|
+
}
|
|
443
|
+
const labelShown = (footer, selector) => getComputedStyle(footer.querySelector(selector)).display !== 'none';
|
|
444
|
+
before(() => document.documentElement.style.setProperty('--nile-display-flex', 'flex'));
|
|
445
|
+
after(() => document.documentElement.style.removeProperty('--nile-display-flex'));
|
|
446
|
+
afterEach(async () => {
|
|
447
|
+
document.body.querySelectorAll('.nile-virtual-select-portal-append').forEach(n => n.remove());
|
|
448
|
+
document.head.querySelectorAll('style[id^="nile-virtual-select-styles-"]').forEach(n => n.remove());
|
|
449
|
+
});
|
|
450
|
+
for (const width of [120, 400]) {
|
|
451
|
+
it(`R3a. noWidthSync + multiple at ${width}px does not collapse and shows the whole footer`, async () => {
|
|
452
|
+
const { listbox, footer } = await openSelect(width, true);
|
|
453
|
+
expect(listbox.offsetWidth).to.be.greaterThan(60);
|
|
454
|
+
expect(listbox.offsetWidth).to.be.at.least(footer.offsetWidth);
|
|
455
|
+
expect(footer.scrollWidth).to.be.at.most(footer.clientWidth + 1);
|
|
456
|
+
expect(labelShown(footer, '.select__clear .select__footer-label')).to.be.true;
|
|
457
|
+
expect(labelShown(footer, '.select__footer-action .select__footer-label')).to.be.true;
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
it('R3b. width sync at normal width keeps the dropdown as wide as the trigger', async () => {
|
|
461
|
+
const { listbox, combobox, footer } = await openSelect(400, false);
|
|
462
|
+
expect(Math.abs(listbox.offsetWidth - combobox.offsetWidth)).to.be.below(2);
|
|
463
|
+
expect(labelShown(footer, '.select__clear .select__footer-label')).to.be.true;
|
|
464
|
+
});
|
|
465
|
+
it('R3c. width sync at a narrow width still collapses the footer labels (container queries kept)', async () => {
|
|
466
|
+
const { listbox, combobox, footer } = await openSelect(130, false);
|
|
467
|
+
expect(Math.abs(listbox.offsetWidth - combobox.offsetWidth)).to.be.below(2);
|
|
468
|
+
expect(labelShown(footer, '.select__clear .select__footer-label')).to.be.false;
|
|
469
|
+
});
|
|
470
|
+
for (const noWidthSync of [false, true]) {
|
|
471
|
+
it(`R3d. portal (noWidthSync=${noWidthSync}) pins the width and keeps the narrow-footer queries`, async () => {
|
|
472
|
+
const { el, listbox, combobox, footer } = await openSelect(130, noWidthSync, true);
|
|
473
|
+
expect(listbox.offsetWidth).to.be.within(combobox.offsetWidth - 8, combobox.offsetWidth);
|
|
474
|
+
expect(labelShown(footer, '.select__clear .select__footer-label')).to.be.false;
|
|
475
|
+
el.open = false;
|
|
476
|
+
await waitUntil(() => !document.body.querySelector('.nile-virtual-select-portal-append'), 'portal not cleaned up');
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
describe('NileVirtualSelect showtooltip chip layout taken while hidden', () => {
|
|
481
|
+
const LABELS = ['Engineering Operations Team', 'Human Resources Department'];
|
|
482
|
+
const DATA = LABELS.map(label => ({ label, value: label }));
|
|
483
|
+
async function frames(n = 3) {
|
|
484
|
+
for (let i = 0; i < n; i++)
|
|
485
|
+
await nextFrame();
|
|
486
|
+
}
|
|
487
|
+
const chipsOf = (el) => Array.from(el.shadowRoot.querySelectorAll('.select__tags nile-tag'));
|
|
488
|
+
async function hiddenSelect(showTooltip) {
|
|
489
|
+
const host = await fixture(html `<div style="display: none; width: 600px">
|
|
490
|
+
<nile-virtual-select multiple ?showtooltip=${showTooltip} .data=${DATA} .value=${LABELS}></nile-virtual-select>
|
|
491
|
+
</div>`);
|
|
492
|
+
const el = host.querySelector('nile-virtual-select');
|
|
493
|
+
await el.updateComplete;
|
|
494
|
+
await frames();
|
|
495
|
+
await el.updateComplete;
|
|
496
|
+
return { host, el };
|
|
497
|
+
}
|
|
498
|
+
it('R5a. showtooltip chips measured while hidden get real widths once shown', async () => {
|
|
499
|
+
const { host, el } = await hiddenSelect(true);
|
|
500
|
+
host.style.display = 'block';
|
|
501
|
+
await frames(4);
|
|
502
|
+
await el.updateComplete;
|
|
503
|
+
const chips = chipsOf(el);
|
|
504
|
+
expect(chips.length).to.equal(2);
|
|
505
|
+
for (const chip of chips) {
|
|
506
|
+
expect(chip.style.width).to.not.equal('0px');
|
|
507
|
+
expect(chip.offsetWidth).to.be.greaterThan(50);
|
|
508
|
+
}
|
|
509
|
+
});
|
|
510
|
+
it('R5c. without showtooltip a hidden-then-shown select is unaffected (no inline widths)', async () => {
|
|
511
|
+
const { host, el } = await hiddenSelect(false);
|
|
512
|
+
host.style.display = 'block';
|
|
513
|
+
await frames(4);
|
|
514
|
+
for (const chip of chipsOf(el)) {
|
|
515
|
+
expect(chip.style.width).to.equal('');
|
|
516
|
+
expect(chip.offsetWidth).to.be.greaterThan(50);
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
});
|
|
520
|
+
describe('NileVirtualSelect 2.0.8 compatibility matrix', () => {
|
|
521
|
+
const DATA = ['a', 'b', 'c'].map(v => ({ label: `L${v}`, value: v }));
|
|
522
|
+
async function settle(el) {
|
|
523
|
+
await el.updateComplete;
|
|
524
|
+
await nextFrame();
|
|
525
|
+
await nextFrame();
|
|
526
|
+
await el.updateComplete;
|
|
527
|
+
}
|
|
528
|
+
const chipCount = (el) => el.shadowRoot.querySelectorAll('.select__tags nile-tag').length;
|
|
529
|
+
function record(el, names) {
|
|
530
|
+
const seen = [];
|
|
531
|
+
names.forEach(name => el.addEventListener(name, () => seen.push(name)));
|
|
532
|
+
return seen;
|
|
533
|
+
}
|
|
534
|
+
it('CV1. a value set before data arrives is kept, and survives the data being replaced', async () => {
|
|
535
|
+
const el = await fixture(html `<nile-virtual-select multiple .value=${['b']}></nile-virtual-select>`);
|
|
536
|
+
await settle(el);
|
|
537
|
+
el.data = DATA;
|
|
538
|
+
await settle(el);
|
|
539
|
+
expect(el.value).to.deep.equal(['b']);
|
|
540
|
+
expect(chipCount(el)).to.equal(1);
|
|
541
|
+
el.data = [...DATA];
|
|
542
|
+
await settle(el);
|
|
543
|
+
expect(el.value).to.deep.equal(['b']);
|
|
544
|
+
expect(chipCount(el)).to.equal(1);
|
|
545
|
+
});
|
|
546
|
+
it('CV2. programmatic value updates the chips', async () => {
|
|
547
|
+
const el = await fixture(html `<nile-virtual-select multiple .data=${DATA}></nile-virtual-select>`);
|
|
548
|
+
await settle(el);
|
|
549
|
+
el.value = ['a', 'c'];
|
|
550
|
+
await settle(el);
|
|
551
|
+
expect(chipCount(el)).to.equal(2);
|
|
552
|
+
el.value = [];
|
|
553
|
+
await settle(el);
|
|
554
|
+
expect(chipCount(el)).to.equal(0);
|
|
555
|
+
});
|
|
556
|
+
it('CV3. removing a chip updates the value and emits tag-remove', async () => {
|
|
557
|
+
const el = await fixture(html `<nile-virtual-select multiple .data=${DATA} .value=${['a', 'b']}></nile-virtual-select>`);
|
|
558
|
+
await settle(el);
|
|
559
|
+
const seen = record(el, ['nile-tag-remove']);
|
|
560
|
+
const chip = el.shadowRoot.querySelector('.select__tags nile-tag');
|
|
561
|
+
expect(chip, 'select rendered no chips').to.exist;
|
|
562
|
+
chip.dispatchEvent(new CustomEvent('nile-remove', { bubbles: true, composed: true }));
|
|
563
|
+
await settle(el);
|
|
564
|
+
expect(el.value).to.deep.equal(['b']);
|
|
565
|
+
expect(seen).to.deep.equal(['nile-tag-remove']);
|
|
566
|
+
});
|
|
567
|
+
it('CV4. the clear button empties the value and emits nile-clear', async () => {
|
|
568
|
+
const el = await fixture(html `<nile-virtual-select multiple clearable .data=${DATA} .value=${['a', 'b']}></nile-virtual-select>`);
|
|
569
|
+
await settle(el);
|
|
570
|
+
const seen = record(el, ['nile-clear']);
|
|
571
|
+
const clear = el.shadowRoot.querySelector('[part~="clear-button"]');
|
|
572
|
+
expect(clear, 'clear button rendered').to.exist;
|
|
573
|
+
clear.click();
|
|
574
|
+
await settle(el);
|
|
575
|
+
expect(el.value).to.deep.equal([]);
|
|
576
|
+
expect(chipCount(el)).to.equal(0);
|
|
577
|
+
expect(seen).to.include('nile-clear');
|
|
578
|
+
});
|
|
579
|
+
it('CV5. form reset restores the value attribute', async () => {
|
|
580
|
+
const form = await fixture(html `<form>
|
|
581
|
+
<nile-virtual-select name="s" multiple .data=${DATA} value="a"></nile-virtual-select>
|
|
582
|
+
</form>`);
|
|
583
|
+
const el = form.querySelector('nile-virtual-select');
|
|
584
|
+
await settle(el);
|
|
585
|
+
el.value = ['c'];
|
|
586
|
+
await settle(el);
|
|
587
|
+
form.reset();
|
|
588
|
+
await settle(el);
|
|
589
|
+
expect(el.value).to.deep.equal(['a']);
|
|
590
|
+
});
|
|
591
|
+
it('CV6. portal + search: typing in the portalled search keeps the value', async () => {
|
|
592
|
+
const el = await fixture(html `<nile-virtual-select multiple portal searchEnabled .data=${DATA} .value=${['a']}></nile-virtual-select>`);
|
|
593
|
+
await settle(el);
|
|
594
|
+
el.open = true;
|
|
595
|
+
await waitUntil(() => document.body.querySelector('.nile-virtual-select-portal-append .select__search nile-input'), 'portal search never rendered');
|
|
596
|
+
const search = document.body.querySelector('.nile-virtual-select-portal-append .select__search nile-input');
|
|
597
|
+
await search.updateComplete;
|
|
598
|
+
const input = search.shadowRoot.querySelector('input');
|
|
599
|
+
input.value = 'Lb';
|
|
600
|
+
input.dispatchEvent(new Event('input', { bubbles: true, composed: true }));
|
|
601
|
+
await settle(el);
|
|
602
|
+
expect(el.value).to.deep.equal(['a']);
|
|
603
|
+
el.open = false;
|
|
604
|
+
await waitUntil(() => !document.body.querySelector('.nile-virtual-select-portal-append'), 'portal not cleaned up');
|
|
605
|
+
});
|
|
606
|
+
it('CV7. reconnecting without showtooltip keeps value and chips', async () => {
|
|
607
|
+
const host = await fixture(html `<div style="width: 500px">
|
|
608
|
+
<nile-virtual-select multiple .data=${DATA} .value=${['a', 'b']}></nile-virtual-select>
|
|
609
|
+
</div>`);
|
|
610
|
+
const el = host.querySelector('nile-virtual-select');
|
|
611
|
+
await settle(el);
|
|
612
|
+
el.remove();
|
|
613
|
+
host.appendChild(el);
|
|
614
|
+
await settle(el);
|
|
615
|
+
expect(el.value).to.deep.equal(['a', 'b']);
|
|
616
|
+
expect(chipCount(el)).to.equal(2);
|
|
617
|
+
});
|
|
618
|
+
});
|
|
619
|
+
describe('NileVirtualSelect showtooltip tooltip on sub-pixel truncation', () => {
|
|
620
|
+
const A = 'Engineering Operations';
|
|
621
|
+
const B = 'Human Resources Department And Payroll';
|
|
622
|
+
async function frames(n = 5) {
|
|
623
|
+
for (let i = 0; i < n; i++)
|
|
624
|
+
await nextFrame();
|
|
625
|
+
}
|
|
626
|
+
async function mount(width, chipMaxWidth) {
|
|
627
|
+
const host = await fixture(html `<div style="width: ${width}px">
|
|
628
|
+
<nile-virtual-select multiple showtooltip chipminwidth="40" chipmaxwidth=${chipMaxWidth} .data=${[A, B].map(v => ({ label: v, value: v }))} .value=${[A, B]}></nile-virtual-select>
|
|
629
|
+
</div>`);
|
|
630
|
+
const el = host.querySelector('nile-virtual-select');
|
|
631
|
+
await el.updateComplete;
|
|
632
|
+
await frames();
|
|
633
|
+
await el.updateComplete;
|
|
634
|
+
await frames(2);
|
|
635
|
+
return el;
|
|
636
|
+
}
|
|
637
|
+
function visiblyCut(chip) {
|
|
638
|
+
const content = chip.shadowRoot.querySelector('[part="content"]');
|
|
639
|
+
const text = content.assignedNodes({ flatten: true }).find(n => n.textContent?.trim());
|
|
640
|
+
const range = document.createRange();
|
|
641
|
+
range.selectNodeContents(text);
|
|
642
|
+
const over = range.getBoundingClientRect().right - content.getBoundingClientRect().right;
|
|
643
|
+
return { cut: over > 1 / 64, over, pxGap: content.scrollWidth - content.clientWidth };
|
|
644
|
+
}
|
|
645
|
+
function chipsAndTips(el) {
|
|
646
|
+
const chips = Array.from(el.shadowRoot.querySelectorAll('.select__tags nile-tag'));
|
|
647
|
+
const tips = Array.from(el.shadowRoot.querySelectorAll('.select__tags nile-lite-tooltip'));
|
|
648
|
+
return chips
|
|
649
|
+
.map((chip, i) => ({ chip, tipOn: !!tips[i] && !tips[i].hasAttribute('disabled') }))
|
|
650
|
+
.filter(({ chip }) => chip.style.display !== 'none');
|
|
651
|
+
}
|
|
652
|
+
it('TT1. every visibly cut chip has its tooltip, every uncut chip has none (sweep across the edge)', async () => {
|
|
653
|
+
const wide = await mount(900, 400);
|
|
654
|
+
const natural = chipsAndTips(wide)[0].chip.offsetWidth;
|
|
655
|
+
let subPixelCuts = 0;
|
|
656
|
+
for (let max = natural - 4; max <= natural + 1; max += 0.25) {
|
|
657
|
+
const el = await mount(330, max);
|
|
658
|
+
for (const { chip, tipOn } of chipsAndTips(el)) {
|
|
659
|
+
const { cut, pxGap } = visiblyCut(chip);
|
|
660
|
+
expect(tipOn, `chipMaxWidth ${max}: tooltip ${tipOn} but cut ${cut}`).to.equal(cut);
|
|
661
|
+
if (cut && pxGap <= 1)
|
|
662
|
+
subPixelCuts++;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
expect(subPixelCuts, 'sweep reached the sub-pixel truncation window').to.be.greaterThan(0);
|
|
666
|
+
});
|
|
667
|
+
it('TT2. chips at their natural width get no tooltip', async () => {
|
|
668
|
+
const el = await mount(900, 400);
|
|
669
|
+
for (const { chip, tipOn } of chipsAndTips(el)) {
|
|
670
|
+
expect(visiblyCut(chip).cut).to.be.false;
|
|
671
|
+
expect(tipOn).to.be.false;
|
|
672
|
+
}
|
|
673
|
+
});
|
|
359
674
|
});
|
|
360
675
|
//# sourceMappingURL=nile-virtual-select.test.js.map
|