Skip to content

Commit

Permalink
fix: 修复 meta name 同名时,hoverFocus 出错的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
wjgogogo committed May 4, 2023
1 parent 1734416 commit 5c6d5d0
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
64 changes: 64 additions & 0 deletions packages/s2-core/__tests__/bugs/issue-1781-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
/**
* @description spec for issue #1781
* https://github.com/antvis/S2/issues/1781
*/

import { getContainer, sleep } from '../util/helpers';
import * as mockDataConfig from '../data/simple-table-data.json';
import {
OriginEventType,
S2Event,
type S2DataConfig,
type S2Options,
} from '@/index';
import { TableSheet } from '@/sheet-type';

const s2DataConfig: S2DataConfig = {
...mockDataConfig,
meta: [
{
field: 'province',
name: '一样的名字',
},
{
field: 'city',
name: '一样的名字',
},
],
};

const s2Options: S2Options = {
width: 800,
height: 400,
};

describe('Hover Focus Tests', () => {
const s2 = new TableSheet(getContainer(), s2DataConfig, s2Options);

s2.render();

test(`should focus on province cell but don't focus on city cell when hover on province cell`, async () => {
await sleep(3000);

// 浙江省份信息
const provinceCell = s2.panelScrollGroup.getChildByIndex(7);

// 义乌城市信息
const cityCell = s2.panelScrollGroup.getChildByIndex(10);

const event = new MouseEvent(OriginEventType.MOUSE_MOVE);

// @ts-ignore
s2.emit(S2Event.DATA_CELL_HOVER, { ...event, target: provinceCell });

expect(
// @ts-ignore
provinceCell.stateShapes.get('interactiveBorderShape')?.cfg.visible,
).toBeTrue();
expect(
// @ts-ignore
cityCell.stateShapes.get('interactiveBorderShape')?.cfg.visible,
).toBeFalse();
});
});
9 changes: 8 additions & 1 deletion packages/s2-core/src/cell/data-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,14 @@ export class DataCell extends BaseCell<ViewMeta> {
}
}

if (isEqual(currentHoverCell.id, this.getMeta().id)) {
const { id, rowIndex, colIndex } = this.getMeta();

// fix issue: https://github.com/antvis/S2/issues/1781
if (
isEqual(currentHoverCell.id, id) &&
isEqual(currentHoverCell.rowIndex, rowIndex) &&
isEqual(currentHoverCell.colIndex, colIndex)
) {
this.updateByState(InteractionStateName.HOVER_FOCUS);
}
}
Expand Down

0 comments on commit 5c6d5d0

Please sign in to comment.