Browse Source

fix: Table not trigger custom selection onSelect when hideDefaultSelections is true (#7653)

pull/7374/merge
feng zhi hao 7 years ago
committed by Benjy Cui
parent
commit
58fd54e978
  1. 7
      components/table/Table.tsx
  2. 27
      components/table/__tests__/Table.rowSelection.test.js

7
components/table/Table.tsx

@ -552,7 +552,12 @@ export default class Table<T> extends React.Component<TableProps<T>, any> {
selectionDirty: true,
});
// when select custom selection, callback selections[n].onSelect
if (index > 1 && typeof onSelectFunc === 'function') {
const { rowSelection } = this.props;
let customSelectionStartIndex = 2;
if (rowSelection && rowSelection.hideDefaultSelections) {
customSelectionStartIndex = 0;
}
if (index >= customSelectionStartIndex && typeof onSelectFunc === 'function') {
return onSelectFunc(changeableRowKeys);
}
this.setSelectedRowKeys(selectedRowKeys, {

27
components/table/__tests__/Table.rowSelection.test.js

@ -252,6 +252,33 @@ describe('Table.rowSelection', () => {
expect(dropdownWrapper.find('.ant-dropdown-menu-item').length).toBe(2);
});
it('handle custom selection onSelect correctly when hide default selection options', () => {
const handleSelectOdd = jest.fn();
const handleSelectEven = jest.fn();
const rowSelection = {
hideDefaultSelections: true,
selections: [{
key: 'odd',
text: '奇数项',
onSelect: handleSelectOdd,
}, {
key: 'even',
text: '偶数项',
onSelect: handleSelectEven,
}],
};
const wrapper = mount(createTable({ rowSelection }));
const dropdownWrapper = mount(wrapper.find('Trigger').node.getComponent());
expect(dropdownWrapper.find('.ant-dropdown-menu-item').length).toBe(2);
dropdownWrapper.find('.ant-dropdown-menu-item > div').at(0).simulate('click');
expect(handleSelectOdd).toBeCalledWith([0, 1, 2, 3]);
dropdownWrapper.find('.ant-dropdown-menu-item > div').at(1).simulate('click');
expect(handleSelectEven).toBeCalledWith([0, 1, 2, 3]);
});
// https://github.com/ant-design/ant-design/issues/4245
it('handles disabled checkbox correctly when dataSource changes', () => {
const rowSelection = {

Loading…
Cancel
Save