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() + )} +
+ ); +};