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(core): 文本区域高度不应超过视口高度 #2265

Merged
merged 11 commits into from
Jul 13, 2023
35 changes: 30 additions & 5 deletions packages/s2-core/src/cell/row-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import {
ResizeDirectionType,
S2Event,
} from '../common/constant';
import { CellBorderPosition, type ViewMeta } from '../common/interface';
import {
CellBorderPosition,
type TextArea,
type ViewMeta,
} from '../common/interface';
import type { RowHeaderConfig } from '../facet/header/row';
import {
getBorderPositionAndStyle,
Expand Down Expand Up @@ -415,7 +419,7 @@ export class RowCell extends HeaderCell {
return width - this.getTextIndent() - this.getActionIconsWidth();
}

protected getTextArea() {
protected getTextArea(): TextArea {
lijinke666 marked this conversation as resolved.
Show resolved Hide resolved
const content = this.getContentArea();
const textIndent = this.getTextIndent();
return {
Expand All @@ -425,16 +429,37 @@ export class RowCell extends HeaderCell {
};
}

protected getAdjustTextAreaHeight(
textArea: TextArea,
scrollY: number,
viewportHeight: number,
): number {
let adjustTextAreaHeight = textArea.height;
d2FuZ3h1ZG9uZw marked this conversation as resolved.
Show resolved Hide resolved
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
7 changes: 7 additions & 0 deletions packages/s2-core/src/common/interface/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,3 +528,10 @@ export interface GridInfo {
}

export type RowData = Data | DataType;

export type TextArea = {
lijinke666 marked this conversation as resolved.
Show resolved Hide resolved
x: number;
y: number;
width: number;
height: number;
};
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