Skip to content

Commit

Permalink
feat: use css hover when no colSpan
Browse files Browse the repository at this point in the history
  • Loading branch information
linxianxi committed Feb 7, 2024
1 parent 886671b commit 1c24035
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
6 changes: 6 additions & 0 deletions assets/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@
background: #fff;
}

&:hover {
td {
background: #fff4f4;
}
}

th {
background: @table-head-background-color;
}
Expand Down
22 changes: 11 additions & 11 deletions src/Body/BodyRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
const computedExpandedRowClassName =
expandedRowClassName && expandedRowClassName(record, index, indent);

const cellPropsArray = flattenColumns.map((column, colIndex) =>
getCellProps(rowInfo, column, colIndex, indent, index),
);
const useJsHover = flattenColumns.some((_, colIndex) => {
const { additionalCellProps } = cellPropsArray[colIndex];
const rowSpan = additionalCellProps.rowSpan ?? 1;
return rowSpan !== 1;
});

// ======================== Base tr row ========================
const baseRowNode = (
<RowComponent
Expand All @@ -149,16 +158,11 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
{flattenColumns.map((column: ColumnType<RecordType>, colIndex) => {
const { render, dataIndex, className: columnClassName } = column;

const { key, fixedInfo, appendCellNode, additionalCellProps } = getCellProps(
rowInfo,
column,
colIndex,
indent,
index,
);
const { key, fixedInfo, appendCellNode, additionalCellProps } = cellPropsArray[colIndex];

return (
<Cell
useJsHover={useJsHover}
className={columnClassName}
ellipsis={column.ellipsis}
align={column.align}
Expand Down Expand Up @@ -213,8 +217,4 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
);
}

if (process.env.NODE_ENV !== 'production') {
BodyRow.displayName = 'BodyRow';
}

export default responseImmutable(BodyRow);
6 changes: 4 additions & 2 deletions src/Cell/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface CellProps<RecordType extends DefaultRecordType> {
scope?: ScopeType;
ellipsis?: CellEllipsisType;
align?: AlignType;
useJsHover?: boolean;

shouldCellUpdate?: (record: RecordType, prevRecord: RecordType) => boolean;

Expand Down Expand Up @@ -87,6 +88,7 @@ function Cell<RecordType>(props: CellProps<RecordType>) {
prefixCls,
className,
align,
useJsHover = true,

// Value
record,
Expand Down Expand Up @@ -244,8 +246,8 @@ function Cell<RecordType>(props: CellProps<RecordType>) {
title={title}
scope={scope}
// Hover
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
onMouseEnter={useJsHover ? onMouseEnter : undefined}
onMouseLeave={useJsHover ? onMouseLeave : undefined}
//Span
colSpan={mergedColSpan !== 1 ? mergedColSpan : null}
rowSpan={mergedRowSpan !== 1 ? mergedRowSpan : null}
Expand Down

0 comments on commit 1c24035

Please sign in to comment.