-
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! Re-implement
Modal
component using HTMLDialogE…
…lement (#461)
- Loading branch information
1 parent
64ae3d4
commit 06a7018
Showing
8 changed files
with
145 additions
and
42 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
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 |
---|---|---|
|
@@ -78,7 +78,7 @@ | |
} | ||
|
||
.isRootPositionTop { | ||
position: sticky; | ||
top: var(--rui-local-outer-spacing); | ||
bottom: auto; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export const dialogOnCancelHandler = (e, closeButtonRef) => { | ||
// 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 | ||
) { | ||
closeButtonRef.current.click(); | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export const dialogOnClickHandler = ( | ||
e, | ||
closeButtonRef, | ||
dialogRef, | ||
allowCloseOnBackdropClick, | ||
) => { | ||
// If it is not allowed to close modal on backdrop click, do nothing. | ||
if (!allowCloseOnBackdropClick) { | ||
return; | ||
} | ||
|
||
// Detection of the click on the backdrop is based on the following conditions: | ||
// 1. The click target is the dialog itself. This prevents detection of clicks on the dialog's children. | ||
// 2. The click is outside the dialog's boundaries. | ||
const dialogRect = dialogRef.current.getBoundingClientRect(); | ||
const isClickedOnBackdrop = dialogRef.current === e.target && ( | ||
e.clientX < dialogRect.left | ||
|| e.clientX > dialogRect.right | ||
|| e.clientY < dialogRect.top | ||
|| e.clientY > dialogRect.bottom | ||
); | ||
|
||
// If user does not click on the backdrop, do nothing. | ||
if (!isClickedOnBackdrop) { | ||
return; | ||
} | ||
|
||
// If the close button is not disabled, close the modal. | ||
if (closeButtonRef?.current != null && closeButtonRef?.current?.disabled === false) { | ||
closeButtonRef.current.click(); | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export const dialogOnCloseHandler = (e, closeButtonRef) => { | ||
// 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) { | ||
closeButtonRef.current.click(); | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export const dialogOnKeyDownHandler = ( | ||
e, | ||
closeButtonRef, | ||
allowCloseOnEscapeKey, | ||
) => { | ||
// When `allowCloseOnEscapeKey` is set to `false`, prevent closing the modal using the Escape key. | ||
if ( | ||
e.key === 'Escape' | ||
&& !allowCloseOnEscapeKey | ||
) { | ||
e.preventDefault(); | ||
} | ||
|
||
// When the close button is disabled, prevent closing the modal using the Escape key. | ||
if ( | ||
e.key === 'Escape' | ||
&& closeButtonRef?.current != null | ||
&& closeButtonRef?.current?.disabled === true | ||
) { | ||
e.preventDefault(); | ||
} | ||
}; |
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