Skip to content

Commit

Permalink
Apply correct styles for cell hover reveal during cell edition
Browse files Browse the repository at this point in the history
  • Loading branch information
laratran committed Oct 29, 2024
1 parent dea32fa commit ac34389
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,16 @@ export const MRT_TableBodyCell = <TData extends MRT_RowData>({
};

const cellHoverRevealDivRef = useRef<any>(null);
const [isCellContentOverflowing, setIsCellContentOverflowing] = useState(false);
const [isCellContentOverflowing, setIsCellContentOverflowing] =
useState(false);

useLayoutEffect(() => {
const div = cellHoverRevealDivRef.current;
if (div) {
const isOverflow = div.scrollWidth > div.clientWidth;
setIsCellContentOverflowing(isOverflow);
}
}, [tableCellProps.children]);
}, [cell]);

const renderCellContent = () => {
if (cell.getIsPlaceholder()) {
Expand Down Expand Up @@ -241,7 +242,6 @@ export const MRT_TableBodyCell = <TData extends MRT_RowData>({

return <MRT_TableBodyCellValue {...cellValueProps} />;
};

return (
<TableTd
data-column-pinned={isColumnPinned || undefined}
Expand Down Expand Up @@ -288,6 +288,7 @@ export const MRT_TableBodyCell = <TData extends MRT_RowData>({
isEditable &&
['cell', 'table'].includes(editDisplayMode ?? '') &&
columnDefType !== 'display' &&
!isCellContentOverflowing &&
classes['root-editable-hover'],
columnDefType === 'data' && classes['root-data-col'],
density === 'xs' && classes['root-nowrap'],
Expand All @@ -302,13 +303,15 @@ export const MRT_TableBodyCell = <TData extends MRT_RowData>({
})}
>
<>
{tableCellProps.children ?? (
columnDef.enableCellHoverReveal ? (
{tableCellProps.children ??
(columnDef.enableCellHoverReveal ? (
<div
ref={cellHoverRevealDivRef}
className={clsx(
columnDef.enableCellHoverReveal && classes["cell-hover-reveal"],
isCellContentOverflowing && classes['overflowing']
columnDef.enableCellHoverReveal &&
!(isCreating || isEditing) &&
classes['cell-hover-reveal'],
isCellContentOverflowing && classes['overflowing'],
)}
>
{renderCellContent()}
Expand All @@ -323,8 +326,7 @@ export const MRT_TableBodyCell = <TData extends MRT_RowData>({
<> ({row.subRows?.length})</>
)}
</>
)
)}
))}
</>
</TableTd>
);
Expand Down

0 comments on commit ac34389

Please sign in to comment.