-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! fixup! fixup! fixup! fixup! fixup! Re-implement
Modal
compon…
…ent using HTMLDialogElement (#461)
- Loading branch information
1 parent
715e2e5
commit 904ca4e
Showing
4 changed files
with
62 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,28 @@ | ||
// Disable coverage for the following function | ||
/* istanbul ignore next line */ | ||
export const dialogOnCancelHandler = (e, closeButtonRef, onCancel = undefined) => { | ||
/* istanbul ignore next */ | ||
|
||
/** | ||
* Handles the cancel event of the dialog which is fired when the user presses the Escape key or triggers cancel event | ||
* by native dialog mechanism. | ||
* | ||
* It prevents the default behaviour of the native dialog and closes the dialog manually by clicking the close button, | ||
* if the close button is not disabled. | ||
* | ||
* @param e | ||
* @param closeButtonRef | ||
* @param onCancelHandler | ||
*/ | ||
export const dialogOnCancelHandler = (e, closeButtonRef, onCancelHandler = undefined) => { | ||
// Prevent the default behaviour of the event as we want to close dialog manually. | ||
e.preventDefault(); | ||
|
||
// If the close button is not disabled, close the modal. | ||
if ( | ||
closeButtonRef?.current != null | ||
&& closeButtonRef?.current?.disabled === false | ||
) { | ||
if (closeButtonRef?.current != null && closeButtonRef?.current?.disabled === false) { | ||
closeButtonRef.current.click(); | ||
} | ||
|
||
// This is a custom handler that is passed as a prop to the Modal component | ||
if (onCancel) { | ||
onCancel(e); | ||
if (onCancelHandler) { | ||
onCancelHandler(e); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters