1
0
Fork 0
mirror of synced 2024-06-29 11:31:06 +12:00

Merge pull request #8301 from Budibase/fix/clicking-the-toggle-button-of-an-open-action-menu-does-not-close-it

Clicking the Toggle Button of an Open Action Menu Does Not Close It
This commit is contained in:
Martin McKeaveney 2022-10-20 20:35:39 +01:00 committed by GitHub
commit 7091b3baf2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View file

@ -1,18 +1,18 @@
export default function clickOutside(element, callbackFunction) {
function onClick(event) {
if (!element.contains(event.target)) {
callbackFunction()
callbackFunction(event)
}
}
document.body.addEventListener("mousedown", onClick, true)
document.body.addEventListener("click", onClick, true)
return {
update(newCallbackFunction) {
callbackFunction = newCallbackFunction
},
destroy() {
document.body.removeEventListener("mousedown", onClick, true)
document.body.removeEventListener("click", onClick, true)
},
}
}

View file

@ -33,6 +33,13 @@
open = false
}
const handleOutsideClick = e => {
if (open) {
e.stopPropagation()
hide()
}
}
let open = null
function handleEscape(e) {
@ -47,7 +54,7 @@
<div
tabindex="0"
use:positionDropdown={{ anchor, align, maxWidth }}
use:clickOutside={hide}
use:clickOutside={handleOutsideClick}
on:keydown={handleEscape}
class={"spectrum-Popover is-open " + (tooltipClasses || "")}
role="presentation"