Skip to content

Commit 4595542

Browse files
authored
refactor: Rename fixColumn to horizonScroll (#449)
* refactor variable name * update example
1 parent d3adff8 commit 4595542

File tree

6 files changed

+27
-20
lines changed

6 files changed

+27
-20
lines changed

examples/expandedRowRender.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const Demo = () => {
3535
const [expandedRowKeys, setExpandedRowKeys] = React.useState([]);
3636
const [expandRowByClick, expandRowByClickProps] = useCheckbox(false);
3737
const [fixColumns, fixColumnsProps] = useCheckbox(false);
38+
const [scrollX, scrollXProps] = useCheckbox(false);
3839
const [fixHeader, fixHeaderProps] = useCheckbox(false);
3940
const [expandIconPosition, expandIconPositionProps] = useCheckbox(false);
4041

@@ -103,6 +104,10 @@ const Demo = () => {
103104
<input {...fixColumnsProps} />
104105
Fix Columns
105106
</label>
107+
<label>
108+
<input {...scrollXProps} />
109+
ScrollX
110+
</label>
106111
<label>
107112
<input {...fixHeaderProps} />
108113
Fix Header
@@ -123,7 +128,7 @@ const Demo = () => {
123128
rowExpandable,
124129
expandIconColumnIndex: expandIconPosition ? 1 : null,
125130
}}
126-
scroll={{ x: fixColumns ? 2000 : null, y: fixHeader ? 300 : null }}
131+
scroll={{ x: fixColumns || scrollX ? 2000 : null, y: fixHeader ? 300 : null }}
127132
data={data}
128133
/>
129134
</div>

src/Body/BodyRow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function BodyRow<RecordType extends { children?: RecordType[] }>(props: BodyRowP
5252
const { prefixCls, direction } = React.useContext(TableContext);
5353
const {
5454
fixHeader,
55-
fixColumn,
55+
horizonScroll,
5656
componentWidth,
5757
flattenColumns,
5858
expandableType,
@@ -196,7 +196,7 @@ function BodyRow<RecordType extends { children?: RecordType[] }>(props: BodyRowP
196196
)}
197197
prefixCls={prefixCls}
198198
fixHeader={fixHeader}
199-
fixColumn={fixColumn}
199+
horizonScroll={horizonScroll}
200200
component={RowComponent}
201201
componentWidth={componentWidth}
202202
cellComponent={cellComponent}

src/Body/ExpandedRow.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface ExpandedRowProps<RecordType> {
88
component: CustomizeComponent;
99
cellComponent: CustomizeComponent;
1010
fixHeader: boolean;
11-
fixColumn: boolean;
11+
horizonScroll: boolean;
1212
componentWidth: number;
1313
className: string;
1414
expanded: boolean;
@@ -22,7 +22,7 @@ function ExpandedRow<RecordType>({
2222
component: Component,
2323
cellComponent,
2424
fixHeader,
25-
fixColumn,
25+
horizonScroll,
2626
className,
2727
expanded,
2828
componentWidth,
@@ -34,7 +34,7 @@ function ExpandedRow<RecordType>({
3434
return React.useMemo(() => {
3535
let contentNode = children;
3636

37-
if (fixColumn) {
37+
if (horizonScroll) {
3838
contentNode = (
3939
<div
4040
style={{
@@ -66,7 +66,7 @@ function ExpandedRow<RecordType>({
6666
children,
6767
Component,
6868
fixHeader,
69-
fixColumn,
69+
horizonScroll,
7070
className,
7171
expanded,
7272
componentWidth,

src/Body/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ function Body<RecordType>({
3333
}: BodyProps<RecordType>) {
3434
const { onColumnResize } = React.useContext(ResizeContext);
3535
const { prefixCls, getComponent } = React.useContext(TableContext);
36-
const { fixHeader, fixColumn, flattenColumns, componentWidth } = React.useContext(BodyContext);
36+
const { fixHeader, horizonScroll, flattenColumns, componentWidth } = React.useContext(
37+
BodyContext,
38+
);
3739

3840
return React.useMemo(() => {
3941
const WrapperComponent = getComponent(['body', 'wrapper'], 'tbody');
@@ -70,7 +72,7 @@ function Body<RecordType>({
7072
className={`${prefixCls}-placeholder`}
7173
prefixCls={prefixCls}
7274
fixHeader={fixHeader}
73-
fixColumn={fixColumn}
75+
horizonScroll={horizonScroll}
7476
component={trComponent}
7577
componentWidth={componentWidth}
7678
cellComponent={tdComponent}

src/Table.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
369369
const colWidths = React.useMemo(() => pureColWidths, [pureColWidths.join('_')]);
370370
const stickyOffsets = useStickyOffsets(colWidths, flattenColumns.length, direction);
371371
const fixHeader = hasData && scroll && validateValue(scroll.y);
372-
const fixColumn = scroll && validateValue(scroll.x);
372+
const horizonScroll = scroll && validateValue(scroll.x);
373373

374374
let scrollXStyle: React.CSSProperties;
375375
let scrollYStyle: React.CSSProperties;
@@ -382,7 +382,7 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
382382
};
383383
}
384384

385-
if (fixColumn) {
385+
if (horizonScroll) {
386386
scrollXStyle = { overflowX: 'scroll' };
387387
// When no vertical scrollbar, should hide it
388388
// https://github.com/ant-design/ant-design/pull/20705
@@ -446,13 +446,13 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
446446
setComponentWidth(fullTableRef.current ? fullTableRef.current.offsetWidth : width);
447447
};
448448

449-
// Sync scroll bar when init or `fixColumn` changed
449+
// Sync scroll bar when init or `horizonScroll` changed
450450
React.useEffect(() => triggerOnScroll, []);
451451
React.useEffect(() => {
452-
if (fixColumn) {
452+
if (horizonScroll) {
453453
triggerOnScroll();
454454
}
455-
}, [fixColumn]);
455+
}, [horizonScroll]);
456456

457457
// ================== INTERNAL HOOKS ==================
458458
React.useEffect(() => {
@@ -501,7 +501,7 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
501501
const bodyTable = (
502502
<Body
503503
data={mergedData}
504-
measureColumnWidth={fixHeader || fixColumn}
504+
measureColumnWidth={fixHeader || horizonScroll}
505505
stickyOffsets={stickyOffsets}
506506
expandedKeys={mergedExpandedKeys}
507507
rowExpandable={rowExpandable}
@@ -625,7 +625,7 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
625625
[`${prefixCls}-ping-right`]: pingedRight,
626626
[`${prefixCls}-layout-fixed`]: tableLayout === 'fixed',
627627
[`${prefixCls}-fixed-header`]: fixHeader,
628-
[`${prefixCls}-fixed-column`]: fixColumn,
628+
[`${prefixCls}-fixed-column`]: horizonScroll,
629629
[`${prefixCls}-has-fix-left`]: flattenColumns[0] && flattenColumns[0].fixed,
630630
[`${prefixCls}-has-fix-right`]:
631631
flattenColumns[flattenColumns.length - 1] &&
@@ -648,7 +648,7 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
648648
</div>
649649
);
650650

651-
if (fixColumn) {
651+
if (horizonScroll) {
652652
fullTable = <ResizeObserver onResize={onFullTableResize}>{fullTable}</ResizeObserver>;
653653
}
654654

@@ -670,7 +670,7 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
670670
expandedRowClassName,
671671
componentWidth,
672672
fixHeader,
673-
fixColumn,
673+
horizonScroll,
674674
expandIcon: mergedExpandIcon,
675675
expandableType,
676676
expandRowByClick,
@@ -686,7 +686,7 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
686686
expandedRowClassName,
687687
componentWidth,
688688
fixHeader,
689-
fixColumn,
689+
horizonScroll,
690690
mergedExpandIcon,
691691
expandableType,
692692
expandRowByClick,

src/context/BodyContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface BodyContextProps<RecordType = DefaultRecordType> {
2121
componentWidth: number;
2222
tableLayout: TableLayout;
2323
fixHeader: boolean;
24-
fixColumn: boolean;
24+
horizonScroll: boolean;
2525

2626
indentSize: number;
2727
expandableType: ExpandableType;

0 commit comments

Comments
 (0)