Skip to content

Commit

Permalink
fix(react-grid): Cancel sorting by using the Ctrl key in Material UI (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyAlexeev authored and dxbykov committed Jun 9, 2017
1 parent 9d3a119 commit 2508537
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ const GroupPanelCellBase = ({
<span
onClick={(e) => {
if (!allowSorting) return;
changeSortingDirection({ keepOther: e.shiftKey });
const cancelSortingRelatedKey = e.metaKey || e.ctrlKey;
changeSortingDirection({
keepOther: e.shiftKey || cancelSortingRelatedKey,
cancel: cancelSortingRelatedKey,
});
}}
>
<TableSortLabel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,22 @@ describe('GroupPanelCell', () => {

expect(tree.find('TableSortLabel').text()).toBe('Test');
});

test('should cancel sorting by using the Ctrl key', () => {
const changeSortingDirection = jest.fn();
const tree = mountWithStyles(
<GroupPanelCell
column={{
name: 'Test',
}}
changeSortingDirection={changeSortingDirection}
allowSorting
/>,
);

tree.find('span > span > span').simulate('click', { ctrlKey: true });

expect(changeSortingDirection.mock.calls).toHaveLength(1);
expect(changeSortingDirection.mock.calls[0][0].cancel).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ export const TableHeaderCellBase = ({
onClick={(e) => {
if (!allowSorting) return;
e.stopPropagation();
changeSortingDirection({ keepOther: e.shiftKey });
const cancelSortingRelatedKey = e.metaKey || e.ctrlKey;
changeSortingDirection({
keepOther: e.shiftKey || cancelSortingRelatedKey,
cancel: cancelSortingRelatedKey,
});
}}
style={style}
className={tableCellClasses}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,22 @@ describe('TableHeaderCell', () => {

expect(tree.find('div').text()).toBe('Test');
});

test('should cancel sorting by using the Ctrl key', () => {
const changeSortingDirection = jest.fn();
const tree = mountWithStyles(
<TableHeaderCell
column={{
name: 'Test',
}}
changeSortingDirection={changeSortingDirection}
allowSorting
/>,
);

tree.simulate('click', { ctrlKey: true });

expect(changeSortingDirection.mock.calls).toHaveLength(1);
expect(changeSortingDirection.mock.calls[0][0].cancel).toBeTruthy();
});
});

0 comments on commit 2508537

Please sign in to comment.