Skip to content

Commit 463c2b9

Browse files
committed
chore: add isVirtualized prop
1 parent 96cbd91 commit 463c2b9

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

packages/blade/src/components/Table/Table.web.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ const _Table = forwardRef(
478478
console.log('Parent dimensions:', { width, height });
479479
// You can use the width and height to set your table dimensions
480480
}
481-
}, [ref]);
481+
}, [height, ref, width]);
482482

483483
useEffect(() => {
484484
// Get the total number of items
@@ -657,6 +657,7 @@ const _Table = forwardRef(
657657
setHasHoverActions,
658658
columnCount,
659659
gridTemplateColumns,
660+
isVirtualized,
660661
}),
661662
[
662663
selectionType,
@@ -684,6 +685,7 @@ const _Table = forwardRef(
684685
showBorderedCells,
685686
hasHoverActions,
686687
setHasHoverActions,
688+
isVirtualized,
687689
],
688690
);
689691

@@ -696,7 +698,7 @@ const _Table = forwardRef(
696698
alignItems="center"
697699
justifyContent="center"
698700
height={height}
699-
width={width}
701+
width={isVirtualized ? width : undefined}
700702
{...getStyledProps(rest)}
701703
{...metaAttribute({ name: MetaConstants.Table })}
702704
{...makeAnalyticsAttribute(rest)}
@@ -710,7 +712,7 @@ const _Table = forwardRef(
710712
position="relative"
711713
{...getStyledProps(rest)}
712714
{...metaAttribute({ name: MetaConstants.Table })}
713-
width={width || `${VirtualizedTableDimensions.width}px`}
715+
width={isVirtualized ? width || `${VirtualizedTableDimensions.width}px` : undefined}
714716
>
715717
{isRefreshSpinnerMounted && (
716718
<RefreshWrapper
@@ -740,7 +742,7 @@ const _Table = forwardRef(
740742
sort={sortFunctions ? sort : null}
741743
$styledProps={{
742744
height: height || `${VirtualizedTableDimensions.height}px`,
743-
width: width || `${VirtualizedTableDimensions.width}px`,
745+
width: isVirtualized ? width || `${VirtualizedTableDimensions.width}px` : undefined,
744746
isVirtualized,
745747
isSelectable: selectionType !== 'none',
746748
showStripedRows,

packages/blade/src/components/Table/TableContext.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export type TableContextType = {
4242
setHasHoverActions: (hasHoverActions: boolean) => void;
4343
columnCount: number;
4444
gridTemplateColumns: string | undefined;
45+
isVirtualized?: boolean;
4546
};
4647

4748
const TableContext = React.createContext<TableContextType>({
@@ -70,6 +71,7 @@ const TableContext = React.createContext<TableContextType>({
7071
setHasHoverActions: () => {},
7172
columnCount: 0,
7273
gridTemplateColumns: undefined,
74+
isVirtualized: false,
7375
});
7476

7577
const useTableContext = (): TableContextType => {

packages/blade/src/components/Table/TableHeader.web.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ const StyledHeaderRow = styled(HeaderRow)<{
213213
$hasHoverActions: boolean;
214214
$selectionType: TableProps<unknown>['selectionType'];
215215
$columnCount: number;
216+
$isVirtualized?: boolean;
216217
}>(
217218
({
218219
theme,
@@ -221,21 +222,23 @@ const StyledHeaderRow = styled(HeaderRow)<{
221222
$hasHoverActions,
222223
$selectionType,
223224
$columnCount,
225+
$isVirtualized,
224226
}) => ({
225227
'& th': $showBorderedCells
226228
? {
227229
borderRightWidth: makeSpace(getIn(theme.border.width, tableRow.borderBottomWidth)),
228230
borderRightColor: getIn(theme.colors, tableRow.borderColor),
229231
borderRightStyle: 'solid',
230-
//TODO: add check to only add this for virtalized tables
231-
display: 'grid',
232-
gridTemplateColumns: $gridTemplateColumns
233-
? `${$gridTemplateColumns} ${$hasHoverActions ? 'min-content' : ''}`
234-
: ` ${
235-
$selectionType === 'multiple' ? 'min-content' : ''
236-
} repeat(${$columnCount},minmax(100px, 1fr)) ${
237-
$hasHoverActions ? 'min-content' : ''
238-
} !important;`,
232+
...($isVirtualized && {
233+
display: 'grid',
234+
gridTemplateColumns: $gridTemplateColumns
235+
? `${$gridTemplateColumns} ${$hasHoverActions ? 'min-content' : ''}`
236+
: ` ${
237+
$selectionType === 'multiple' ? 'min-content' : ''
238+
} repeat(${$columnCount},minmax(100px, 1fr)) ${
239+
$hasHoverActions ? 'min-content' : ''
240+
} !important;`,
241+
}),
239242
}
240243
: undefined,
241244
'& th:last-child ': {
@@ -260,6 +263,7 @@ const _TableHeaderRow = ({
260263
hasHoverActions,
261264
gridTemplateColumns,
262265
columnCount,
266+
isVirtualized,
263267
} = useTableContext();
264268
const isMultiSelect = selectionType === 'multiple';
265269
const isAllSelected = selectedRows && selectedRows.length === totalItems;
@@ -285,6 +289,7 @@ const _TableHeaderRow = ({
285289
$hasHoverActions={hasHoverActions}
286290
$selectionType={selectionType}
287291
$columnCount={columnCount}
292+
$isVirtualized={isVirtualized}
288293
>
289294
{isMultiSelect && (
290295
<TableHeaderCellCheckbox

0 commit comments

Comments
 (0)