Skip to content

Commit

Permalink
Close clipboard if clicked anywhere outside clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
manics committed Jul 14, 2024
1 parent b4ef5ac commit 05c6af9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions js/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import "./clipboard.css";
* @param {Element} trigger
* @param {Element} clipboard
*/
export function setupClipboard(trigger, clipboard, canvas) {
export function setupClipboard(trigger, clipboard, parent) {
const arrowElement = clipboard.querySelector(".arrow");
function updatePosition() {
computePosition(trigger, clipboard, {
Expand Down Expand Up @@ -53,14 +53,15 @@ export function setupClipboard(trigger, clipboard, canvas) {
trigger.classList.toggle("active");
updatePosition();
e.preventDefault();
e.stopPropagation();
});

// If the clipboard is clicked this should not be passed to the desktop
clipboard.addEventListener("click", (e) => {
e.stopPropagation();
});
// Close the popup if we click outside it
canvas.addEventListener("click", () => {
parent.addEventListener("click", () => {
if (trigger.classList.contains("active")) {
clipboard.classList.toggle("hidden");
trigger.classList.toggle("active");
Expand Down
2 changes: 1 addition & 1 deletion js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function connect() {
setupClipboard(
document.getElementById("clipboard-button"),
document.getElementById("clipboard-container"),
document.getElementsByTagName("canvas")[0],
document.body,
);
}

Expand Down

0 comments on commit 05c6af9

Please sign in to comment.