perf: table hover cell, close #7451
parent
42d33e963c
commit
9b0f0e71e7
|
@ -1,7 +1,7 @@
|
||||||
import classNames from '../../_util/classNames';
|
import classNames from '../../_util/classNames';
|
||||||
import { filterEmpty, flattenChildren, isValidElement } from '../../_util/props-util';
|
import { filterEmpty, findDOMNode, flattenChildren, isValidElement } from '../../_util/props-util';
|
||||||
import type { CSSProperties, VNodeArrayChildren } from 'vue';
|
import type { CSSProperties, VNodeArrayChildren } from 'vue';
|
||||||
import { Text, computed, defineComponent, isVNode } from 'vue';
|
import { watch, shallowRef, Text, computed, defineComponent, isVNode } from 'vue';
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
DataIndex,
|
DataIndex,
|
||||||
|
@ -24,6 +24,7 @@ import { warning } from '../../vc-util/warning';
|
||||||
import type { MouseEventHandler } from '../../_util/EventInterface';
|
import type { MouseEventHandler } from '../../_util/EventInterface';
|
||||||
import eagerComputed from '../../_util/eagerComputed';
|
import eagerComputed from '../../_util/eagerComputed';
|
||||||
import { customRenderSlot } from '../../_util/vnode';
|
import { customRenderSlot } from '../../_util/vnode';
|
||||||
|
import { addClass, removeClass } from '../../vc-util/Dom/class';
|
||||||
|
|
||||||
/** Check if cell is in hover range */
|
/** Check if cell is in hover range */
|
||||||
function inHoverRange(cellStartRow: number, cellRowSpan: number, startRow: number, endRow: number) {
|
function inHoverRange(cellStartRow: number, cellRowSpan: number, startRow: number, endRow: number) {
|
||||||
|
@ -157,6 +158,17 @@ export default defineComponent<CellProps>({
|
||||||
return vnode;
|
return vnode;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const hoverRef = shallowRef(null);
|
||||||
|
watch([hovering, () => props.prefixCls, hoverRef], () => {
|
||||||
|
const cellDom = findDOMNode(hoverRef.value);
|
||||||
|
if (!cellDom) return;
|
||||||
|
if (hovering.value) {
|
||||||
|
addClass(cellDom, `${props.prefixCls}-cell-row-hover`);
|
||||||
|
} else {
|
||||||
|
removeClass(cellDom, `${props.prefixCls}-cell-row-hover`);
|
||||||
|
}
|
||||||
|
});
|
||||||
return () => {
|
return () => {
|
||||||
const {
|
const {
|
||||||
prefixCls,
|
prefixCls,
|
||||||
|
@ -334,7 +346,6 @@ export default defineComponent<CellProps>({
|
||||||
[`${cellPrefixCls}-with-append`]: appendNode,
|
[`${cellPrefixCls}-with-append`]: appendNode,
|
||||||
[`${cellPrefixCls}-fix-sticky`]:
|
[`${cellPrefixCls}-fix-sticky`]:
|
||||||
(isFixLeft || isFixRight) && isSticky && supportSticky.value,
|
(isFixLeft || isFixRight) && isSticky && supportSticky.value,
|
||||||
[`${cellPrefixCls}-row-hover`]: !cellProps && hovering.value,
|
|
||||||
},
|
},
|
||||||
additionalProps.class,
|
additionalProps.class,
|
||||||
cellClassName,
|
cellClassName,
|
||||||
|
@ -347,7 +358,7 @@ export default defineComponent<CellProps>({
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Component {...componentProps}>
|
<Component {...componentProps} ref={hoverRef}>
|
||||||
{appendNode}
|
{appendNode}
|
||||||
{childNode}
|
{childNode}
|
||||||
{slots.dragHandle?.()}
|
{slots.dragHandle?.()}
|
||||||
|
|
Loading…
Reference in New Issue