Fix dismiss idempotency
This commit is contained in:
parent
be99077306
commit
523c908b20
@ -44,13 +44,19 @@ export function createDismiss(options: CreateDismissOptions): Dismiss {
|
||||
options.onDismiss();
|
||||
};
|
||||
|
||||
let attached = false;
|
||||
|
||||
const dismiss: Dismiss = {
|
||||
attach() {
|
||||
if (attached) return;
|
||||
attached = true;
|
||||
layerStack.push(dismiss);
|
||||
document.addEventListener("keydown", handleKeyDown);
|
||||
document.addEventListener("pointerdown", handlePointerDown);
|
||||
},
|
||||
detach() {
|
||||
if (!attached) return;
|
||||
attached = false;
|
||||
const index = layerStack.indexOf(dismiss);
|
||||
if (index !== -1) layerStack.splice(index, 1);
|
||||
document.removeEventListener("keydown", handleKeyDown);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user