From e431f26488da97a5b0ad8bf0affeed6a906c26e0 Mon Sep 17 00:00:00 2001 From: eti Date: Tue, 13 Oct 2026 05:26:31 +0200 Subject: [PATCH] web/components: drop position-anchor while pinning a closing popover Signed-off-by: eti --- web/src/lib/popoverExit.ts | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/web/src/lib/popoverExit.ts b/web/src/lib/popoverExit.ts index 20e35a38f..6aa5ac9d7 100644 --- a/web/src/lib/popoverExit.ts +++ b/web/src/lib/popoverExit.ts @@ -23,22 +23,6 @@ import type { Attachment } from "svelte/attachments"; * contents lazily and would otherwise empty itself out mid-exit. */ -const pinned = [ - "display", - "position", - "position-area", - "position-try-fallbacks", - "justify-self", - "align-self", - "margin", - "top", - "left", - "right", - "bottom", - "width", - "height" -]; - const fixedOrigin = (parent: HTMLElement) => { const probe = document.createElement("div"); probe.style.cssText = "position:fixed;top:0;left:0;width:0;height:0"; @@ -52,11 +36,16 @@ export const popoverExit = (onExiting?: (exiting: boolean) => void): Attachment => (node) => { let exiting = false; + let unpinned: [string, string][] = []; const settle = () => { if (!exiting) return; exiting = false; - for (const property of pinned) node.style.removeProperty(property); + for (const [property, value] of unpinned) { + if (value) node.style.setProperty(property, value); + else node.style.removeProperty(property); + } + unpinned = []; onExiting?.(false); }; @@ -69,6 +58,7 @@ export const popoverExit = display: getComputedStyle(node).display, position: "fixed", // the anchor rules own the insets, so they have to stand down first + "position-anchor": "none", "position-area": "none", "position-try-fallbacks": "none", "justify-self": "normal", @@ -81,6 +71,10 @@ export const popoverExit = width: `${box.width}px`, height: `${box.height}px` }; + unpinned = Object.keys(pin).map((property) => [ + property, + node.style.getPropertyValue(property) + ]); for (const [property, value] of Object.entries(pin)) node.style.setProperty(property, value); }; -- 2.54.0