-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for keyboard shortcuts that allow sorting columns (#10410)
The PR adds support for new keyboard shortcuts that allows sorting the column/multiple columns based on the currently selected column header. The keyboard shortcuts are active only when the header is focused. Expected working new keyboard shortcuts * Enter Sorts the column (if the ColumnSorting or MultipleColumnSorting plugins are enabled) in a specific order: Ascending > Descending > Restore original order. If there is initialized the multiple columns order, the whole state is cleared, and only the selected column is sorted; * Ctrl/Cmd+Enter Sorts the column in the same order as above, and it works only if the MultipleColumnSorting plugin is enabled. Sorting other columns does not clear the previous columns sorting state but adds new sorting order to the stack.
- Loading branch information
Showing
8 changed files
with
538 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"issuesOrigin": "private", | ||
"title": "Added support for column sorting using a keyboard shortcut.", | ||
"type": "added", | ||
"issueOrPR": 10410, | ||
"breaking": false, | ||
"framework": "none" | ||
} |
143 changes: 143 additions & 0 deletions
143
handsontable/src/plugins/columnSorting/__tests__/keyboardShortcuts.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
describe('ColumnSorting keyboard shortcut', () => { | ||
const id = 'testContainer'; | ||
|
||
beforeEach(function() { | ||
this.$container = $(`<div id="${id}"></div>`).appendTo('body'); | ||
}); | ||
|
||
afterEach(function() { | ||
if (this.$container) { | ||
destroy(); | ||
this.$container.remove(); | ||
} | ||
}); | ||
|
||
function columnHeader(renderedColumnIndex, TH) { | ||
const visualColumnsIndex = renderedColumnIndex >= 0 ? | ||
this.columnIndexMapper.getVisualFromRenderableIndex(renderedColumnIndex) : renderedColumnIndex; | ||
|
||
this.view.appendColHeader(visualColumnsIndex, TH); | ||
} | ||
|
||
describe('"Enter"', () => { | ||
it('should be possible to sort columns with correct sort order', () => { | ||
handsontable({ | ||
data: createSpreadsheetData(3, 8), | ||
colHeaders: true, | ||
rowHeaders: true, | ||
navigableHeaders: true, | ||
columnSorting: true | ||
}); | ||
|
||
selectCell(-1, 1); | ||
keyDownUp('enter'); | ||
|
||
expect(getPlugin('columnSorting').getSortConfig()).toEqual([{ | ||
column: 1, | ||
sortOrder: 'asc', | ||
}]); | ||
|
||
keyDownUp('enter'); | ||
|
||
expect(getPlugin('columnSorting').getSortConfig()).toEqual([{ | ||
column: 1, | ||
sortOrder: 'desc', | ||
}]); | ||
|
||
keyDownUp('enter'); | ||
|
||
expect(getPlugin('columnSorting').getSortConfig()).toEqual([]); | ||
|
||
keyDownUp('enter'); | ||
|
||
expect(getPlugin('columnSorting').getSortConfig()).toEqual([{ | ||
column: 1, | ||
sortOrder: 'asc', | ||
}]); | ||
|
||
selectCell(-1, 3); | ||
keyDownUp('enter'); | ||
|
||
expect(getPlugin('columnSorting').getSortConfig()).toEqual([{ | ||
column: 3, | ||
sortOrder: 'asc', | ||
}]); | ||
}); | ||
|
||
it('should be possible to sort a column when a range of the columns are selected', () => { | ||
handsontable({ | ||
data: createSpreadsheetData(3, 8), | ||
colHeaders: true, | ||
rowHeaders: true, | ||
navigableHeaders: true, | ||
columnSorting: true | ||
}); | ||
|
||
selectColumns(1, 4, -1); | ||
listen(); | ||
keyDownUp('enter'); | ||
|
||
expect(getPlugin('columnSorting').getSortConfig()).toEqual([{ | ||
column: 1, | ||
sortOrder: 'asc', | ||
}]); | ||
}); | ||
|
||
it('should be possible to sort columns only by triggering the action from the lowest column header', () => { | ||
handsontable({ | ||
data: createSpreadsheetData(3, 8), | ||
colHeaders: true, | ||
rowHeaders: true, | ||
navigableHeaders: true, | ||
columnSorting: true, | ||
afterGetColumnHeaderRenderers(headerRenderers) { | ||
headerRenderers.push(columnHeader.bind(this)); | ||
headerRenderers.push(columnHeader.bind(this)); | ||
}, | ||
}); | ||
|
||
selectCell(-1, -1); // corner | ||
keyDownUp('enter'); | ||
|
||
expect(getPlugin('columnSorting').getSortConfig()).toEqual([]); | ||
|
||
selectCell(1, -1); // row header | ||
keyDownUp('enter'); | ||
|
||
expect(getPlugin('columnSorting').getSortConfig()).toEqual([]); | ||
|
||
selectCell(-3, 1); // the first (top) column header | ||
keyDownUp('enter'); | ||
|
||
expect(getPlugin('columnSorting').getSortConfig()).toEqual([]); | ||
|
||
selectCell(-2, 1); // the second column header | ||
keyDownUp('enter'); | ||
|
||
expect(getPlugin('columnSorting').getSortConfig()).toEqual([]); | ||
|
||
selectCell(-1, 1); // the third (bottom) column header | ||
keyDownUp('enter'); | ||
|
||
expect(getPlugin('columnSorting').getSortConfig()).toEqual([{ | ||
column: 1, | ||
sortOrder: 'asc', | ||
}]); | ||
}); | ||
|
||
it('should not trigger the editor to be opened', () => { | ||
handsontable({ | ||
data: createSpreadsheetData(3, 8), | ||
colHeaders: true, | ||
rowHeaders: true, | ||
navigableHeaders: true, | ||
columnSorting: true, | ||
}); | ||
|
||
selectCell(-1, 1); | ||
keyDownUp('enter'); | ||
|
||
expect(getActiveEditor()).toBeUndefined(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.