Skip to content

Commit

Permalink
fix: 修复点击单元格中的 icon 时无法获取到单元格 meta 信息的问题 close #2985
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 committed Dec 4, 2024
1 parent 598f68a commit 80f4484
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions packages/s2-core/src/utils/interaction/formatter.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import type { DisplayObject, FederatedPointerEvent as Event } from '@antv/g';
import type { S2CellType, TargetCellInfo } from '../../common/interface';
import type { SpreadSheet } from '../../sheet-type';
import { getAppendInfo } from './common';

/* formate the base Event data */
export const getBaseCellData = (event: Event): TargetCellInfo => {
export const getBaseCellData = (
event: Event,
s2?: SpreadSheet,
): TargetCellInfo => {
const targetElement = event?.target as unknown as DisplayObject;
const currentCellMeta = getAppendInfo(targetElement)?.meta;
const target = targetElement?.parentNode as S2CellType;
// https://github.com/antvis/S2/issues/2985
const target =
s2?.getCell?.(targetElement)! || (targetElement?.parentNode as S2CellType);
const viewMeta = target?.getMeta?.() || currentCellMeta;

return {
Expand Down
2 changes: 1 addition & 1 deletion packages/s2-react/src/hooks/useEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const useCellEvent = (
) => {
React.useLayoutEffect(() => {
const handlerFn = (event: GEvent) => {
handler?.(getBaseCellData(event));
handler?.(getBaseCellData(event, s2));
};

s2?.on(eventName, handlerFn);
Expand Down

0 comments on commit 80f4484

Please sign in to comment.