Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(popup): keep a tap's click that ends beside what it pressed
Elian Doran06ef7a58977b
diff --git a/apps/client/src/widgets/react/Popup.spec.tsx b/apps/client/src/widgets/react/Popup.spec.tsxindex a9893e2db1..e9c6ea135e 100644--- a/apps/client/src/widgets/react/Popup.spec.tsx+++ b/apps/client/src/widgets/react/Popup.spec.tsx@@ -311,6 +311,13 @@ describe("Popup", () => {press(popup);click(icon);expect(iconClicked).toHaveBeenCalledTimes(3);++ // A tap that starts on the button's glyph and ends on its padding clicks the button.+ const glyph = document.createElement("span");+ icon.append(glyph);+ press(glyph);+ click(icon);+ expect(iconClicked).toHaveBeenCalledTimes(4);cover.remove();icon.remove();});diff --git a/apps/client/src/widgets/react/Popup.tsx b/apps/client/src/widgets/react/Popup.tsxindex 690be25e74..5a521bb8ca 100644--- a/apps/client/src/widgets/react/Popup.tsx+++ b/apps/client/src/widgets/react/Popup.tsx@@ -211,13 +211,16 @@ export default function Popup({ anchor, placement = "bottom-start", offset: gap/*** Drops the click that follows a press dismissing a popup when it lands on something other than- * `pressed`. A cover or backdrop is removed with the popup before a tap's click, so the click lands- * on the element under it, such as an icon under the icon picker's menu.+ * `pressed` or an element containing it. A cover or backdrop is removed with the popup before a+ * tap's click, so the click lands on the element under it, such as an icon under the icon picker's+ * menu. A tap that ends outside `pressed` clicks the element that contains both ends of the tap.*/function swallowStrayClick(pressed: Node) {const onClick = (e: MouseEvent) => {stop();- if (e.target instanceof Node && pressed.contains(e.target)) return;+ if (e.target instanceof Node && (pressed.contains(e.target) || e.target.contains(pressed))) {+ return;+ }e.preventDefault();e.stopPropagation();};