Skip to content

Commit e675d00

Browse files
fix(component->table->cell):fix the table component rendering when hover
1 parent 9a5f83e commit e675d00

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

components/vc-table/Cell/index.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import classNames from '../../_util/classNames';
22
import { filterEmpty, flattenChildren, isValidElement } from '../../_util/props-util';
33
import type { CSSProperties, VNodeArrayChildren } from 'vue';
4-
import { Text, computed, defineComponent, isVNode } from 'vue';
5-
4+
import { Text, computed, defineComponent, isVNode, ref, watch } from 'vue';
65
import type {
76
DataIndex,
87
ColumnType,
@@ -22,7 +21,6 @@ import { useInjectHover } from '../context/HoverContext';
2221
import { useInjectSticky } from '../context/StickyContext';
2322
import { warning } from '../../vc-util/warning';
2423
import type { MouseEventHandler } from '../../_util/EventInterface';
25-
import eagerComputed from '../../_util/eagerComputed';
2624
import { customRenderSlot } from '../../_util/vnode';
2725

2826
/** Check if cell is in hover range */
@@ -105,6 +103,8 @@ export default defineComponent<CellProps>({
105103
'transformCellText',
106104
] as any,
107105
setup(props, { slots }) {
106+
107+
const hoverRef = ref(null)
108108
const contextSlots = useInjectSlots();
109109
const { onHover, startRow, endRow } = useInjectHover();
110110
const colSpan = computed(() => {
@@ -121,10 +121,14 @@ export default defineComponent<CellProps>({
121121
(props.additionalProps?.rowspan as number)
122122
);
123123
});
124-
const hovering = eagerComputed(() => {
124+
watch([rowSpan,startRow,endRow],()=>{
125125
const { index } = props;
126-
return inHoverRange(index, rowSpan.value || 1, startRow.value, endRow.value);
127-
});
126+
if(inHoverRange(index, rowSpan.value || 1, startRow.value, endRow.value)){
127+
hoverRef.value?.setAttribute("class",`ant-table-cell ${props.prefixCls}-cell-row-hover`)
128+
}else{
129+
hoverRef.value?.setAttribute("class",`ant-table-cell`)
130+
}
131+
})
128132
const supportSticky = useInjectSticky();
129133

130134
// ====================== Hover =======================
@@ -203,7 +207,7 @@ export default defineComponent<CellProps>({
203207
renderIndex,
204208
column: column.__originColumn__,
205209
});
206-
210+
207211
if (isRenderCell(renderData)) {
208212
if (process.env.NODE_ENV !== 'production') {
209213
warning(
@@ -217,7 +221,7 @@ export default defineComponent<CellProps>({
217221
childNode = renderData;
218222
}
219223
}
220-
224+
221225
if (
222226
!(INTERNAL_COL_DEFINE in column) &&
223227
cellType === 'body' &&
@@ -303,7 +307,6 @@ export default defineComponent<CellProps>({
303307
if (align) {
304308
alignStyle.textAlign = align;
305309
}
306-
307310
// ====================== Render ======================
308311
let title: string;
309312
const ellipsisConfig: CellEllipsisType = ellipsis === true ? { showTitle: true } : ellipsis;
@@ -314,7 +317,7 @@ export default defineComponent<CellProps>({
314317
title = getTitle([childNode]);
315318
}
316319
}
317-
320+
318321
const componentProps = {
319322
title,
320323
...restCellProps,
@@ -334,7 +337,6 @@ export default defineComponent<CellProps>({
334337
[`${cellPrefixCls}-with-append`]: appendNode,
335338
[`${cellPrefixCls}-fix-sticky`]:
336339
(isFixLeft || isFixRight) && isSticky && supportSticky.value,
337-
[`${cellPrefixCls}-row-hover`]: !cellProps && hovering.value,
338340
},
339341
additionalProps.class,
340342
cellClassName,
@@ -345,9 +347,9 @@ export default defineComponent<CellProps>({
345347
onMouseleave,
346348
style: [additionalProps.style, alignStyle, fixedStyle, cellStyle],
347349
};
348-
350+
349351
return (
350-
<Component {...componentProps}>
352+
<Component {...componentProps} ref={hoverRef}>
351353
{appendNode}
352354
{childNode}
353355
{slots.dragHandle?.()}

0 commit comments

Comments
 (0)