@lion/ui 0.14.1 → 0.14.2

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.
Files changed (58) hide show
  1. package/components/dialog/test/lion-dialog.test.js +114 -1
  2. package/components/overlays/src/OverlayMixin.js +12 -5
  3. package/components/overlays/test/OverlayController.test.js +2 -0
  4. package/components/overlays/test-suites/OverlayMixin.suite.js +4 -1
  5. package/custom-elements.json +30 -30
  6. package/dist-types/components/dialog/test/lion-dialog.test.d.ts.map +1 -1
  7. package/dist-types/components/overlays/src/OverlayMixin.d.ts.map +1 -1
  8. package/dist-types/components/overlays/test-suites/OverlayMixin.suite.d.ts.map +1 -1
  9. package/dist-types/tsconfig.tsbuildinfo +1 -1
  10. package/docs/components/checkbox-group/overview.md +2 -2
  11. package/docs/components/collapsible/overview.md +1 -1
  12. package/docs/components/combobox/overview.md +1 -1
  13. package/docs/components/combobox/use-cases.md +1 -1
  14. package/docs/components/dialog/overview.md +1 -1
  15. package/docs/components/fieldset/overview.md +5 -5
  16. package/docs/components/form/overview.md +3 -3
  17. package/docs/components/form/use-cases.md +2 -2
  18. package/docs/components/icon/use-cases.md +1 -1
  19. package/docs/components/input/overview.md +1 -1
  20. package/docs/components/input-amount/overview.md +3 -3
  21. package/docs/components/input-date/overview.md +3 -3
  22. package/docs/components/input-datepicker/overview.md +5 -5
  23. package/docs/components/input-email/overview.md +2 -2
  24. package/docs/components/input-file/overview.md +1 -1
  25. package/docs/components/input-iban/overview.md +2 -2
  26. package/docs/components/input-range/overview.md +2 -2
  27. package/docs/components/input-stepper/overview.md +1 -1
  28. package/docs/components/input-tel/overview.md +1 -1
  29. package/docs/components/input-tel/use-cases.md +6 -6
  30. package/docs/components/input-tel-dropdown/overview.md +1 -1
  31. package/docs/components/listbox/use-cases.md +1 -1
  32. package/docs/components/radio-group/overview.md +3 -3
  33. package/docs/components/select/use-cases.md +1 -1
  34. package/docs/components/select-rich/use-cases.md +1 -1
  35. package/docs/components/tabs/examples.md +1 -1
  36. package/docs/fundamentals/index.md +4 -4
  37. package/docs/fundamentals/node-tools/publish-docs/overview.md +3 -3
  38. package/docs/fundamentals/node-tools/rocket-preset-extend-lion-docs/overview.md +2 -2
  39. package/docs/fundamentals/rationales/accessibility.md +1 -1
  40. package/docs/fundamentals/systems/core/SlotMixin.md +1 -1
  41. package/docs/fundamentals/systems/core/overview.md +1 -1
  42. package/docs/fundamentals/systems/form/formatting-and-parsing.md +4 -4
  43. package/docs/fundamentals/systems/form/model-value.md +1 -1
  44. package/docs/fundamentals/systems/form/overview.md +28 -28
  45. package/docs/fundamentals/systems/form/validate.md +2 -2
  46. package/docs/fundamentals/systems/localize/overview.md +4 -4
  47. package/docs/fundamentals/systems/overlays/configuration.md +2 -2
  48. package/docs/fundamentals/systems/overlays/overview.md +5 -5
  49. package/docs/fundamentals/systems/overlays/use-cases.md +2 -2
  50. package/docs/fundamentals/tools/helpers/overview.md +1 -1
  51. package/docs/fundamentals/tools/singleton-manager/overview.md +4 -4
  52. package/docs/guides/how-to/create-a-custom-field.md +5 -5
  53. package/docs/guides/how-to/create-a-form.md +4 -4
  54. package/docs/guides/how-to/extend-a-native-input.md +2 -2
  55. package/docs/guides/index.md +8 -8
  56. package/docs/guides/principles/index.md +5 -5
  57. package/docs/guides/principles/styling.md +1 -1
  58. package/package.json +1 -1
@@ -1,9 +1,20 @@
1
1
  /* eslint-disable lit-a11y/no-autofocus */
2
- import { expect, fixture as _fixture, html, unsafeStatic, aTimeout } from '@open-wc/testing';
2
+ import {
3
+ expect,
4
+ fixture as _fixture,
5
+ html,
6
+ unsafeStatic,
7
+ aTimeout,
8
+ defineCE,
9
+ waitUntil,
10
+ } from '@open-wc/testing';
11
+ import { cache } from 'lit/directives/cache.js';
12
+ import { LitElement, nothing } from 'lit';
3
13
  import { runOverlayMixinSuite } from '../../overlays/test-suites/OverlayMixin.suite.js';
4
14
  import { isActiveElement } from '../../core/test-helpers/isActiveElement.js';
5
15
  import '../test-helpers/test-router.js';
6
16
  import '@lion/ui/define/lion-dialog.js';
17
+ import '@lion/ui/define/lion-tabs.js';
7
18
 
8
19
  /**
9
20
  * @typedef {import('../src/LionDialog.js').LionDialog} LionDialog
@@ -296,5 +307,107 @@ describe('lion-dialog', () => {
296
307
  await dialogAfterRouteChange._overlayCtrl._showComplete;
297
308
  expect(dialogAfterRouteChange.opened).to.be.true;
298
309
  });
310
+
311
+ it('should close the popup dialog after rendered from cache', async () => {
312
+ /**
313
+ *
314
+ * @param {Event} e
315
+ * @returns
316
+ */
317
+ const closeButtonHandler = e =>
318
+ e.target?.dispatchEvent(new Event('close-overlay', { bubbles: true }));
319
+ const dialog = html` <lion-dialog>
320
+ <button slot="invoker" class="invoker-button">Click me to open dialog</button>
321
+ <div slot="content" class="demo-dialog-content">
322
+ Hello! You can close this dialog here:
323
+ <button class="close-button" @click="${closeButtonHandler}">⨯</button>
324
+ </div>
325
+ </lion-dialog>`;
326
+
327
+ /**
328
+ * Note, inactive tab content is **destroyed** on every tab switch.
329
+ */
330
+ class Wrapper extends LitElement {
331
+ static properties = {
332
+ ...super.properties,
333
+ activeTabIndex: { type: Number },
334
+ };
335
+
336
+ constructor() {
337
+ super();
338
+ this.activeTabIndex = 0;
339
+ }
340
+
341
+ /**
342
+ * @param {number} index
343
+ */
344
+ changeActiveTabIndex(index) {
345
+ this.activeTabIndex = index;
346
+ }
347
+
348
+ render() {
349
+ const changeActiveTabIndexRef = this.changeActiveTabIndex.bind(this);
350
+ return html`
351
+ <lion-tabs>
352
+ <button slot="tab" class="first-button" @click=${() => changeActiveTabIndexRef(0)}>
353
+ First
354
+ </button>
355
+ <p slot="panel">${cache(this.activeTabIndex === 0 ? dialog : nothing)}</p>
356
+ <button slot="tab" class="second-button" @click=${() => changeActiveTabIndexRef(1)}>
357
+ Second
358
+ </button>
359
+ <p slot="panel">Info page with lots of information about us.</p>
360
+ </lion-tabs>
361
+ `;
362
+ }
363
+ }
364
+
365
+ const wrapperFixture = /** @type {(arg: TemplateResult) => Promise<Wrapper>} */ (_fixture);
366
+ const tagString = defineCE(Wrapper);
367
+ const wrapperTag = unsafeStatic(tagString);
368
+ const wrapperElement = /** @type {Wrapper} */ (
369
+ await wrapperFixture(html`<${wrapperTag}></${wrapperTag}>`)
370
+ );
371
+ await wrapperElement.updateComplete;
372
+ const wrapperElementShadowRoot = wrapperElement.shadowRoot;
373
+ /**
374
+ * @returns { HTMLElement | null | undefined }
375
+ */
376
+ const getFirstButton = () => wrapperElementShadowRoot?.querySelector('.first-button');
377
+ /**
378
+ * @returns { HTMLElement | null | undefined }
379
+ */
380
+ const getSecondButton = () => wrapperElementShadowRoot?.querySelector('.second-button');
381
+ /**
382
+ * @returns { HTMLElement | null | undefined }
383
+ */
384
+ const getInvokerButton = () => wrapperElementShadowRoot?.querySelector('.invoker-button');
385
+ /**
386
+ * @returns { HTMLElement | null | undefined }
387
+ */
388
+ const getCloseButton = () => wrapperElementShadowRoot?.querySelector('.close-button');
389
+ /**
390
+ * @returns { Element | null | undefined }
391
+ */
392
+ const getDialog = () =>
393
+ wrapperElementShadowRoot?.querySelector('lion-dialog')?.shadowRoot?.querySelector('dialog');
394
+ // @ts-ignore
395
+ const isDialogVisible = () => getDialog()?.checkVisibility() === true;
396
+ const isDialogRendered = () =>
397
+ !!wrapperElement.shadowRoot?.querySelector('lion-dialog')?.shadowRoot?.childNodes.length;
398
+ getInvokerButton()?.click();
399
+ await waitUntil(isDialogVisible);
400
+ getCloseButton()?.click();
401
+ await waitUntil(() => !isDialogVisible());
402
+ getSecondButton()?.click();
403
+ await waitUntil(() => !isDialogRendered());
404
+ getFirstButton()?.click();
405
+ await waitUntil(isDialogRendered);
406
+ getInvokerButton()?.click();
407
+ await waitUntil(isDialogVisible);
408
+ getCloseButton()?.click();
409
+ await waitUntil(() => !isDialogVisible());
410
+ expect(isDialogVisible()).to.equal(false);
411
+ });
299
412
  });
300
413
  });
@@ -246,16 +246,23 @@ export const OverlayMixinImplementation = superclass =>
246
246
 
247
247
  /** @protected */
248
248
  _setupOverlayCtrl() {
249
- if (this._overlayCtrl) return;
250
-
251
- /** @type {OverlayController} */
252
- this._overlayCtrl = this._defineOverlay({
249
+ if (this.#hasSetup) return;
250
+ const config = {
253
251
  contentNode: this._overlayContentNode,
254
252
  contentWrapperNode: this._overlayContentWrapperNode,
255
253
  invokerNode: this._overlayInvokerNode,
256
254
  referenceNode: this._overlayReferenceNode,
257
255
  backdropNode: this._overlayBackdropNode,
258
- });
256
+ };
257
+
258
+ if (this._overlayCtrl) {
259
+ // when `lit` `cache` attaches node to the DOM, register the controller back in the OverlaysManager
260
+ this._overlayCtrl.updateConfig(config);
261
+ } else {
262
+ /** @type {OverlayController} */
263
+ this._overlayCtrl = this._defineOverlay(config);
264
+ }
265
+
259
266
  this.__syncToOverlayController();
260
267
  this.__setupSyncFromOverlayController();
261
268
  this._setupOpenCloseListeners();
@@ -153,6 +153,8 @@ async function createNestedEscControllers(parentContent) {
153
153
 
154
154
  afterEach(() => {
155
155
  overlays.teardown();
156
+ // clean document.body from the DOM nodes left by previous tests
157
+ document.body.innerHTML = '';
156
158
  });
157
159
 
158
160
  describe('OverlayController', () => {
@@ -533,8 +533,11 @@ export function runOverlayMixinSuite({ tagString, tag, suffix = '' }) {
533
533
 
534
534
  el.switched = false;
535
535
  await el.updateComplete;
536
-
537
536
  expect(setupSpy.callCount).to.equal(1);
537
+
538
+ const elCtrl = /** @type {OverlayEl} */ (el.overlayEl)?._overlayCtrl;
539
+ const isCtrlRegisteredAtOverlaysManager = elCtrl.manager.list.some(ctrl => elCtrl === ctrl);
540
+ expect(isCtrlRegisteredAtOverlaysManager).to.equal(true);
538
541
  });
539
542
 
540
543
  it('correctly removes event listeners when disconnected from dom', async () => {
@@ -2145,6 +2145,36 @@
2145
2145
  }
2146
2146
  ]
2147
2147
  },
2148
+ {
2149
+ "kind": "javascript-module",
2150
+ "path": "exports/define-helpers/sb-action-logger.js",
2151
+ "declarations": [],
2152
+ "exports": [
2153
+ {
2154
+ "kind": "custom-element-definition",
2155
+ "name": "sb-action-logger",
2156
+ "declaration": {
2157
+ "name": "SbActionLogger",
2158
+ "module": "/exports/helpers.js"
2159
+ }
2160
+ }
2161
+ ]
2162
+ },
2163
+ {
2164
+ "kind": "javascript-module",
2165
+ "path": "exports/define-helpers/sb-locale-switcher.js",
2166
+ "declarations": [],
2167
+ "exports": [
2168
+ {
2169
+ "kind": "custom-element-definition",
2170
+ "name": "sb-locale-switcher",
2171
+ "declaration": {
2172
+ "name": "SbLocaleSwitcher",
2173
+ "module": "/exports/helpers.js"
2174
+ }
2175
+ }
2176
+ ]
2177
+ },
2148
2178
  {
2149
2179
  "kind": "javascript-module",
2150
2180
  "path": "exports/define/lion-accordion.js",
@@ -2850,36 +2880,6 @@
2850
2880
  }
2851
2881
  ]
2852
2882
  },
2853
- {
2854
- "kind": "javascript-module",
2855
- "path": "exports/define-helpers/sb-action-logger.js",
2856
- "declarations": [],
2857
- "exports": [
2858
- {
2859
- "kind": "custom-element-definition",
2860
- "name": "sb-action-logger",
2861
- "declaration": {
2862
- "name": "SbActionLogger",
2863
- "module": "/exports/helpers.js"
2864
- }
2865
- }
2866
- ]
2867
- },
2868
- {
2869
- "kind": "javascript-module",
2870
- "path": "exports/define-helpers/sb-locale-switcher.js",
2871
- "declarations": [],
2872
- "exports": [
2873
- {
2874
- "kind": "custom-element-definition",
2875
- "name": "sb-locale-switcher",
2876
- "declaration": {
2877
- "name": "SbLocaleSwitcher",
2878
- "module": "/exports/helpers.js"
2879
- }
2880
- }
2881
- ]
2882
- },
2883
2883
  {
2884
2884
  "kind": "javascript-module",
2885
2885
  "path": "components/accordion/src/LionAccordion.js",
@@ -1 +1 @@
1
- {"version":3,"file":"lion-dialog.test.d.ts","sourceRoot":"","sources":["../../../../components/dialog/test/lion-dialog.test.js"],"names":[],"mappings":"yBAQa,OAAO,sBAAsB,EAAE,UAAU;6BACzC,OAAO,KAAK,EAAE,cAAc"}
1
+ {"version":3,"file":"lion-dialog.test.d.ts","sourceRoot":"","sources":["../../../../components/dialog/test/lion-dialog.test.js"],"names":[],"mappings":"yBAmBa,OAAO,sBAAsB,EAAE,UAAU;6BACzC,OAAO,KAAK,EAAE,cAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"OverlayMixin.d.ts","sourceRoot":"","sources":["../../../../components/overlays/src/OverlayMixin.js"],"names":[],"mappings":"AAIA;;;;GAIG;AAEH;;;;;;;GAOG;AACH,yCAHU,YAAY,CA8YlB;2BAtZS,OAAO,+BAA+B,EAAE,YAAY;AAuZjE,gGAAoE;4BAzZvD,OAAO,2BAA2B,EAAE,aAAa;kCACjD,OAAO,+BAA+B,EAAE,mBAAmB"}
1
+ {"version":3,"file":"OverlayMixin.d.ts","sourceRoot":"","sources":["../../../../components/overlays/src/OverlayMixin.js"],"names":[],"mappings":"AAIA;;;;GAIG;AAEH;;;;;;;GAOG;AACH,yCAHU,YAAY,CAqZlB;2BA7ZS,OAAO,+BAA+B,EAAE,YAAY;AA8ZjE,gGAAoE;4BAhavD,OAAO,2BAA2B,EAAE,aAAa;kCACjD,OAAO,+BAA+B,EAAE,mBAAmB"}
@@ -1 +1 @@
1
- {"version":3,"file":"OverlayMixin.suite.d.ts","sourceRoot":"","sources":["../../../../components/overlays/test-suites/OverlayMixin.suite.js"],"names":[],"mappings":"AAwDA;;GAEG;AACH,iEAFW;IAAC,SAAS,EAAC,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAC,MAAM,CAAA;CAAC,QA4mBzD;kCAlpBY,OAAO,+BAA+B,EAAE,mBAAmB;wBAC3D,UAAU,GAAG,WAAW,GAAG;IAAC,YAAY,EAAC,iBAAiB,CAAA;CAAC;2BAC3D,OAAO,+BAA+B,EAAE,YAAY;0BACpD,OAAO,+BAA+B,EAAE,WAAW;4BACnD,OAAO,2BAA2B,EAAE,aAAa"}
1
+ {"version":3,"file":"OverlayMixin.suite.d.ts","sourceRoot":"","sources":["../../../../components/overlays/test-suites/OverlayMixin.suite.js"],"names":[],"mappings":"AAwDA;;GAEG;AACH,iEAFW;IAAC,SAAS,EAAC,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAC,MAAM,CAAA;CAAC,QA+mBzD;kCArpBY,OAAO,+BAA+B,EAAE,mBAAmB;wBAC3D,UAAU,GAAG,WAAW,GAAG;IAAC,YAAY,EAAC,iBAAiB,CAAA;CAAC;2BAC3D,OAAO,+BAA+B,EAAE,YAAY;0BACpD,OAAO,+BAA+B,EAAE,WAAW;4BACnD,OAAO,2BAA2B,EAAE,aAAa"}