Skip to content

Commit 27c0729

Browse files
committed
feat: resizable.minWidth -> column.minWidth
1 parent 73c7d29 commit 27c0729

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,11 @@ React.render(<Table columns={columns} data={data} />, mountNode);
129129
| title | React Node | | title of this column |
130130
| dataIndex | String | | display field of the data record |
131131
| width | String \| Number | | width of the specific proportion calculation according to the width of the columns |
132+
| minWidth | Number | | min width of the specific proportion calculation according to the width of the columns |
132133
| fixed | String \| Boolean | | this column will be fixed when table scroll horizontally: true or 'left' or 'right' |
133134
| align | String | | specify how cell content is aligned |
134135
| ellipsis | Boolean | | specify whether cell content be ellipsized |
135-
| resizable | Boolean \| { minWidth?: number } | | column resize config |
136+
| resizable | Boolean | | column resize |
136137
| rowScope | 'row' \| 'rowgroup' | | Set scope attribute for all cells in this column |
137138
| onCell | Function(record, index) | | Set custom props per each cell. |
138139
| onHeaderCell | Function(record) | | Set custom props per each header cell. |

src/Header/HeaderCell.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import TableContext from '../context/TableContext';
77

88
interface HeaderCellProps<RecordType> extends CellProps<RecordType> {
99
columnKey?: React.Key;
10-
resizable?: boolean | { minWidth?: number };
10+
resizable?: boolean;
11+
minWidth?: number;
1112
}
1213

1314
function HeaderCell<RecordType>({
1415
columnKey,
1516
resizable,
17+
minWidth,
1618
...cellProps
1719
}: HeaderCellProps<RecordType>) {
1820
const { supportSticky } = useContext(TableContext, ['supportSticky']);
@@ -21,7 +23,7 @@ function HeaderCell<RecordType>({
2123
const isFixRight = typeof fixRight === 'number' && supportSticky;
2224
const cellPrefixCls = `${prefixCls}-cell`;
2325

24-
const resizeHandleNode = useCellResize(columnKey, isFixRight, cellPrefixCls, resizable);
26+
const resizeHandleNode = useCellResize(columnKey, isFixRight, cellPrefixCls, resizable, minWidth);
2527

2628
return <Cell {...cellProps} appendNode={resizeHandleNode} />;
2729
}

src/Header/HeaderRow.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ const HeaderRow = <RecordType extends any>(props: RowProps<RecordType>) => {
7373
additionalProps={additionalProps}
7474
rowType="header"
7575
columnKey={columnsKey[cellIndex]}
76-
resizable={column.resizable}
76+
resizable={(column as ColumnType<RecordType>).resizable}
77+
minWidth={(column as ColumnType<RecordType>).minWidth}
7778
/>
7879
);
7980
})}

src/Header/useCellResize.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ export default function useCelResize(
88
columnKey: React.Key,
99
isFixRight: boolean,
1010
cellPrefixCls: string,
11-
resizable?: boolean | { minWidth?: number },
11+
resizable?: boolean,
12+
minWidth: number = 0,
1213
) {
1314
const {
1415
colsWidths,
@@ -47,7 +48,6 @@ export default function useCelResize(
4748
const oldWidth = colsWidths.get(columnKey);
4849
let newWidth = startRealWidth.current + (isFixRight ? -offset : offset);
4950

50-
const minWidth = typeof resizable === 'object' ? resizable.minWidth || 0 : 0;
5151
if (newWidth < minWidth) {
5252
newWidth = minWidth;
5353
}

src/interface.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ interface ColumnSharedType<RecordType> {
9494
ellipsis?: CellEllipsisType;
9595
align?: AlignType;
9696
rowScope?: RowScopeType;
97-
resizable?: boolean | { minWidth?: number };
9897
}
9998

10099
export interface ColumnGroupType<RecordType> extends ColumnSharedType<RecordType> {
@@ -114,6 +113,8 @@ export interface ColumnType<RecordType> extends ColumnSharedType<RecordType> {
114113
shouldCellUpdate?: (record: RecordType, prevRecord: RecordType) => boolean;
115114
rowSpan?: number;
116115
width?: number | string;
116+
minWidth?: number;
117+
resizable?: boolean;
117118
onCell?: GetComponentProps<RecordType>;
118119
/** @deprecated Please use `onCell` instead */
119120
onCellClick?: (record: RecordType, e: React.MouseEvent<HTMLElement>) => void;

0 commit comments

Comments
 (0)