Skip to content

Commit

Permalink
impr: use dialog element to take advantage of focus trapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Miodec committed Feb 28, 2024
1 parent a88ba61 commit 8e0f124
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
16 changes: 8 additions & 8 deletions frontend/src/html/popups.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
</div>
</div>

<div id="alertsPopupWrapper" class="popupWrapper hidden">
<dialog id="alertsPopupWrapper" class="popupWrapper hidden">
<div id="alertsPopup">
<div class="button mobileClose">
<button class="mobileClose">
<i class="fas fa-times"></i>
Close
</div>
</button>
<div class="scrollWrapper">
<div class="accountAlerts">
<div class="title">
Expand All @@ -19,14 +19,14 @@
</div>
<div class="right"></div>
</div>
<div class="button claimAll hidden">
<button class="claimAll hidden">
<i class="fas fa-fw fa-gift"></i>
Claim all
</div>
<div class="button deleteAll hidden">
</button>
<button class="deleteAll hidden">
<i class="fas fa-fw fa-trash"></i>
Delete all
</div>
</button>
<div class="list">
<div class="nothing">Nothing to show</div>
</div>
Expand All @@ -53,7 +53,7 @@
</div>
</div>
</div>
</div>
</dialog>

<div id="simplePopupWrapper" class="popupWrapper hidden">
<div id="simplePopup" popupId=""></div>
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/styles/popups.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
.popupWrapper {
width: 100%;
height: 100%;
max-width: 100%;
max-height: 100%;
margin: 0;
background: rgba(0, 0, 0, 0.75);
position: fixed;
left: 0;
Expand All @@ -10,6 +13,7 @@
justify-content: center;
align-items: center;
padding: 2rem 0;
border: none;
&:focus-visible {
outline: none;
}
Expand Down Expand Up @@ -1631,7 +1635,7 @@
padding: 0;
justify-content: end;
z-index: 99999999;
// padding: 2rem;
overflow-x: hidden;
#alertsPopup {
background: var(--bg-color);
width: calc(350px + 2rem);
Expand All @@ -1647,7 +1651,8 @@
border-radius: var(--roundness) 0 0 var(--roundness);

.mobileClose {
margin: 0 1rem 2rem 1rem;
margin-bottom: 2rem;
width: 100%;
display: none;
}

Expand Down
7 changes: 7 additions & 0 deletions frontend/src/ts/elements/alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import * as Skeleton from "../popups/skeleton";

const wrapperId = "alertsPopupWrapper";

const wrapperDialog = document.querySelector(
"#" + wrapperId
) as HTMLDialogElement;

let accountAlerts: MonkeyTypes.MonkeyMail[] = [];
let maxMail = 0;
let mailToMarkRead: string[] = [];
Expand Down Expand Up @@ -116,6 +120,7 @@ function hide(): void {
$("#alertsPopupWrapper").addClass("hidden");
$("#alertsPopup .notificationHistory .list").empty();
$("#alertsPopup .psas .list").empty();
wrapperDialog.close();
Skeleton.remove(wrapperId);
}
);
Expand All @@ -125,6 +130,8 @@ function hide(): void {
async function show(): Promise<void> {
Skeleton.append(wrapperId);
if (!isPopupVisible(wrapperId)) {
wrapperDialog.showModal();

$("#alertsPopup").css("marginRight", "-10rem").animate(
{
marginRight: 0,
Expand Down

0 comments on commit 8e0f124

Please sign in to comment.