From 15cf94ff1805c567d991091d1bcc25dcc0bb7c6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E7=88=B1=E5=90=83=E7=99=BD=E8=90=9D?= =?UTF-8?q?=E5=8D=9C?= Date: Wed, 12 Mar 2025 11:06:53 +0800 Subject: [PATCH] feat: Table rowSelection support align (#53127) --- components/table/__tests__/Table.test.tsx | 14 ++++++++++++++ components/table/hooks/useSelection.tsx | 1 + components/table/index.en-US.md | 1 + components/table/index.zh-CN.md | 1 + components/table/interface.ts | 2 ++ 5 files changed, 19 insertions(+) diff --git a/components/table/__tests__/Table.test.tsx b/components/table/__tests__/Table.test.tsx index 09c441e1dc..d9647d3745 100644 --- a/components/table/__tests__/Table.test.tsx +++ b/components/table/__tests__/Table.test.tsx @@ -496,4 +496,18 @@ describe('Table', () => { fireEvent.mouseEnter(cell); expect(container.querySelectorAll('.ant-table-cell-row-hover')).toHaveLength(0); }); + + it('rowSelection should support align', () => { + const wrapper = render( + , + ); + + expect(wrapper.container.querySelector('.ant-table-selection-column')).toHaveStyle({ + textAlign: 'right', + }); + }); }); diff --git a/components/table/hooks/useSelection.tsx b/components/table/hooks/useSelection.tsx index 79f91c9e67..2564f715f2 100644 --- a/components/table/hooks/useSelection.tsx +++ b/components/table/hooks/useSelection.tsx @@ -709,6 +709,7 @@ const useSelection = ( title: renderColumnTitle(), render: renderSelectionCell, onCell: rowSelection.onCell, + align: rowSelection.align, [INTERNAL_COL_DEFINE]: { className: columnCls }, }; diff --git a/components/table/index.en-US.md b/components/table/index.en-US.md index aed5167acf..130b323dc3 100644 --- a/components/table/index.en-US.md +++ b/components/table/index.en-US.md @@ -265,6 +265,7 @@ Properties for row selection. | Property | Description | Type | Default | Version | | --- | --- | --- | --- | --- | +| align | Set the alignment of selection column | `left` \| `right` \| `center` | `left` | 5.25.0 | | checkStrictly | Check table row precisely; parent row and children rows are not associated | boolean | true | 4.4.0 | | columnTitle | Set the title of the selection column | ReactNode \| (originalNode: ReactNode) => ReactNode | - | | | columnWidth | Set the width of the selection column | string \| number | `32px` | | diff --git a/components/table/index.zh-CN.md b/components/table/index.zh-CN.md index 418dee4740..4c9a233f04 100644 --- a/components/table/index.zh-CN.md +++ b/components/table/index.zh-CN.md @@ -267,6 +267,7 @@ const columns = [ | 参数 | 说明 | 类型 | 默认值 | 版本 | | --- | --- | --- | --- | --- | +| align | 设置选择列的对齐方式 | `left` \| `right` \| `center` | `left` | 5.25.0 | | checkStrictly | checkable 状态下节点选择完全受控(父子数据选中状态不再关联) | boolean | true | 4.4.0 | | columnTitle | 自定义列表选择框标题 | ReactNode \| (originalNode: ReactNode) => ReactNode | - | | | columnWidth | 自定义列表选择框宽度 | string \| number | `32px` | | diff --git a/components/table/interface.ts b/components/table/interface.ts index 6429a32722..8b9af727a1 100644 --- a/components/table/interface.ts +++ b/components/table/interface.ts @@ -242,6 +242,8 @@ export interface TableRowSelection { columnWidth?: string | number; columnTitle?: React.ReactNode | ((checkboxNode: React.ReactNode) => React.ReactNode); checkStrictly?: boolean; + /** Set the alignment of the selection column */ + align?: 'left' | 'center' | 'right'; renderCell?: ( value: boolean, record: T,