Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(modal): changing the open property no longer calls beforeClose #7042

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
569f64f
fix(modal): changing the open property should not call beforeClose. #…
driskull May 26, 2023
b278a00
test
driskull May 26, 2023
5ab7600
remove public method
driskull Jun 2, 2023
198d781
cleanup
driskull Jun 2, 2023
91ffe95
remove test
driskull Jun 2, 2023
dcac742
cleanup
driskull Jun 2, 2023
e2a2f3e
cleanup
driskull Jun 2, 2023
cf82dd5
Merge branch 'master' into dris0000/modal-beforeClose-fix
driskull Jun 5, 2023
fcd13e6
Merge branch 'master' into dris0000/modal-beforeClose-fix
driskull Jun 5, 2023
cea0732
Merge branch 'master' into dris0000/modal-beforeClose-fix
driskull Jun 6, 2023
7543db5
Merge branch 'master' into dris0000/modal-beforeClose-fix
driskull Jun 8, 2023
47f036e
add test for #6379
driskull Jun 8, 2023
e80859e
Merge branch 'master' into dris0000/modal-beforeClose-fix
driskull Jun 20, 2023
4709369
Merge branch 'master' into dris0000/modal-beforeClose-fix
driskull Jun 28, 2023
11320ee
Merge branch 'master' into dris0000/modal-beforeClose-fix
driskull Jun 28, 2023
9d25a55
Merge branch 'master' into dris0000/modal-beforeClose-fix
driskull Jun 29, 2023
8ab769f
Merge branch 'main' into dris0000/modal-beforeClose-fix
driskull Jul 3, 2023
4a3c9f3
Merge branch 'main' into dris0000/modal-beforeClose-fix
driskull Jul 3, 2023
212d1e4
Merge branch 'main' into dris0000/modal-beforeClose-fix
driskull Jul 6, 2023
f9b5f90
Update flow.tsx
driskull Jul 6, 2023
9f2f908
Merge branch 'main' into dris0000/modal-beforeClose-fix
driskull Jul 7, 2023
556aa3e
Merge branch 'main' into dris0000/modal-beforeClose-fix
driskull Jul 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/calcite-components/src/components/modal/modal.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,12 @@ describe("calcite-modal properties", () => {
(elm.beforeClose = (window as typeof window & Pick<typeof elm, "beforeClose">).beforeClose)
);
await page.waitForChanges();
await modal.setProperty("open", true);
modal.setProperty("open", true);
await page.waitForChanges();
await modal.setProperty("open", false);
const closeButton = await page.find(`calcite-modal >>> .${CSS.close}`);
await closeButton.click();
await page.waitForChanges();
expect(mockCallBack).toHaveBeenCalled();
expect(mockCallBack).toHaveBeenCalledTimes(1);
});
});

Expand Down
32 changes: 18 additions & 14 deletions packages/calcite-components/src/components/modal/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ export class Modal
@Prop({ mutable: true, reflect: true }) open = false;

/** Passes a function to run before the component closes. */
@Prop()
beforeClose: (el: HTMLElement) => Promise<void> = () => Promise.resolve();
@Prop() beforeClose: (el: HTMLCalciteModalElement) => Promise<void>;

/** When `true`, disables the component's close button. */
@Prop({ reflect: true }) closeButtonDisabled = false;
Expand Down Expand Up @@ -291,7 +290,7 @@ export class Modal
aria-label={this.messages.close}
class={CSS.close}
key="button"
onClick={this.close}
onClick={this.handleClose}
title={this.messages.close}
// eslint-disable-next-line react/jsx-sort-props
ref={(el) => (this.closeButtonEl = el)}
Expand Down Expand Up @@ -407,7 +406,7 @@ export class Modal
@Listen("keydown", { target: "window" })
handleEscape(event: KeyboardEvent): void {
if (this.open && !this.escapeDisabled && event.key === "Escape" && !event.defaultPrevented) {
this.close();
this.handleClose();
event.preventDefault();
}
}
Expand Down Expand Up @@ -511,7 +510,7 @@ export class Modal
this.openModal();
} else {
this.transitionEl?.classList.add(CSS.closingIdle);
this.close();
this.closeModal();
}
}

Expand All @@ -536,23 +535,28 @@ export class Modal
}
}

handleOutsideClose = (): void => {
private handleOutsideClose = (): void => {
if (this.outsideCloseDisabled) {
return;
}

this.close();
this.handleClose();
};

/** Close the modal, first running the `beforeClose` method */
close = (): Promise<void> => {
return this.beforeClose(this.el).then(() => {
this.open = false;
this.isOpen = false;
this.removeOverflowHiddenClass();
});
private handleClose = async (): Promise<void> => {
if (this.beforeClose) {
await this.beforeClose(this.el);
}

this.closeModal();
};

private closeModal(): void {
this.open = false;
this.isOpen = false;
this.removeOverflowHiddenClass();
}

private removeOverflowHiddenClass(): void {
document.documentElement.classList.remove(CSS.overflowHidden);
}
Expand Down