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
feat(sdk,embed-js): Improve touch device support in dropdown components in Notebook Editor (#71562)
Timofey Kachalov0336557161d8
diff --git a/e2e/test-component/scenarios/embedding-sdk/touch-brush.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/touch-brush.cy.spec.tsxindex ca191cfd12a..513a7746f5d 100644--- a/e2e/test-component/scenarios/embedding-sdk/touch-brush.cy.spec.tsx+++ b/e2e/test-component/scenarios/embedding-sdk/touch-brush.cy.spec.tsx@@ -22,6 +22,8 @@ function waitForChart() {// Wait for ECharts to finish rendering data points.echartsContainer().find("path").should("have.length.greaterThan", 0);});+ // Wait for brush event listeners to attach after chart renders.+ cy.wait(100);}describe("scenarios > embedding-sdk > touch-brush", () => {diff --git a/e2e/test-component/scenarios/embedding-sdk/touch-join-column-picker.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/touch-join-column-picker.cy.spec.tsxnew file mode 100644index 00000000000..260382ecb9c--- /dev/null+++ b/e2e/test-component/scenarios/embedding-sdk/touch-join-column-picker.cy.spec.tsx@@ -0,0 +1,100 @@+import { InteractiveQuestion } from "@metabase/embedding-sdk-react";++import { popover } from "e2e/support/helpers";+import { getSdkRoot } from "e2e/support/helpers/e2e-embedding-sdk-helpers";+import {+ disableTouchEmulation,+ enableTouchEmulation,+} from "e2e/support/helpers/e2e-mobile-device-helpers";+import { mountSdkContent } from "e2e/support/helpers/embedding-sdk-component-testing/component-embedding-sdk-helpers";+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 join column picker", () => {+ beforeEach(() => {+ signInAsAdminAndEnableEmbeddingSdk();+ cy.signOut();+ mockAuthProviderAndJwtSignIn();+ });++ describe("touch device", () => {+ beforeEach(() => {+ cy.viewport("iphone-x", "landscape");+ enableTouchEmulation();+ });++ afterEach(() => {+ disableTouchEmulation();+ });++ it("should show bucket picker button text on touch devices", () => {+ mountSdkContent(+ <div style={{ display: "flex", padding: "20px" }}>+ <InteractiveQuestion questionId="new" />+ </div>,+ );++ // Pick Orders table+ popover().within(() => {+ cy.findByText("Orders").click();+ });++ // Add join+ getSdkRoot().within(() => {+ cy.button("Join data").click();+ });++ // Pick Products table+ popover().within(() => {+ cy.findByText("Products").click();+ });++ // Open left column picker and find a date column with temporal bucket+ cy.findByLabelText("Left column").click();+ popover().within(() => {+ // Scroll to the bucket picker item to ensure it's in view+ cy.findByTestId("dimension-list-item-binning").scrollIntoView();++ // The "by month" bucket button should be visible on touch devices+ cy.findByTestId("dimension-list-item-binning").should("be.visible");+ cy.findByTestId("dimension-list-item-binning").should(+ "not.have.css",+ "visibility",+ "hidden",+ );+ });+ });++ it("should not autofocus search field in column picker on touch devices", () => {+ mountSdkContent(+ <div style={{ display: "flex", padding: "20px" }}>+ <InteractiveQuestion questionId="new" />+ </div>,+ );++ // Pick Orders table+ popover().within(() => {+ cy.findByText("Orders").click();+ });++ // Add join+ getSdkRoot().within(() => {+ cy.button("Join data").click();+ });++ // Pick Products table+ popover().within(() => {+ cy.findByText("Products").click();+ });++ // Open left column picker+ cy.findByLabelText("Left column").click();++ // Search field should exist but not be focused on touch devices+ popover().within(() => {+ cy.findByTestId("list-search-field").should("exist");+ cy.findByTestId("list-search-field").should("not.be.focused");+ });+ });+ });+});diff --git a/frontend/src/metabase/common/components/AccordionList/AccordionListCell.tsx b/frontend/src/metabase/common/components/AccordionList/AccordionListCell.tsxindex ab967196f84..84fbb9d01e1 100644--- a/frontend/src/metabase/common/components/AccordionList/AccordionListCell.tsx+++ b/frontend/src/metabase/common/components/AccordionList/AccordionListCell.tsx@@ -15,6 +15,7 @@ import { ListSearchField } from "metabase/common/components/ListSearchField";import { LoadingSpinner } from "metabase/common/components/LoadingSpinner";import ListS from "metabase/css/components/list.module.css";import CS from "metabase/css/core/index.css";+import { isTouchDevice } from "metabase/lib/browser";import type { TextInputProps } from "metabase/ui";import { Box, Icon, Text, isValidIconName } from "metabase/ui";import type { ColorName } from "metabase/ui/colors/types";@@ -322,7 +323,7 @@ export const AccordionListCell = forwardRef(function AccordionListCell<borderBottom = true;content = (<ListSearchField- autoFocus+ autoFocus={!isTouchDevice()}onChange={(e) => onChangeSearchText(e.target.value)}onResetClick={() => onChangeSearchText("")}value={searchText}diff --git a/frontend/src/metabase/common/components/BucketPickerPopover/BucketPickerPopover.module.css b/frontend/src/metabase/common/components/BucketPickerPopover/BucketPickerPopover.module.cssindex b4072002fe4..fd50c0d1adb 100644--- a/frontend/src/metabase/common/components/BucketPickerPopover/BucketPickerPopover.module.css+++ b/frontend/src/metabase/common/components/BucketPickerPopover/BucketPickerPopover.module.css@@ -9,6 +9,18 @@visibility: visible;}+/* No hover on touch devices, so always show the button with readable text */+@media (hover: none) and (pointer: coarse) {+ .triggerButton {+ visibility: visible;+ color: var(--mb-color-brand);+ }++ .chevronIcon {+ color: var(--mb-color-brand);+ }+}+.triggerButtonLabel {display: flex;gap: 0.5rem;diff --git a/frontend/src/metabase/common/components/BucketPickerPopover/BucketPickerPopover.tsx b/frontend/src/metabase/common/components/BucketPickerPopover/BucketPickerPopover.tsxindex 033ba980818..b3298a46fd5 100644--- a/frontend/src/metabase/common/components/BucketPickerPopover/BucketPickerPopover.tsx+++ b/frontend/src/metabase/common/components/BucketPickerPopover/BucketPickerPopover.tsx@@ -1,5 +1,12 @@import cx from "classnames";-import { useCallback, useMemo, useState } from "react";+import {+ type CSSProperties,+ type MouseEvent,+ type TouchEvent,+ useCallback,+ useMemo,+ useState,+} from "react";import { t } from "ttag";import { SelectList } from "metabase/common/components/SelectList";@@ -51,7 +58,7 @@ export function BucketPickerPopover({const [isExpanded, setIsExpanded] = useState(shouldBeExpanded);- const handleExpand = useCallback((event: React.MouseEvent) => {+ const handleExpand = useCallback((event: MouseEvent) => {event.stopPropagation();setIsExpanded(true);}, []);@@ -108,14 +115,20 @@ export function BucketPickerPopover({)}</Button></Popover.Target>- <Popover.Dropdown>+ <Popover.Dropdown+ // Prevent touch events from bubbling to the parent dropdown,+ // which causes it to scroll/select items on mobile (metabase#EMB-1471)+ onTouchStart={(e: TouchEvent) => e.stopPropagation()}+ onTouchMove={(e: TouchEvent) => e.stopPropagation()}+ ><SelectListp="sm"miw="10rem"style={{"--bucket-picker-active-color": activeColor,- } as React.CSSProperties+ overscrollBehavior: "contain",+ } as CSSProperties}>{visibleItems.map((item) => (diff --git a/frontend/src/metabase/common/components/SelectList/SelectListItem.styled.tsx b/frontend/src/metabase/common/components/SelectList/SelectListItem.styled.tsxindex 28a86eb93c0..cc9fde6ec3c 100644--- a/frontend/src/metabase/common/components/SelectList/SelectListItem.styled.tsx+++ b/frontend/src/metabase/common/components/SelectList/SelectListItem.styled.tsx@@ -43,11 +43,13 @@ export const BaseItemRoot = styled.li<{margin-bottom: 0;}- ${(props) => props.isSelected && activeItemCss}-- &:hover {- ${activeItemCss}+ @media (hover: hover) {+ &:hover {+ ${activeItemCss}+ }}++ ${(props) => props.isSelected && activeItemCss}`;const getGridTemplateColumns = (hasLeftIcon: boolean, hasRightIcon: boolean) =>diff --git a/frontend/src/metabase/lib/browser.ts b/frontend/src/metabase/lib/browser.tsindex 83cf58b5813..66dd7cc47ac 100644--- a/frontend/src/metabase/lib/browser.ts+++ b/frontend/src/metabase/lib/browser.ts@@ -54,10 +54,11 @@ export const isTouchDevice = () => {}if (typeof window.matchMedia === "function") {- const hasCoarsePointer = window.matchMedia("(pointer: coarse)").matches;- const cannotHover = window.matchMedia("(hover: none)").matches;+ const hasCoarsePointerSupport =+ window.matchMedia("(pointer: coarse)").matches;+ const hasHoverSupport = window.matchMedia("(hover: hover)").matches;- if (hasCoarsePointer && cannotHover) {+ if (hasCoarsePointerSupport && !hasHoverSupport) {return true;}}diff --git a/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookStep.module.css b/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookStep.module.cssindex 50722457418..7a919693d74 100644--- a/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookStep.module.css+++ b/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookStep.module.css@@ -30,7 +30,7 @@visibility: visible;}-@media (hover: none) {+@media (hover: none) and (pointer: coarse) {.StepRoot .StepHeader {visibility: visible;}diff --git a/frontend/src/metabase/visualizations/components/EChartsRenderer/EChartsRenderer.styled.tsx b/frontend/src/metabase/visualizations/components/EChartsRenderer/EChartsRenderer.styled.tsxindex 694e117a9b0..d12e41f6db1 100644--- a/frontend/src/metabase/visualizations/components/EChartsRenderer/EChartsRenderer.styled.tsx+++ b/frontend/src/metabase/visualizations/components/EChartsRenderer/EChartsRenderer.styled.tsx@@ -16,7 +16,7 @@ export const EChartsRendererRoot = styled.div`scrolling on touch devices. We override with auto so the browser handlesscroll in all directions. Brush selection is gated behind a long-pressthat calls preventDefault on touchmove to reclaim the gesture (see useBrush). */- @media (hover: none) {+ @media (hover: none) and (pointer: coarse) {& svg {touch-action: auto !important;}