-
-
Notifications
You must be signed in to change notification settings - Fork 619
chore: sync antd 5.x branch to master #1349
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
Changes from all commits
3c278e0
c9d0c5f
eba59a8
8c37e7f
d2eed49
835364f
25fb5a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import React from 'react'; | ||
| import Table from 'rc-table'; | ||
|
|
||
| // 示例:使用 measureRowRender 来隐藏 MeasureRow 中的弹层 | ||
| const MeasureRowRenderExample = () => { | ||
| const columns = [ | ||
| { | ||
| title: ( | ||
| <div> | ||
| Name | ||
| <div className="filter-dropdown" style={{ display: 'none' }}> | ||
| Filter Content | ||
| </div> | ||
| </div> | ||
| ), | ||
| dataIndex: 'name', | ||
| key: 'name', | ||
| width: 100, | ||
| }, | ||
| { | ||
| title: 'Age', | ||
| dataIndex: 'age', | ||
| key: 'age', | ||
| width: 80, | ||
| }, | ||
| ]; | ||
|
|
||
| const data = [ | ||
| { key: 1, name: 'John', age: 25 }, | ||
| { key: 2, name: 'Jane', age: 30 }, | ||
| ]; | ||
|
|
||
| // 自定义 MeasureRow 渲染,隐藏弹层内容 | ||
| const measureRowRender = measureRow => <div style={{ display: 'none' }}>{measureRow}</div>; | ||
|
|
||
| return ( | ||
| <Table | ||
| columns={columns} | ||
| data={data} | ||
| sticky | ||
| scroll={{ x: true }} | ||
| measureRowRender={measureRowRender} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| export default MeasureRowRenderExample; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -137,6 +137,34 @@ const data = [ | |
| { a: '1333', c: 'eee', d: 2, key: '20' }, | ||
| ]; | ||
|
|
||
| const columns3: ColumnType<RecordType>[] = [ | ||
| { title: '', dataIndex: 'name', key: '0' }, | ||
| { title: 'First column', dataIndex: 'name', key: '1' }, | ||
| { title: 'Second column', dataIndex: 'address', key: '2' }, | ||
| { title: 'Third column', dataIndex: 'age', key: '3' }, | ||
| { title: 'Another column', dataIndex: 'address', key: '4' }, | ||
| { title: 'Extra column', dataIndex: 'name', key: '5' }, | ||
| { title: 'And yet another column', dataIndex: 'address', key: '6' }, | ||
| { | ||
| title: 'Column 7 with extraaaaaaaaa long word', | ||
| dataIndex: 'age', | ||
| key: '7', | ||
| }, | ||
| { title: 'Column 8', dataIndex: 'address', key: '8' }, | ||
| { title: 'Column 9', dataIndex: 'name', key: '9' }, | ||
| { title: 'Column 10', dataIndex: 'address', key: '10' }, | ||
| { title: 'Column 11', dataIndex: 'address', key: '11' }, | ||
| { title: 'Column 12', dataIndex: 'age', key: '12' }, | ||
| { title: 'Column 13', dataIndex: 'address', key: '13' }, | ||
| { title: 'Column 14', dataIndex: 'name', key: '14' }, | ||
| { title: 'Column 15', dataIndex: 'address', key: '15' }, | ||
| { title: 'Column 16', dataIndex: 'address', key: '16' }, | ||
| { title: 'Column 17', dataIndex: 'name', key: '17' }, | ||
| { title: 'Column 18', dataIndex: 'address', key: '18' }, | ||
| { title: 'Column 19', dataIndex: 'address', key: '19' }, | ||
| { title: 'Column 20', dataIndex: 'age', key: '20' }, | ||
| ]; | ||
|
|
||
| const Demo = () => { | ||
| const container = useRef(); | ||
| return ( | ||
|
|
@@ -274,7 +302,7 @@ const Demo = () => { | |
| <br /> | ||
| <Table | ||
| columns={fixedColumns} | ||
| data={[{}]} | ||
| data={[{ key: '1' }]} | ||
| scroll={{ | ||
| x: 'max-content', | ||
| }} | ||
|
|
@@ -283,7 +311,7 @@ const Demo = () => { | |
| <br /> | ||
| <Table | ||
| columns={columnsWithWidth} | ||
| data={[{}]} | ||
| data={[{ key: '1' }]} | ||
| scroll={{ | ||
| x: 1200, | ||
| }} | ||
|
|
@@ -301,7 +329,7 @@ const Demo = () => { | |
| <br /> | ||
| <Table | ||
| columns={fixedColumns.map(column => ({ ...column, width: undefined }))} | ||
| data={[{}]} | ||
| data={[{ key: '1' }]} | ||
| scroll={{ | ||
| x: 'max-content', | ||
| }} | ||
|
|
@@ -310,12 +338,26 @@ const Demo = () => { | |
| <br /> | ||
| <Table | ||
| columns={columnsGrouped} | ||
| data={[{}, {}]} | ||
| data={[{ key: '1' }, { key: '2' }]} | ||
| scroll={{ | ||
| x: 'max-content', | ||
| }} | ||
| sticky | ||
| /> | ||
| <br /> | ||
| <h3>scroll.x is true</h3> | ||
| <p>https://github.com/ant-design/ant-design/issues/54894</p> | ||
| <Table | ||
| columns={columns3} | ||
| data={ | ||
| [ | ||
| { key: '1', name: 'Test', age: 1, address: '2' }, | ||
| { key: '2', name: '0', age: 1, address: '2' }, | ||
| ] as any | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using For example: interface MyStickyRecord {
key: string;
name: string;
age: number;
address: string;
}
const columns3: ColumnType<MyStickyRecord>[] = [/* ... */];
// ... in component
<Table<MyStickyRecord>
columns={columns3}
data={[
{ key: '1', name: 'Test', age: 1, address: '2' },
{ key: '2', name: '0', age: 1, address: '2' },
]}
// ...
/> |
||
| } | ||
| sticky | ||
| scroll={{ x: true }} | ||
| /> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -34,7 +34,7 @@ export interface FixedHeaderProps<RecordType> extends HeaderProps<RecordType> { | |||||
| stickyTopOffset?: number; | ||||||
| stickyBottomOffset?: number; | ||||||
| stickyClassName?: string; | ||||||
| scrollTableStyle?: React.CSSProperties; | ||||||
| scrollX?: number | string | true; | ||||||
afc163 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| tableLayout?: TableLayout; | ||||||
| onScroll: (info: { currentTarget: HTMLDivElement; scrollLeft?: number }) => void; | ||||||
| children: (info: HeaderProps<RecordType>) => React.ReactNode; | ||||||
|
|
@@ -60,7 +60,7 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((pro | |||||
| stickyTopOffset, | ||||||
| stickyBottomOffset, | ||||||
| stickyClassName, | ||||||
| scrollTableStyle, | ||||||
| scrollX, | ||||||
| tableLayout = 'fixed', | ||||||
| onScroll, | ||||||
| children, | ||||||
|
|
@@ -178,8 +178,9 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((pro | |||||
| <TableComponent | ||||||
| style={{ | ||||||
| tableLayout, | ||||||
| visibility: noData || mergedColumnWidth ? null : 'hidden', | ||||||
| ...scrollTableStyle, | ||||||
| minWidth: '100%', | ||||||
| // https://github.com/ant-design/ant-design/issues/54894 | ||||||
| width: scrollX, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||
| }} | ||||||
| > | ||||||
| {colGroupNode} | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,9 +57,10 @@ const Grid = React.forwardRef<GridRef, GridProps>((props, ref) => { | |
| // ========================== Column ========================== | ||
| const columnsWidth = React.useMemo<[key: React.Key, width: number, total: number][]>(() => { | ||
| let total = 0; | ||
| return flattenColumns.map(({ width, key }) => { | ||
| total += width as number; | ||
| return [key, width as number, total]; | ||
| return flattenColumns.map(({ width, minWidth, key }) => { | ||
| const finalWidth = Math.max((width as number) || 0, (minWidth as number) || 0); | ||
| total += finalWidth; | ||
| return [key, finalWidth, total]; | ||
|
Comment on lines
+61
to
+63
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| }); | ||
|
Comment on lines
+60
to
64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 列宽计算对 string 宽度不安全,且 scrollWidth 与
建议修复(仅变更本片段内逻辑): - return flattenColumns.map(({ width, minWidth, key }) => {
- const finalWidth = Math.max((width as number) || 0, (minWidth as number) || 0);
+ return flattenColumns.map(({ width, minWidth, key }) => {
+ const w = typeof width === 'number' ? width : 0;
+ const mw = typeof minWidth === 'number' ? minWidth : 0;
+ const finalWidth = Math.max(w, mw);
total += finalWidth;
return [key, finalWidth, total];
});并在 VirtualList 处(Line 245 附近)用总列宽兜底,避免把 // 建议将 scrollWidth 改成:
scrollWidth={
typeof scrollX === 'number'
? scrollX
: (columnsWidth[columnsWidth.length - 1]?.[2] ?? 0)
}🤖 Prompt for AI Agents |
||
| }, [flattenColumns]); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The removal of
word-break: break-word;could lead to UI issues where long, unbreakable words in table cells overflow their container. This might disrupt the table layout. It's recommended to retain this property or provide an alternative solution for handling long text, such as usingoverflow-wrap: break-word;which is the modern equivalent.