Skip to content

Commit 58aabf1

Browse files
authored
[APT-1675] Don't scroll page on modal cancel (#142)
1 parent 501a7b7 commit 58aabf1

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/components/Modal.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@ export const SubscriptionNoticeModal: React.FC<ModalProps> = ({
2929
handleCancelRequest,
3030
handleAcceptRequest,
3131
}) => {
32-
const onRequestClose = () => {
32+
const onRequestClose = (e) => {
3333
// If the user checked to never see this notice but subsequently cancels we will disregard their selection. We will
3434
// only stop showing this notice if they check the box and then proceed to GitHub
35-
if(window.localStorage.getItem(DONT_SHOW_PRIVATE_GITHUB_WARNING_KEY)) {
35+
if (window.localStorage.getItem(DONT_SHOW_PRIVATE_GITHUB_WARNING_KEY)) {
3636
window.localStorage.removeItem(DONT_SHOW_PRIVATE_GITHUB_WARNING_KEY)
3737
}
38-
38+
3939
handleCancelRequest()
40+
41+
// prevent the browser from handling a Cancel button click and scrolling to top
42+
e.preventDefault()
4043
}
4144

4245
const gitHubRepoName = externalLink.match(
@@ -86,7 +89,7 @@ export const SubscriptionNoticeModal: React.FC<ModalProps> = ({
8689

8790
const setDontWarnMe = (event) => {
8891
event.stopPropagation()
89-
if(!window.localStorage.getItem(DONT_SHOW_PRIVATE_GITHUB_WARNING_KEY)) {
92+
if (!window.localStorage.getItem(DONT_SHOW_PRIVATE_GITHUB_WARNING_KEY)) {
9093
window.localStorage.setItem(DONT_SHOW_PRIVATE_GITHUB_WARNING_KEY, "true")
9194
} else {
9295
window.localStorage.removeItem(DONT_SHOW_PRIVATE_GITHUB_WARNING_KEY)
@@ -117,7 +120,7 @@ export const SubscriptionNoticeModal: React.FC<ModalProps> = ({
117120
<label>Don't warn me again</label>
118121
</div>
119122
<div className={styles.buttonsContainer}>
120-
<a onClick={() => onRequestClose()} href="#">
123+
<a onClick={(e) => onRequestClose(e)} href="#">
121124
Cancel
122125
</a>
123126
<a id={idOfNoticeLink} href={externalLink} target="_blank">

0 commit comments

Comments
 (0)