diff --git a/components/table/__tests__/Table.rowSelection.test.js b/components/table/__tests__/Table.rowSelection.test.js index 9258ad6f95..165cd2d628 100644 --- a/components/table/__tests__/Table.rowSelection.test.js +++ b/components/table/__tests__/Table.rowSelection.test.js @@ -98,6 +98,7 @@ describe('Table.rowSelection', () => { const rowSelection = { getCheckboxProps: record => ({ disabled: record.name === 'Lucy', + indeterminate: record.name === 'Tom', name: record.name, }), }; @@ -109,6 +110,22 @@ describe('Table.rowSelection', () => { expect(checkboxes.at(1).props().name).toEqual(data[0].name); expect(checkboxes.at(2).props().disabled).toBe(true); expect(checkboxes.at(2).props().name).toEqual(data[1].name); + + expect(getIndeterminateSelection(wrapper)).toEqual([2]); + }); + + it("make getCheckboxProps's `indeterminate` override selectedRowKeys' effect", () => { + const rowSelection = { + getCheckboxProps: record => ({ + disabled: record.name === 'Lucy', + indeterminate: record.name === 'Tom', + name: record.name, + }), + selectedRowKeys: [2], + }; + + const wrapper = mount(createTable({ rowSelection })); + expect(getIndeterminateSelection(wrapper)).toEqual([2]); }); it('works with pagination', () => { @@ -1041,6 +1058,26 @@ describe('Table.rowSelection', () => { expect(onChange.mock.calls[2][0]).toEqual(['Jerry Tom Tom']); }); }); + it('warns when set `indeterminate` using `rowSelection.getCheckboxProps` is not allowed with tree structured data.', () => { + resetWarned(); + mount( + createTable({ + dataSource: dataWithChildren, + defaultExpandAllRows: true, + rowSelection: { + checkStrictly: false, + getCheckboxProps() { + return { + indeterminate: true, + }; + }, + }, + }), + ); + expect(errorSpy).toHaveBeenCalledWith( + 'Warning: [antd: Table] set `indeterminate` using `rowSelection.getCheckboxProps` is not allowed with tree structured dataSource.', + ); + }); }); describe('cache with selected keys', () => { diff --git a/components/table/__tests__/__snapshots__/demo.test.js.snap b/components/table/__tests__/__snapshots__/demo.test.js.snap index b846f994a1..aa6646f39e 100644 --- a/components/table/__tests__/__snapshots__/demo.test.js.snap +++ b/components/table/__tests__/__snapshots__/demo.test.js.snap @@ -5494,305 +5494,6 @@ exports[`renders ./components/table/demo/expand.md correctly 1`] = ` `; -exports[`renders ./components/table/demo/expand-children.md correctly 1`] = ` -Array [ -
-
- CheckStrictly: -
-
- -
-
, -
-
-
-
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- -
-
- Name - - Age - - Address -
- - - - - 60 - - New York No. 1 Lake Park -
- - - - - 32 - - Sidney No. 1 Lake Park -
-
-
-
-
    -
  • - -
  • -
  • - - 1 - -
  • -
  • - -
  • -
-
-
-
, -] -`; - exports[`renders ./components/table/demo/fixed-columns.md correctly 1`] = `
+
+ CheckStrictly: +
+
+ +
+
, +
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+ Name + + Age + + Address +
+ + + + + 60 + + New York No. 1 Lake Park +
+ + + + + 32 + + Sidney No. 1 Lake Park +
+
+
+
+
    +
  • + +
  • +
  • + + 1 + +
  • +
  • + +
  • +
+
+
+
, +] +`; + exports[`renders ./components/table/demo/virtual-list.md correctly 1`] = `
( const key = getRowKey(record, index); const checked = keySet.has(key); const indeterminate = derivedHalfSelectedKeySet.has(key); - + const checkboxProps = checkboxPropsMap.get(key); + let mergedIndeterminate: boolean; + if (expandType === 'nest') { + mergedIndeterminate = indeterminate; + devWarning( + !(typeof checkboxProps?.indeterminate === 'boolean'), + 'Table', + 'set `indeterminate` using `rowSelection.getCheckboxProps` is not allowed with tree structured dataSource.', + ); + } else { + mergedIndeterminate = checkboxProps?.indeterminate ?? indeterminate; + } // Record checked return { node: ( e.stopPropagation()} onChange={({ nativeEvent }) => { const { shiftKey } = nativeEvent;