Skip to content

Commit

Permalink
Improve polyfill handleOpen in ha-md-dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
wendevlin committed Sep 16, 2024
1 parent 69e85f2 commit 2678c8e
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/components/ha-md-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,22 @@ export class HaMdDialog extends MdDialog {
// prevent open in older browsers and wait for polyfill to load
private async _handleOpen(openEvent: Event) {
openEvent.preventDefault();
if (!this._polyfillDialogRegistered) {
this._loadPolyfillStylesheet("/static/polyfills/dialog-polyfill.css");
const dialog = this.shadowRoot?.querySelector(
"dialog"
) as HTMLDialogElement;

const dialogPolyfill = await DIALOG_POLYFILL;
dialogPolyfill.default.registerDialog(dialog);
this.removeEventListener("open", this._handleOpen);

this._polyfillDialogRegistered = true;
this.show();

if (this._polyfillDialogRegistered) {
return;
}

this._loadPolyfillStylesheet("/static/polyfills/dialog-polyfill.css");
const dialog = this.shadowRoot?.querySelector(
"dialog"
) as HTMLDialogElement;

const dialogPolyfill = await DIALOG_POLYFILL;
dialogPolyfill.default.registerDialog(dialog);
this.removeEventListener("open", this._handleOpen);

this._polyfillDialogRegistered = true;
this.show();
}

private async _loadPolyfillStylesheet(href) {
Expand Down

0 comments on commit 2678c8e

Please sign in to comment.