diff --git a/components/table/SelectionCheckboxAll.tsx b/components/table/SelectionCheckboxAll.tsx index e0da1c3870..da7c802472 100644 --- a/components/table/SelectionCheckboxAll.tsx +++ b/components/table/SelectionCheckboxAll.tsx @@ -4,6 +4,7 @@ import { Store } from './createStore'; import Dropdown from '../dropdown'; import Menu from '../menu'; import Icon from '../icon'; +import classNames from 'classnames'; export interface SelectionDecorator { key: string; @@ -20,7 +21,7 @@ export interface SelectionCheckboxAllProps { data: any[]; prefixCls: string | undefined; onSelect: (key: string, index: number, selectFunc: any) => void; - selections: SelectionDecorator[]; + selections?: SelectionDecorator[] | boolean; } export default class SelectionCheckboxAll extends React.Component { @@ -151,31 +152,27 @@ export default class SelectionCheckboxAll extends React.Component - {this.renderMenus(selections)} - - ); + if (selections) { + let newSelections = Array.isArray(selections) ? this.defaultSelections.concat(selections) + : this.defaultSelections; - return ( -
- + let menu = ( + + {this.renderMenus(newSelections)} + + ); + + customSelections = ( trigger.parentNode as HTMLElement} @@ -184,6 +181,19 @@ export default class SelectionCheckboxAll extends React.Component
+ ); + } + + return ( +
+ + {customSelections}
); } diff --git a/components/table/Table.tsx b/components/table/Table.tsx index ee7c8bf3db..107879369f 100755 --- a/components/table/Table.tsx +++ b/components/table/Table.tsx @@ -54,7 +54,7 @@ export interface TableRowSelection { onSelect?: (record: T, selected: boolean, selectedRows: Object[]) => any; onSelectAll?: (selected: boolean, selectedRows: Object[], changeRows: Object[]) => any; onSelectInvert?: (selectedRows: Object[]) => any; - selections?: SelectionDecorator[]; + selections?: SelectionDecorator[] | boolean; } export interface TableProps { @@ -624,10 +624,13 @@ export default class Table extends React.Component, any> { } return true; }); + let selectionColumnClass = classNames(`${prefixCls}-selection-column`, { + [`${prefixCls}-selection-column-custom`]: rowSelection.selections, + }); const selectionColumn: ColumnProps = { key: 'selection-column', render: this.renderSelectionBox(rowSelection.type), - className: `${prefixCls}-selection-column`, + className: selectionColumnClass, }; if (rowSelection.type !== 'radio') { const checkboxAllDisabled = data.every((item, index) => this.getCheckboxPropsByItem(item, index).disabled); @@ -641,7 +644,7 @@ export default class Table extends React.Component, any> { disabled={checkboxAllDisabled} prefixCls={prefixCls} onSelect={this.handleSelectRow} - selections={rowSelection.selections || []} + selections={rowSelection.selections} /> ); } diff --git a/components/table/__tests__/Table.rowSelection.test.js b/components/table/__tests__/Table.rowSelection.test.js index d9c3ad7128..8b0352f465 100644 --- a/components/table/__tests__/Table.rowSelection.test.js +++ b/components/table/__tests__/Table.rowSelection.test.js @@ -172,8 +172,11 @@ describe('Table.rowSelection', () => { expect(handleSelectAll).toBeCalledWith(false, [], data); }); - it('render selection correctly', () => { - const wrapper = mount(createTable()); + it('render with default selection correctly', () => { + const rowSelection = { + selections: true, + }; + const wrapper = mount(createTable({ rowSelection })); const dropdownWrapper = render(wrapper.find('Trigger').node.getComponent()); expect(renderToJson(dropdownWrapper)).toMatchSnapshot(); }); @@ -182,6 +185,7 @@ describe('Table.rowSelection', () => { const handleSelectAll = jest.fn(); const rowSelection = { onSelectAll: handleSelectAll, + selections: true, }; const wrapper = mount(createTable({ rowSelection })); @@ -195,6 +199,7 @@ describe('Table.rowSelection', () => { const handleSelectInvert = jest.fn(); const rowSelection = { onSelectInvert: handleSelectInvert, + selections: true, }; const wrapper = mount(createTable({ rowSelection })); const checkboxes = wrapper.find('input'); diff --git a/components/table/__tests__/__snapshots__/Table.rowSelection.test.js.snap b/components/table/__tests__/__snapshots__/Table.rowSelection.test.js.snap index 73857ca49b..da170cff98 100644 --- a/components/table/__tests__/__snapshots__/Table.rowSelection.test.js.snap +++ b/components/table/__tests__/__snapshots__/Table.rowSelection.test.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Table.rowSelection render selection correctly 1`] = ` +exports[`Table.rowSelection render with default selection correctly 1`] = `
-
- -
@@ -2966,7 +2959,7 @@ exports[`renders ./components/table/demo/expand-children.md correctly 1`] = ` class="ant-table-selection" > -
- -
@@ -8841,7 +8827,7 @@ exports[`renders ./components/table/demo/row-selection.md correctly 1`] = ` class="ant-table-selection" > -
- -
@@ -9176,7 +9155,7 @@ exports[`renders ./components/table/demo/row-selection-and-operation.md correctl class="ant-table-selection" > -
- -
@@ -9767,14 +9739,14 @@ exports[`renders ./components/table/demo/row-selection-custom.md correctly 1`] = >