Skip to content

Commit

Permalink
fix(dialog): dialog freeze when using open property (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgonzalezr committed Jul 18, 2023
1 parent 235a15e commit 252baa1
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/bee-q/src/components/dialog/bq-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ export class BqDialog {
handleOpenChange() {
if (this.open) {
this.el.classList.add(this.OPEN_CSS_CLASS);
this.removeInertAttribute();
!this.disableBackdrop ? this.dialogElem.showModal() : this.dialogElem.show();
} else {
this.dialogElem.close();
this.setInertAttribute();
}
}

Expand Down Expand Up @@ -170,13 +172,21 @@ export class BqDialog {
// These methods cannot be called from the host element.
// =======================================================

private setInertAttribute() {
if (!this.dialogElem) return;
this.dialogElem.setAttribute('inert', 'true');
}

private removeInertAttribute() {
if (!this.dialogElem) return;
this.dialogElem.removeAttribute('inert');
}

private handleClose = () => {
if (!this.dialogElem) return;

const ev = this.bqClose.emit();
if (ev.defaultPrevented) return;

this.dialogElem.setAttribute('inert', 'true');
this.open = false;
};

Expand All @@ -186,15 +196,13 @@ export class BqDialog {
const ev = this.bqOpen.emit();
if (ev.defaultPrevented) return;

this.dialogElem.removeAttribute('inert');
this.open = true;
};

private handleCancel = () => {
const ev = this.bqCancel.emit();
if (ev.defaultPrevented) return;

this.dialogElem.setAttribute('inert', 'true');
this.open = false;
};

Expand Down

0 comments on commit 252baa1

Please sign in to comment.