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

fix: 解决移动端下,树形结构展开、收起交互失效的问题 #3039

Merged
merged 9 commits into from
Dec 13, 2024
26 changes: 21 additions & 5 deletions packages/s2-core/src/cell/corner-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
getResizeAreaAttrs,
shouldAddResizeArea,
} from '../utils/interaction/resize';
import { isMobile } from '../utils/is-mobile';
import { HeaderCell } from './header-cell';

export class CornerCell extends HeaderCell<CornerHeaderConfig> {
Expand Down Expand Up @@ -55,6 +56,19 @@ export class CornerCell extends HeaderCell<CornerHeaderConfig> {
this.update();
}

private onTreeIconClick(isCollapsed: boolean) {
if (isMobile()) {
return;
}

this.emitCollapseEvent(isCollapsed);
}

private emitCollapseEvent(isCollapsed: boolean) {
this.spreadsheet.facet.resetScrollY();
this.spreadsheet.emit(S2Event.ROW_CELL_ALL_COLLAPSED__PRIVATE, isCollapsed);
}

/**
* 绘制折叠展开的 icon
*/
Expand Down Expand Up @@ -85,13 +99,15 @@ export class CornerCell extends HeaderCell<CornerHeaderConfig> {
},
isCollapsed,
onClick: () => {
this.spreadsheet.facet.resetScrollY();
this.spreadsheet.emit(
S2Event.ROW_CELL_ALL_COLLAPSED__PRIVATE,
isCollapsed,
);
this.onTreeIconClick(isCollapsed);
},
});
// 移动端, 点击热区为整个单元格
if (isMobile()) {
this.addEventListener('touchend', () => {
this.emitCollapseEvent(isCollapsed);
});
}
}

protected isLastRowCornerCell() {
Expand Down
6 changes: 3 additions & 3 deletions packages/s2-core/src/cell/row-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ export class RowCell extends HeaderCell<RowHeaderConfig> {
iconCfg: {
x: iconX,
y: iconY,
width: size!,
height: size!,
width: size,
height: size,
fill,
},
isCollapsed,
Expand All @@ -173,7 +173,7 @@ export class RowCell extends HeaderCell<RowHeaderConfig> {

// 移动端, 点击热区为整个单元格
if (isMobile()) {
this.addEventListener('click', () => {
this.addEventListener('touchend', () => {
this.emitCollapseEvent();
});
}
Expand Down
Loading