Skip to content

Commit 9b0f0e7

Browse files
committed
perf: table hover cell, close #7451
1 parent 42d33e9 commit 9b0f0e7

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

components/vc-table/Cell/index.tsx

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import classNames from '../../_util/classNames';
2-
import { filterEmpty, flattenChildren, isValidElement } from '../../_util/props-util';
2+
import { filterEmpty, findDOMNode, flattenChildren, isValidElement } from '../../_util/props-util';
33
import type { CSSProperties, VNodeArrayChildren } from 'vue';
4-
import { Text, computed, defineComponent, isVNode } from 'vue';
4+
import { watch, shallowRef, Text, computed, defineComponent, isVNode } from 'vue';
55

66
import type {
77
DataIndex,
@@ -24,6 +24,7 @@ import { warning } from '../../vc-util/warning';
2424
import type { MouseEventHandler } from '../../_util/EventInterface';
2525
import eagerComputed from '../../_util/eagerComputed';
2626
import { customRenderSlot } from '../../_util/vnode';
27+
import { addClass, removeClass } from '../../vc-util/Dom/class';
2728

2829
/** Check if cell is in hover range */
2930
function inHoverRange(cellStartRow: number, cellRowSpan: number, startRow: number, endRow: number) {
@@ -157,6 +158,17 @@ export default defineComponent<CellProps>({
157158
return vnode;
158159
}
159160
};
161+
162+
const hoverRef = shallowRef(null);
163+
watch([hovering, () => props.prefixCls, hoverRef], () => {
164+
const cellDom = findDOMNode(hoverRef.value);
165+
if (!cellDom) return;
166+
if (hovering.value) {
167+
addClass(cellDom, `${props.prefixCls}-cell-row-hover`);
168+
} else {
169+
removeClass(cellDom, `${props.prefixCls}-cell-row-hover`);
170+
}
171+
});
160172
return () => {
161173
const {
162174
prefixCls,
@@ -334,7 +346,6 @@ export default defineComponent<CellProps>({
334346
[`${cellPrefixCls}-with-append`]: appendNode,
335347
[`${cellPrefixCls}-fix-sticky`]:
336348
(isFixLeft || isFixRight) && isSticky && supportSticky.value,
337-
[`${cellPrefixCls}-row-hover`]: !cellProps && hovering.value,
338349
},
339350
additionalProps.class,
340351
cellClassName,
@@ -347,7 +358,7 @@ export default defineComponent<CellProps>({
347358
};
348359

349360
return (
350-
<Component {...componentProps}>
361+
<Component {...componentProps} ref={hoverRef}>
351362
{appendNode}
352363
{childNode}
353364
{slots.dragHandle?.()}

0 commit comments

Comments
 (0)