Skip to content

Commit

Permalink
handle concurrent button highlights
Browse files Browse the repository at this point in the history
  • Loading branch information
jelni committed Dec 22, 2023
1 parent d9a5673 commit 603463c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion public/scripts/password-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ const charsets = {

let password = null;

let concurrentButtonActions = {
"copy-success": 0,
"copy-error": 0,
};

const preferences = {
form: document.getElementById("password-preferences"),
autoGenerate: document.getElementById("auto-generate"),
Expand Down Expand Up @@ -108,9 +113,11 @@ async function copyPassword() {
}
const className = success ? "copy-success" : "copy-error";
const copyButton = document.getElementById("password-copy");
concurrentButtonActions[className] += 1;
copyButton.classList.add(className);
setTimeout(() => {
copyButton.classList.remove(className);
const concurrentActions = (concurrentButtonActions[className] -= 1);
if (concurrentActions <= 0) copyButton.classList.remove(className);
}, 1_000);
}

Expand Down
2 changes: 1 addition & 1 deletion public/styles/password-generator.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ button {
transition-timing-function: ease-out;
}

button:hover {
button:not(.copy-success):not(.copy-error):hover {
background: var(--gray-20);
}

Expand Down

0 comments on commit 603463c

Please sign in to comment.