From 2e7f2e40b89a0a9fa6ca2cbe951acbfdba1daa1d Mon Sep 17 00:00:00 2001 From: Nathan Vasse Date: Mon, 24 Mar 2025 15:28:52 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8(front)=20handle=20item=20title=20over?= =?UTF-8?q?flow=20in=20explorer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When there is a an overflow, we display a tooltip on hover. Fixes #58 --- .../explorer/components/Explorer.scss | 15 ++++++ .../explorer/components/ExplorerGrid.tsx | 52 ++++++++++++++++--- 2 files changed, 60 insertions(+), 7 deletions(-) diff --git a/src/frontend/apps/drive/src/features/explorer/components/Explorer.scss b/src/frontend/apps/drive/src/features/explorer/components/Explorer.scss index a96390aa..a1088472 100644 --- a/src/frontend/apps/drive/src/features/explorer/components/Explorer.scss +++ b/src/frontend/apps/drive/src/features/explorer/components/Explorer.scss @@ -83,10 +83,25 @@ text-decoration: none; color: var(--c--theme--colors--greyscale-700); + .c__tooltip { + max-width: 100%; + } + + > img { + // Need to set width and height to prevent layout shift + // and to make overflow calculations work correctly before + // the image is loaded + width: 32px; + height: 32px; + } + &__text { font-size: 14px; font-weight: 400; color: var(--c--theme--colors--greyscale-1000); + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; } } diff --git a/src/frontend/apps/drive/src/features/explorer/components/ExplorerGrid.tsx b/src/frontend/apps/drive/src/features/explorer/components/ExplorerGrid.tsx index 08a6111b..055514d5 100644 --- a/src/frontend/apps/drive/src/features/explorer/components/ExplorerGrid.tsx +++ b/src/frontend/apps/drive/src/features/explorer/components/ExplorerGrid.tsx @@ -7,7 +7,7 @@ import { getCoreRowModel, useReactTable, } from "@tanstack/react-table"; -import { useCallback, useRef, useState } from "react"; +import { useCallback, useEffect, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import { NavigationEventType, useExplorer } from "./ExplorerContext"; import clsx from "clsx"; @@ -36,12 +36,7 @@ export const ExplorerGrid = () => { // icon as which get re-fetched on every render. const nameCellRenderer = useCallback( (params: CellContext) => ( -
- - - {params.row.original.title} - -
+ ), [] ); @@ -320,3 +315,46 @@ const ItemActions = ({ item }: { item: Item }) => { ); }; + +const ItemTitle = ({ item }: { item: Item }) => { + const ref = useRef(null); + const [isOverflown, setIsOverflown] = useState(false); + + useEffect(() => { + const checkOverflow = () => { + const element = ref.current; + // Should always be defined, but just in case. + if (element) { + setIsOverflown(element.scrollWidth > element.clientWidth); + } + }; + checkOverflow(); + + window.addEventListener("resize", checkOverflow); + return () => { + window.removeEventListener("resize", checkOverflow); + }; + }, [item.title]); + + const renderTitle = () => { + // We need to have the element holding the ref nested because the Tooltip component + // seems to make the top-most children ref null. + return ( +
+ + {item.title} + +
+ ); + }; + return ( +
+ + {isOverflown ? ( + {renderTitle()} + ) : ( + renderTitle() + )} +
+ ); +};