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
Prevent scrollbar flicker from cell tooltips in TreeTable (#78337)
Oleh Kb7d519320b65
diff --git a/frontend/src/metabase/ui/components/data-display/TreeTable/TreeTable.tsx b/frontend/src/metabase/ui/components/data-display/TreeTable/TreeTable.tsxindex 73e1ec1713c..17fb293be36 100644--- a/frontend/src/metabase/ui/components/data-display/TreeTable/TreeTable.tsx+++ b/frontend/src/metabase/ui/components/data-display/TreeTable/TreeTable.tsx@@ -1,3 +1,4 @@+import { useMergedRef } from "@mantine/hooks";import type { Row } from "@tanstack/react-table";import type { VirtualItem } from "@tanstack/react-virtual";import cx from "classnames";@@ -8,12 +9,14 @@ import {useEffect,useMemo,useRef,+ useState,} from "react";import {Box,Center,Flex,+ TooltipPortalTargetProvider,type TreeTableRowPinnedPosition,} from "metabase/ui";@@ -68,6 +71,11 @@ export function TreeTable<TData extends TreeNodeData>({const rootRef = useRef<HTMLDivElement>(null);+ // Portal cell tooltips into the scroll container so a tooltip positioned past+ // the fold is clipped by the table instead of stretching <body> (metabase#GDGT-2822)+ const [portalTarget, setPortalTarget] = useState<HTMLElement | null>(null);+ const bodyRef = useMergedRef(containerRef, setPortalTarget);+const handleKeyDownWithFocus = useCallback((event: KeyboardEvent<HTMLElement>) => {const isCheckboxFocused =@@ -183,92 +191,102 @@ export function TreeTable<TData extends TreeNodeData>({);return (- <Flex- ref={rootRef}- className={cx(S.root, classNames?.root)}- style={styles?.root}- direction="column"- flex={1}- mih={0}- w="100%"- role="treegrid"- tabIndex={0}- aria-label={ariaLabel}- aria-labelledby={ariaLabelledBy}- onKeyDown={handleKeyDownWithFocus}- >- <Box- ref={containerRef}- className={cx(S.body, classNames?.body, { [S.measuring]: !isMeasured })}+ <TooltipPortalTargetProvider target={portalTarget}>+ <Flex+ ref={rootRef}+ className={cx(S.root, classNames?.root)}+ style={styles?.root}+ direction="column"flex={1}- style={styles?.body}+ mih={0}+ w="100%"+ role="treegrid"+ tabIndex={0}+ aria-label={ariaLabel}+ aria-labelledby={ariaLabelledBy}+ onKeyDown={handleKeyDownWithFocus}>- {showEmptyState ? (- <Center h="100%" p="xl" c="text-disabled">- {emptyState}- </Center>- ) : (- <>- <Box- pos="sticky"- top={0}- style={{ minWidth: totalContentWidth, zIndex: 1 }}- >- <TreeTableHeader- table={table}- columnWidths={columnWidths}- showCheckboxes={showCheckboxes}- headerVariant={headerVariant}- classNames={classNames}- styles={styles}- isMeasured={isMeasured}- totalContentWidth={totalContentWidth}- getSelectionState={getSelectionState}- onHeaderCheckboxClick={onHeaderCheckboxClick}- headerCheckboxAriaLabel={headerCheckboxAriaLabel}- />- {topPinnedRows.length > 0 && (- <Box- className={classNames?.pinnedTop}- style={{ minWidth: totalContentWidth, ...styles?.pinnedTop }}- >- {topPinnedRows.map((row, index) =>- renderRow(row, index, "top"),- )}- </Box>- )}- </Box>- <Box- pos="relative"- style={{ height: totalSize, minWidth: totalContentWidth }}- >- {virtualRows.map((virtualItem) => {- const row = centerRows[virtualItem.index];- if (!row) {- return null;- }- const rowIndex = topPinnedRows.length + virtualItem.index;- return renderRow(row, rowIndex, virtualItem);- })}- </Box>-- {bottomPinnedRows.length > 0 && (+ <Box+ ref={bodyRef}+ className={cx(S.body, classNames?.body, {+ [S.measuring]: !isMeasured,+ })}+ flex={1}+ style={styles?.body}+ >+ {showEmptyState ? (+ <Center h="100%" p="xl" c="text-disabled">+ {emptyState}+ </Center>+ ) : (+ <><Boxpos="sticky"- bottom={0}- className={classNames?.pinnedBottom}- style={{ minWidth: totalContentWidth, ...styles?.pinnedBottom }}+ top={0}+ style={{ minWidth: totalContentWidth, zIndex: 1 }}+ >+ <TreeTableHeader+ table={table}+ columnWidths={columnWidths}+ showCheckboxes={showCheckboxes}+ headerVariant={headerVariant}+ classNames={classNames}+ styles={styles}+ isMeasured={isMeasured}+ totalContentWidth={totalContentWidth}+ getSelectionState={getSelectionState}+ onHeaderCheckboxClick={onHeaderCheckboxClick}+ headerCheckboxAriaLabel={headerCheckboxAriaLabel}+ />+ {topPinnedRows.length > 0 && (+ <Box+ className={classNames?.pinnedTop}+ style={{+ minWidth: totalContentWidth,+ ...styles?.pinnedTop,+ }}+ >+ {topPinnedRows.map((row, index) =>+ renderRow(row, index, "top"),+ )}+ </Box>+ )}+ </Box>+ <Box+ pos="relative"+ style={{ height: totalSize, minWidth: totalContentWidth }}>- {bottomPinnedRows.map((row, index) => {- const rowIndex =- topPinnedRows.length + centerRows.length + index;- return renderRow(row, rowIndex, "bottom");+ {virtualRows.map((virtualItem) => {+ const row = centerRows[virtualItem.index];+ if (!row) {+ return null;+ }+ const rowIndex = topPinnedRows.length + virtualItem.index;+ return renderRow(row, rowIndex, virtualItem);})}</Box>- )}- </>- )}- </Box>- </Flex>++ {bottomPinnedRows.length > 0 && (+ <Box+ pos="sticky"+ bottom={0}+ className={classNames?.pinnedBottom}+ style={{+ minWidth: totalContentWidth,+ ...styles?.pinnedBottom,+ }}+ >+ {bottomPinnedRows.map((row, index) => {+ const rowIndex =+ topPinnedRows.length + centerRows.length + index;+ return renderRow(row, rowIndex, "bottom");+ })}+ </Box>+ )}+ </>+ )}+ </Box>+ </Flex>+ </TooltipPortalTargetProvider>);}diff --git a/frontend/src/metabase/ui/components/overlays/Tooltip/Tooltip.tsx b/frontend/src/metabase/ui/components/overlays/Tooltip/Tooltip.tsxnew file mode 100644index 00000000000..5cd847fdec9--- /dev/null+++ b/frontend/src/metabase/ui/components/overlays/Tooltip/Tooltip.tsx@@ -0,0 +1,43 @@+import { Tooltip as MantineTooltip, type TooltipProps } from "@mantine/core";+import {+ type PropsWithChildren,+ createContext,+ forwardRef,+ useContext,+ useMemo,+} from "react";++const TooltipPortalTargetContext = createContext<HTMLElement | null>(null);++export function TooltipPortalTargetProvider({+ target,+ children,+}: PropsWithChildren<{ target: HTMLElement | null }>) {+ return (+ <TooltipPortalTargetContext.Provider value={target}>+ {children}+ </TooltipPortalTargetContext.Provider>+ );+}++const TooltipImpl = forwardRef<HTMLDivElement, TooltipProps>(+ function TooltipImpl({ portalProps, ...props }, ref) {+ const contextTarget = useContext(TooltipPortalTargetContext);+ const resolvedPortalProps = useMemo(+ () =>+ contextTarget && portalProps?.target == null+ ? { ...portalProps, target: contextTarget }+ : portalProps,+ [contextTarget, portalProps],+ );++ return (+ <MantineTooltip {...props} portalProps={resolvedPortalProps} ref={ref} />+ );+ },+);++export const Tooltip = Object.assign(TooltipImpl, {+ Floating: MantineTooltip.Floating,+ Group: MantineTooltip.Group,+});diff --git a/frontend/src/metabase/ui/components/overlays/Tooltip/index.ts b/frontend/src/metabase/ui/components/overlays/Tooltip/index.tsindex e1c785a9136..af01c0d92b3 100644--- a/frontend/src/metabase/ui/components/overlays/Tooltip/index.ts+++ b/frontend/src/metabase/ui/components/overlays/Tooltip/index.ts@@ -1,3 +1,3 @@-export { Tooltip } from "@mantine/core";+export { Tooltip, TooltipPortalTargetProvider } from "./Tooltip";export type { TooltipProps } from "@mantine/core";export { tooltipOverrides } from "./Tooltip.config";