Skip to content

Commit bed15ab

Browse files
committed
Conditionally wrap cell with div based on enableCellHoverReveal
1 parent 2a0edd8 commit bed15ab

File tree

2 files changed

+64
-42
lines changed

2 files changed

+64
-42
lines changed

packages/mantine-react-table/src/components/body/MRT_TableBodyCell.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
overflow: visible;
9090
white-space: normal;
9191
position: absolute;
92-
z-index: 5;
92+
z-index: 1;
9393
padding: var(--table-vertical-spacing)
9494
var(--table-horizontal-spacing, var(--mantine-spacing-xs));
9595
background-color: var(--mrt-base-background-color);

packages/mantine-react-table/src/components/body/MRT_TableBodyCell.tsx

Lines changed: 63 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,47 @@ export const MRT_TableBodyCell = <TData extends MRT_RowData>({
200200
const isOverflow = div.scrollWidth > div.clientWidth;
201201
setIsOverflowing(isOverflow);
202202
}
203-
}, [tableCellProps.children ]);
203+
}, [tableCellProps.children]);
204+
205+
const renderCellContent = () => {
206+
if (cell.getIsPlaceholder()) {
207+
return columnDef.PlaceholderCell?.({ cell, column, row, table }) ?? null;
208+
}
209+
210+
if (showSkeletons !== false && (isLoading || showSkeletons)) {
211+
return <Skeleton height={20} width={skeletonWidth} {...skeletonProps} />;
212+
}
213+
214+
if (
215+
columnDefType === 'display' &&
216+
(['mrt-row-expand', 'mrt-row-numbers', 'mrt-row-select'].includes(
217+
column.id,
218+
) ||
219+
!row.getIsGrouped())
220+
) {
221+
return columnDef.Cell?.({
222+
column,
223+
renderedCellValue: cell.renderValue() as any,
224+
row,
225+
rowRef,
226+
...cellValueProps,
227+
});
228+
}
229+
230+
if (isCreating || isEditing) {
231+
return <MRT_EditCellTextInput cell={cell} table={table} />;
232+
}
233+
234+
if (showClickToCopyButton && columnDef.enableClickToCopy !== false) {
235+
return (
236+
<MRT_CopyButton cell={cell} table={table}>
237+
<MRT_TableBodyCellValue {...cellValueProps} />
238+
</MRT_CopyButton>
239+
);
240+
}
241+
242+
return <MRT_TableBodyCellValue {...cellValueProps} />;
243+
};
204244

205245
return (
206246
<TableTd
@@ -261,47 +301,29 @@ export const MRT_TableBodyCell = <TData extends MRT_RowData>({
261301
...parseFromValuesOrFunc(tableCellProps.style, theme),
262302
})}
263303
>
264-
<div
265-
ref={divRef}
266-
className={
267-
clsx(
268-
columnDef.enableCellHoverReveal && classes["cell-hover-reveal"],
269-
isOverflowing && classes['overflowing']
270-
)}
271-
>
272-
{tableCellProps.children ?? (
273-
<>
274-
{cell.getIsPlaceholder() ? (
275-
(columnDef.PlaceholderCell?.({ cell, column, row, table }) ?? null)
276-
) : showSkeletons !== false && (isLoading || showSkeletons) ? (
277-
<Skeleton height={20} width={skeletonWidth} {...skeletonProps} />
278-
) : columnDefType === 'display' &&
279-
(['mrt-row-expand', 'mrt-row-numbers', 'mrt-row-select'].includes(
280-
column.id,
281-
) ||
282-
!row.getIsGrouped()) ? (
283-
columnDef.Cell?.({
284-
column,
285-
renderedCellValue: cell.renderValue() as any,
286-
row,
287-
rowRef,
288-
...cellValueProps,
289-
})
290-
) : isCreating || isEditing ? (
291-
<MRT_EditCellTextInput cell={cell} table={table} />
292-
) : showClickToCopyButton && columnDef.enableClickToCopy !== false ? (
293-
<MRT_CopyButton cell={cell} table={table}>
294-
<MRT_TableBodyCellValue {...cellValueProps} />
295-
</MRT_CopyButton>
304+
<>
305+
{tableCellProps.children ??
306+
(columnDef.enableCellHoverReveal ? (
307+
<div ref={divRef}
308+
className={
309+
clsx(
310+
columnDef.enableCellHoverReveal && classes["cell-hover-reveal"],
311+
isOverflowing && classes['overflowing']
312+
)}>
313+
{renderCellContent()}
314+
{cell.getIsGrouped() && !columnDef.GroupedCell && (
315+
<> ({row.subRows?.length})</>
316+
)}
317+
</div>
296318
) : (
297-
<MRT_TableBodyCellValue {...cellValueProps} />
298-
)}
299-
{cell.getIsGrouped() && !columnDef.GroupedCell && (
300-
<> ({row.subRows?.length})</>
301-
)}
302-
</>
303-
)}
304-
</div>
319+
<>
320+
{renderCellContent()}
321+
{cell.getIsGrouped() && !columnDef.GroupedCell && (
322+
<> ({row.subRows?.length})</>
323+
)}
324+
</>
325+
))}
326+
</>
305327
</TableTd>
306328
);
307329
};

0 commit comments

Comments
 (0)