The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
fix(sdk,embed-js): Don't close ChartSettingsWidgetPopup on touch events (#71979)
Timofey Kachalov5b53f1f8dc2e
diff --git a/e2e/support/helpers/e2e-mobile-device-helpers.ts b/e2e/support/helpers/e2e-mobile-device-helpers.tsindex 2eceb8e42b3..e9680b923f9 100644--- a/e2e/support/helpers/e2e-mobile-device-helpers.ts+++ b/e2e/support/helpers/e2e-mobile-device-helpers.ts@@ -35,6 +35,26 @@ export function disableTouchEmulation() {);}+/**+ * Dispatches a native touchstart event on the element.+ * Unlike cy.realTouch(), this fires a real DOM TouchEvent that bubbles+ * to document — needed to test Mantine's useClickOutside which listens+ * for touchstart at the document level.+ */+export function fireTouchStart(selector: string) {+ cy.findByTestId(selector).then(($el) => {+ const el = $el[0];+ const touch = new Touch({ identifier: 0, target: el });+ el.dispatchEvent(+ new TouchEvent("touchstart", {+ bubbles: true,+ cancelable: true,+ touches: [touch],+ }),+ );+ });+}+export function longPressAndDrag(selector: string,startX: number,diff --git a/e2e/test-component/scenarios/embedding-sdk/touch-question-settings-dropdown.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/touch-question-settings-dropdown.cy.spec.tsxnew file mode 100644index 00000000000..033812aff61--- /dev/null+++ b/e2e/test-component/scenarios/embedding-sdk/touch-question-settings-dropdown.cy.spec.tsx@@ -0,0 +1,49 @@+import { InteractiveQuestion } from "@metabase/embedding-sdk-react";++import { ORDERS_BY_YEAR_QUESTION_ID } from "e2e/support/cypress_sample_instance_data";+import * as H from "e2e/support/helpers";+import { getSdkRoot } from "e2e/support/helpers/e2e-embedding-sdk-helpers";+import {+ disableTouchEmulation,+ enableTouchEmulation,+ fireTouchStart,+} from "e2e/support/helpers/e2e-mobile-device-helpers";+import { mountSdkContent } from "e2e/support/helpers/embedding-sdk-component-testing";+import { signInAsAdminAndEnableEmbeddingSdk } from "e2e/support/helpers/embedding-sdk-testing";+import { mockAuthProviderAndJwtSignIn } from "e2e/support/helpers/embedding-sdk-testing/embedding-sdk-helpers";++describe("scenarios > embedding-sdk > touch-question-settings-dropdown", () => {+ beforeEach(() => {+ signInAsAdminAndEnableEmbeddingSdk();+ cy.signOut();+ mockAuthProviderAndJwtSignIn();++ cy.viewport("iphone-x");+ enableTouchEmulation();+ });++ afterEach(() => {+ disableTouchEmulation();+ });++ it("should not close the settings dropdown when tapping inside a child popover", () => {+ mountSdkContent(+ <InteractiveQuestion questionId={ORDERS_BY_YEAR_QUESTION_ID} />,+ );++ H.openVizSettingsSidebar();++ getSdkRoot().within(() => {+ cy.findByTestId("settings-count").click();++ // Tap inside the child popover — should NOT close the parent dropdown+ fireTouchStart("series-settings");+ cy.findByTestId("series-settings").should("exist");+ cy.findByTestId("chartsettings-sidebar").should("be.visible");++ // Click inside the parent dropdown — should close the child popover+ cy.findByTestId("chartsettings-sidebar").realTouch({ x: 1, y: 1 });+ cy.findByTestId("series-settings").should("not.exist");+ });+ });+});diff --git a/frontend/src/metabase/common/components/EventSandbox/EventSandbox.tsx b/frontend/src/metabase/common/components/EventSandbox/EventSandbox.tsxindex e881df5a9d7..84450457fc8 100644--- a/frontend/src/metabase/common/components/EventSandbox/EventSandbox.tsx+++ b/frontend/src/metabase/common/components/EventSandbox/EventSandbox.tsx@@ -67,6 +67,10 @@ const eventsSandboxedByDefault: EventName[] = ["onMouseOver","onMouseOut","onMouseUp",+ "onTouchCancel",+ "onTouchEnd",+ "onTouchMove",+ "onTouchStart",];/** All supported events that start with 'onMouse' */