Commit 2875a97b70974a379ac6ea15665ad7fe0c3ac747
1 parent
067753d4
fix(table): `clickToRowSelect` support `disabled` checkbox
修复`clickToRowSelect`会无视行选择框disabled状态的问题
Showing
3 changed files
with
20 additions
and
1 deletions
CHANGELOG.zh_CN.md
@@ -8,6 +8,7 @@ | @@ -8,6 +8,7 @@ | ||
8 | - 修复可编辑单元格某些情况下无法提交的问题 | 8 | - 修复可编辑单元格某些情况下无法提交的问题 |
9 | - 修复`inset`属性不起作用的问题 | 9 | - 修复`inset`属性不起作用的问题 |
10 | - 修复`useTable`与`BasicTable`实例的`reload`方法`await`表现不一致的问题 | 10 | - 修复`useTable`与`BasicTable`实例的`reload`方法`await`表现不一致的问题 |
11 | + - 修复`clickToRowSelect`会无视行选择框 disabled 状态的问题 | ||
11 | - **BasicModal** | 12 | - **BasicModal** |
12 | - 修复点击遮罩、按下`Esc`键都不能关闭`Modal`的问题 | 13 | - 修复点击遮罩、按下`Esc`键都不能关闭`Modal`的问题 |
13 | - 修复点击关闭按钮、最大化按钮旁边的空白区域也会导致`Modal`关闭的问题 | 14 | - 修复点击关闭按钮、最大化按钮旁边的空白区域也会导致`Modal`关闭的问题 |
src/components/Table/src/hooks/useCustomRow.ts
@@ -46,6 +46,14 @@ export function useCustomRow( | @@ -46,6 +46,14 @@ export function useCustomRow( | ||
46 | 46 | ||
47 | const isCheckbox = rowSelection.type === 'checkbox'; | 47 | const isCheckbox = rowSelection.type === 'checkbox'; |
48 | if (isCheckbox) { | 48 | if (isCheckbox) { |
49 | + // 找到tr | ||
50 | + const tr: HTMLElement = (e as MouseEvent) | ||
51 | + .composedPath?.() | ||
52 | + .find((dom: HTMLElement) => dom.tagName === 'TR') as HTMLElement; | ||
53 | + if (!tr) return; | ||
54 | + // 找到Checkbox,检查是否为disabled | ||
55 | + const checkBox = tr.querySelector('input[type=checkbox]'); | ||
56 | + if (!checkBox || checkBox.hasAttribute('disabled')) return; | ||
49 | if (!keys.includes(key)) { | 57 | if (!keys.includes(key)) { |
50 | setSelectedRowKeys([...keys, key]); | 58 | setSelectedRowKeys([...keys, key]); |
51 | return; | 59 | return; |
src/views/demo/table/TreeTable.vue
@@ -19,7 +19,17 @@ | @@ -19,7 +19,17 @@ | ||
19 | const [register, { expandAll, collapseAll }] = useTable({ | 19 | const [register, { expandAll, collapseAll }] = useTable({ |
20 | title: '树形表格', | 20 | title: '树形表格', |
21 | isTreeTable: true, | 21 | isTreeTable: true, |
22 | - rowSelection: { type: 'checkbox' }, | 22 | + rowSelection: { |
23 | + type: 'checkbox', | ||
24 | + getCheckboxProps(record: Recordable) { | ||
25 | + // Demo: 第一行(id为0)的选择框禁用 | ||
26 | + if (record.id === '0') { | ||
27 | + return { disabled: true }; | ||
28 | + } else { | ||
29 | + return { disabled: false }; | ||
30 | + } | ||
31 | + }, | ||
32 | + }, | ||
23 | titleHelpMessage: '树形组件不能和序列号列同时存在', | 33 | titleHelpMessage: '树形组件不能和序列号列同时存在', |
24 | columns: getBasicColumns(), | 34 | columns: getBasicColumns(), |
25 | dataSource: getTreeTableData(), | 35 | dataSource: getTreeTableData(), |