feat(dialog): add types for dialog

This commit is contained in:
Joren Broekema 2020-09-28 11:52:13 +02:00 committed by Thomas Allmer
parent 52618dc539
commit b06c85bbb4
4 changed files with 30 additions and 9 deletions

View file

@ -0,0 +1,5 @@
---
'@lion/dialog': minor
---
Added types for dialog package.

View file

@ -2,6 +2,13 @@ import { html, LitElement } from '@lion/core';
import { OverlayMixin, withModalDialogConfig } from '@lion/overlays'; import { OverlayMixin, withModalDialogConfig } from '@lion/overlays';
export class LionDialog extends OverlayMixin(LitElement) { export class LionDialog extends OverlayMixin(LitElement) {
constructor() {
super();
this.__toggle = () => {
this.opened = !this.opened;
};
}
// eslint-disable-next-line class-methods-use-this // eslint-disable-next-line class-methods-use-this
_defineOverlayConfig() { _defineOverlayConfig() {
return { return {
@ -11,10 +18,6 @@ export class LionDialog extends OverlayMixin(LitElement) {
_setupOpenCloseListeners() { _setupOpenCloseListeners() {
super._setupOpenCloseListeners(); super._setupOpenCloseListeners();
this.__toggle = () => {
this.opened = !this.opened;
};
if (this._overlayInvokerNode) { if (this._overlayInvokerNode) {
this._overlayInvokerNode.addEventListener('click', this.__toggle); this._overlayInvokerNode.addEventListener('click', this.__toggle);
} }

View file

@ -1,7 +1,14 @@
import { runOverlayMixinSuite } from '@lion/overlays/test-suites/OverlayMixin.suite.js'; import { runOverlayMixinSuite } from '@lion/overlays/test-suites/OverlayMixin.suite.js';
import { expect, fixture, html, unsafeStatic } from '@open-wc/testing'; import { expect, fixture as _fixture, html, unsafeStatic } from '@open-wc/testing';
import '../lion-dialog.js'; import '../lion-dialog.js';
/**
* @typedef {import('../src/LionDialog').LionDialog} LionDialog
* @typedef {import('lit-html').TemplateResult} TemplateResult
*/
const fixture = /** @type {(arg: TemplateResult) => Promise<LionDialog>} */ (_fixture);
describe('lion-dialog', () => { describe('lion-dialog', () => {
// For some reason, globalRootNode is not cleared properly on disconnectedCallback from previous overlay test fixtures... // For some reason, globalRootNode is not cleared properly on disconnectedCallback from previous overlay test fixtures...
// Not sure why this "bug" happens... // Not sure why this "bug" happens...
@ -31,7 +38,7 @@ describe('lion-dialog', () => {
<button slot="invoker">Popup button</button> <button slot="invoker">Popup button</button>
</lion-dialog> </lion-dialog>
`); `);
const invoker = el.querySelector('[slot="invoker"]'); const invoker = /** @type {HTMLElement} */ (el.querySelector('[slot="invoker"]'));
invoker.click(); invoker.click();
expect(el.opened).to.be.true; expect(el.opened).to.be.true;
@ -51,12 +58,17 @@ describe('lion-dialog', () => {
</lion-dialog> </lion-dialog>
`); `);
// @ts-expect-error you're not allowed to call protected _overlayInvokerNode in public context, but for testing it's okay
el._overlayInvokerNode.click(); el._overlayInvokerNode.click();
expect(el.opened).to.be.true; expect(el.opened).to.be.true;
const wrapperNode = Array.from(document.querySelector('.global-overlays').children)[1]; const overlaysContainer = /** @type {HTMLElement} */ (document.querySelector(
const nestedDialog = wrapperNode.querySelector('lion-dialog'); '.global-overlays',
nestedDialog._overlayInvokerNode.click(); ));
const wrapperNode = Array.from(overlaysContainer.children)[1];
const nestedDialog = /** @type {LionDialog} */ (wrapperNode.querySelector('lion-dialog'));
// @ts-expect-error you're not allowed to call protected _overlayInvokerNode in public context, but for testing it's okay
nestedDialog?._overlayInvokerNode.click();
expect(nestedDialog.opened).to.be.true; expect(nestedDialog.opened).to.be.true;
}); });
}); });

View file

@ -20,6 +20,7 @@
"packages/checkbox-group/**/*.js", "packages/checkbox-group/**/*.js",
"packages/collapsible/**/*.js", "packages/collapsible/**/*.js",
"packages/core/**/*.js", "packages/core/**/*.js",
"packages/dialog/**/*.js",
"packages/fieldset/**/*.js", "packages/fieldset/**/*.js",
"packages/form/**/*.js", "packages/form/**/*.js",
"packages/form-core/**/*.js", "packages/form-core/**/*.js",