Skip to content

Commit

Permalink
fix(core): 文本区域高度不应超过视口高度 (#2265)
Browse files Browse the repository at this point in the history
Co-authored-by: Jinke Li <[email protected]>
  • Loading branch information
d2FuZ3h1ZG9uZw and lijinke666 authored Jul 13, 2023
1 parent 8be446d commit 0507222
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 8 deletions.
31 changes: 26 additions & 5 deletions packages/s2-core/src/cell/row-cell.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Point } from '@antv/g-canvas';
import { GM } from '@antv/g-gesture';
import { find, get } from 'lodash';
import type { SimpleBBox } from '@antv/g-canvas';
import {
CellTypes,
KEY_GROUP_ROW_RESIZE_AREA,
Expand All @@ -27,7 +28,6 @@ import {
} from '../utils/interaction/resize';
import { isMobile } from '../utils/is-mobile';
import { getAdjustPosition } from '../utils/text-absorption';
import { checkIsLinkField } from '../utils/interaction/link-field';
import { shouldAddResizeArea } from './../utils/interaction/resize';
import { HeaderCell } from './header-cell';

Expand Down Expand Up @@ -415,7 +415,7 @@ export class RowCell extends HeaderCell {
return width - this.getTextIndent() - this.getActionIconsWidth();
}

protected getTextArea() {
protected getTextArea(): SimpleBBox {
const content = this.getContentArea();
const textIndent = this.getTextIndent();
return {
Expand All @@ -425,16 +425,37 @@ export class RowCell extends HeaderCell {
};
}

protected getAdjustTextAreaHeight(
textArea: SimpleBBox,
scrollY: number,
viewportHeight: number,
): number {
let adjustTextAreaHeight = textArea.height;
if (
!this.spreadsheet.facet.vScrollBar &&
textArea.y + textArea.height > scrollY + viewportHeight
) {
adjustTextAreaHeight = scrollY + viewportHeight - textArea.y;
}
return adjustTextAreaHeight;
}

protected getTextPosition(): Point {
const textArea = this.getTextArea();
const { scrollY, viewportHeight: height } = this.headerConfig;
const { scrollY, viewportHeight } = this.headerConfig;

const adjustTextAreaHeight = this.getAdjustTextAreaHeight(
textArea,
scrollY,
viewportHeight,
);

const { fontSize } = this.getTextStyle();
const textY = getAdjustPosition(
textArea.y,
textArea.height,
adjustTextAreaHeight,
scrollY,
height,
viewportHeight,
fontSize,
);
const textX = getTextAndFollowingIconPosition(
Expand Down
38 changes: 36 additions & 2 deletions packages/s2-react/__tests__/spreadsheet/pagination-spec.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { act } from 'react-dom/test-utils';
import { LangType, S2Options, setLang } from '@antv/s2';
import { LangType, S2Options, setLang, SpreadSheet } from '@antv/s2';
import { getContainer, sleep } from 'tests/util/helpers';
import * as mockDataConfig from '../data/simple-data.json';
import { pivotSheetDataCfg } from '../../playground/config';
import { SheetComponent } from '../../src';
import { getContainer } from '../util/helpers';
import 'antd/dist/antd.min.css';

const s2Options: S2Options = {
Expand All @@ -17,6 +18,8 @@ const s2Options: S2Options = {
hierarchyType: 'grid',
};

let s2: SpreadSheet;

describe('Pagination Tests', () => {
let container: HTMLDivElement;
beforeEach(() => {
Expand Down Expand Up @@ -94,4 +97,35 @@ describe('Pagination Tests', () => {
document.querySelector('.ant-pagination-options-size-changer'),
).toBeFalsy();
});

test('should row header cell render text position based on the actual cell height when pagination is show', async () => {
act(() => {
ReactDOM.render(
<SheetComponent
options={{
...s2Options,
pagination: {
...s2Options.pagination,
current: 1,
pageSize: 1,
},
height: 400,
}}
dataCfg={pivotSheetDataCfg as any}
onMounted={(instance) => {
s2 = instance;
}}
showPagination
/>,
container,
);
});

await sleep(1000);

expect(
s2.foregroundGroup.cfg.children[0].headerConfig.data[0].belongsCell
.textShapes[0].attrs.y,
).toBe(9);
});
});
11 changes: 10 additions & 1 deletion packages/s2-react/playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ function MainLayout() {
const [tableSheetColumnType, setTableSheetColumnType] = React.useState<
'single' | 'multiple'
>('single');
const [pageSize, setPageSize] = React.useState(10);

// ================== Refs ========================
const s2Ref = React.useRef<SpreadSheet>();
Expand Down Expand Up @@ -330,7 +331,7 @@ function MainLayout() {
{},
{
pagination: showPagination && {
pageSize: 10,
pageSize,
current: 1,
},
tooltip: {
Expand Down Expand Up @@ -550,6 +551,14 @@ function MainLayout() {
>
改变表格大小 (s2.changeSheetSize)
</Button>
<Input
style={{ width: 150 }}
onChange={(e) => setPageSize(+e.target.value)}
defaultValue={pageSize}
suffix="条"
prefix="每页条数"
size="small"
/>
<Popover
placement="bottomRight"
content={
Expand Down

0 comments on commit 0507222

Please sign in to comment.