Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: table hover cell to v3 #7605

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions components/vc-table/Cell/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import {
flattenChildren,
isValidElement,
parseStyleText,
findDOMNode
} from '../../_util/props-util';
import type { CSSProperties, VNodeArrayChildren } from 'vue';
import { Text, computed, defineComponent, isVNode, renderSlot } from 'vue';
import { Text, computed, defineComponent, isVNode, renderSlot, watch, shallowRef } from 'vue';
import { addClass, removeClass } from '../../vc-util/Dom/class';

import type {
DataIndex,
Expand Down Expand Up @@ -161,6 +163,16 @@ export default defineComponent<CellProps>({
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 () => {
const {
prefixCls,
Expand Down Expand Up @@ -242,7 +254,7 @@ export default defineComponent<CellProps>({
const fallback = childNode === undefined ? value : childNode;
return [
(typeof fallback === 'object' && isValidElement(fallback)) ||
typeof fallback !== 'object'
typeof fallback !== 'object'
? fallback
: null,
];
Expand Down Expand Up @@ -337,8 +349,7 @@ export default defineComponent<CellProps>({
[`${cellPrefixCls}-ellipsis`]: ellipsis,
[`${cellPrefixCls}-with-append`]: appendNode,
[`${cellPrefixCls}-fix-sticky`]:
(isFixLeft || isFixRight) && isSticky && supportSticky.value,
[`${cellPrefixCls}-row-hover`]: !cellProps && hovering.value,
(isFixLeft || isFixRight) && isSticky && supportSticky.value
},
additionalProps.class,
cellClassName,
Expand All @@ -356,7 +367,7 @@ export default defineComponent<CellProps>({
};

return (
<Component {...componentProps}>
<Component {...componentProps} ref={hoverRef}>
{appendNode}
{childNode}
{slots.dragHandle?.()}
Expand Down