Skip to content

Commit

Permalink
chore(dialog): remove dialog polyfill (VIV-1986) (#1932)
Browse files Browse the repository at this point in the history
Remove dialog polyfill
  • Loading branch information
RichardHelm authored Oct 3, 2024
1 parent 47b4580 commit 406d588
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 35 deletions.
6 changes: 2 additions & 4 deletions libs/components/src/lib/dialog/definition.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import type { FoundationElementDefinition } from '@microsoft/fast-foundation';
//TODO::remove next line when removing the dialog polyfill
import dialogPolyfillStyles from 'dialog-polyfill/dist/dialog-polyfill.css?inline';
import { registerFactory } from '../../shared/design-system';
import { iconRegistries } from '../icon/definition';
import { buttonRegistries } from '../button/definition';
import { elevationRegistries } from '../elevation/definition';
import styles from './dialog.scss?inline';
import { Dialog, isDialogSupported } from './dialog';
import { Dialog } from './dialog';
import { DialogTemplate as template } from './dialog.template';

export type { IconPlacement } from './dialog';
Expand All @@ -20,7 +18,7 @@ export type { IconPlacement } from './dialog';
export const dialogDefinition = Dialog.compose<FoundationElementDefinition>({
baseName: 'dialog',
template: template as any,
styles: isDialogSupported ? [styles] : [styles, dialogPolyfillStyles],
styles,
});

/**
Expand Down
9 changes: 0 additions & 9 deletions libs/components/src/lib/dialog/dialog-polyfill.spec.ts

This file was deleted.

15 changes: 14 additions & 1 deletion libs/components/src/lib/dialog/dialog.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import { axe, elementUpdated, fixture, getBaseElement } from '@vivid-nx/shared';
import { FoundationElementRegistry } from '@microsoft/fast-foundation';
import * as dialogPolyfill from 'dialog-polyfill';
import {
FoundationElement,
FoundationElementRegistry,
} from '@microsoft/fast-foundation';
import { Dialog } from './dialog';
import '.';
import { dialogDefinition } from './definition';

const COMPONENT_TAG = 'vwc-dialog';

// Polyfill dialog element which is not supported in JSDOM
const originalConnectedCallback = FoundationElement.prototype.connectedCallback;
FoundationElement.prototype.connectedCallback = function () {
originalConnectedCallback.call(this);
this.shadowRoot!.querySelectorAll('dialog').forEach(
(dialogPolyfill as any).registerDialog
);
};

describe('vwc-dialog', () => {
async function closeDialog() {
element.close();
Expand Down
21 changes: 0 additions & 21 deletions libs/components/src/lib/dialog/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,6 @@ import { applyMixins, FoundationElement } from '@microsoft/fast-foundation';
import { attr, observable } from '@microsoft/fast-element';
import { Localized } from '../../shared/patterns';

// eslint-disable-next-line compat/compat
export const isDialogSupported = Boolean(
window.HTMLDialogElement && window.HTMLDialogElement.prototype.showModal
);

// Make sure we support Safari 14
let dialogPolyfill: any;
(async () => {
if (!isDialogSupported) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
delete window.HTMLDialogElement;
dialogPolyfill = await import('dialog-polyfill');
}
})();

/**
* Types of icon placement
*
Expand Down Expand Up @@ -98,11 +82,6 @@ export class Dialog extends FoundationElement {
this.#dialogElement = this.shadowRoot!.querySelector(
'dialog'
) as HTMLDialogElement;
if (this.#dialogElement) {
if (dialogPolyfill) {
dialogPolyfill.registerDialog(this.#dialogElement);
}
}
}
return this.#dialogElement as HTMLDialogElement;
}
Expand Down

0 comments on commit 406d588

Please sign in to comment.