From a7650fe7ad4af8a33d7e3ee9d7ae901d2bf00fd1 Mon Sep 17 00:00:00 2001 From: Brandon Dow Date: Fri, 10 May 2024 16:15:43 -0400 Subject: [PATCH] fix: Fallback message for virtual table was exceeding table header width --- src/components/Table/GridTable.stories.tsx | 12 +++++++++++- src/components/Table/GridTable.tsx | 9 +++++---- src/components/Table/utils/utils.tsx | 4 ++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/components/Table/GridTable.stories.tsx b/src/components/Table/GridTable.stories.tsx index fa3223995..ea67d397b 100644 --- a/src/components/Table/GridTable.stories.tsx +++ b/src/components/Table/GridTable.stories.tsx @@ -298,7 +298,17 @@ export function InfiniteScrollWithLoader() { export function NoRowsFallback() { const nameColumn: GridColumn = { header: "Name", data: ({ name }) => name }; const valueColumn: GridColumn = { header: "Value", data: ({ value }) => value }; - return ; + return ( +
+ +
+ ); } // Make a `Row` ADT for a table with a header + 3 levels of nesting diff --git a/src/components/Table/GridTable.tsx b/src/components/Table/GridTable.tsx index cc9bd0698..537bf34f6 100644 --- a/src/components/Table/GridTable.tsx +++ b/src/components/Table/GridTable.tsx @@ -2,7 +2,7 @@ import memoizeOne from "memoize-one"; import { runInAction } from "mobx"; import React, { MutableRefObject, ReactElement, useEffect, useMemo, useRef, useState } from "react"; import { Components, Virtuoso, VirtuosoHandle } from "react-virtuoso"; -import { Loader } from "src/components"; +import { getTableRefWidthStyles, Loader } from "src/components"; import { DiscriminateUnion, GridRowKind } from "src/components/index"; import { PresentationFieldProps, PresentationProvider } from "src/components/PresentationContext"; import { GridTableApi, GridTableApiImpl } from "src/components/Table/GridTableApi"; @@ -20,7 +20,7 @@ import { import { assignDefaultColumnIds } from "src/components/Table/utils/columns"; import { GridRowLookup } from "src/components/Table/utils/GridRowLookup"; import { TableStateContext } from "src/components/Table/utils/TableState"; -import { EXPANDABLE_HEADER, KEPT_GROUP, isCursorBelowMidpoint, zIndices } from "src/components/Table/utils/utils"; +import { EXPANDABLE_HEADER, isCursorBelowMidpoint, KEPT_GROUP, zIndices } from "src/components/Table/utils/utils"; import { Css, Only } from "src/Css"; import { useComputed } from "src/hooks"; import { useRenderCount } from "src/hooks/useRenderCount"; @@ -486,7 +486,7 @@ export function GridTable = an {/* If virtualized take some pixels off the width to accommodate when virtuoso's scrollbar is introduced. */} {/* Otherwise a horizontal scrollbar will _always_ appear once the vertical scrollbar is needed */} -
+
{renders[_as]( style, id, @@ -713,7 +713,8 @@ function renderVirtual( if (firstRowMessage) { if (index === 0) { return ( -
+ // Ensure the fallback message is the same width as the table +
{firstRowMessage}
); diff --git a/src/components/Table/utils/utils.tsx b/src/components/Table/utils/utils.tsx index b3d3f836f..9d48a2524 100644 --- a/src/components/Table/utils/utils.tsx +++ b/src/components/Table/utils/utils.tsx @@ -301,3 +301,7 @@ export function recursivelyGetContainingRow( return undefined; } + +export function getTableRefWidthStyles(isVirtual: boolean) { + return Css.w100.if(isVirtual).w("calc(100% - 20px)").$; +}