Clicking the Toggle Button of an Open Action Menu Does Not Close It

This commit is contained in:
Gerard Burns 2022-10-17 19:58:43 +01:00
parent 806ac9b50f
commit ef6fadb9d4
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"