selection management enhancements for DT/DL (#2209)

This commit is contained in:
Denys Vuika 2017-08-14 11:08:27 +01:00 committed by Mario Romano
parent 919f2a9fdf
commit f3515ad02b
2 changed files with 27 additions and 8 deletions

View File

@ -133,7 +133,7 @@ describe('DataTable', () => {
expect(rows[1].isSelected).toBeTruthy();
});
it('should unselect the row with [single] selection mode', () => {
it('should not unselect the row with [single] selection mode', () => {
dataTable.selectionMode = 'single';
dataTable.data = new ObjectDataTableAdapter(
[
@ -150,10 +150,29 @@ describe('DataTable', () => {
expect(rows[1].isSelected).toBeFalsy();
dataTable.onRowClick(rows[0], null);
expect(rows[0].isSelected).toBeFalsy();
expect(rows[0].isSelected).toBeTruthy();
expect(rows[1].isSelected).toBeFalsy();
});
it('should unselect the row with [multiple] selection mode and modifier key', () => {
dataTable.selectionMode = 'multiple';
dataTable.data = new ObjectDataTableAdapter(
[ { name: '1' } ],
[ new ObjectDataColumn({ key: 'name'}) ]
);
const rows = dataTable.data.getRows();
dataTable.ngOnChanges({});
dataTable.onRowClick(rows[0], null);
expect(rows[0].isSelected).toBeTruthy();
dataTable.onRowClick(rows[0], null);
expect(rows[0].isSelected).toBeTruthy();
dataTable.onRowClick(rows[0], <any> { metaKey: true, preventDefault() {} });
expect(rows[0].isSelected).toBeFalsy();
});
it('should select multiple rows with [multiple] selection mode', () => {
dataTable.selectionMode = 'multiple';
dataTable.data = new ObjectDataTableAdapter(

View File

@ -237,17 +237,17 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck
if (row) {
if (this.data) {
const newValue = !row.isSelected;
const domEventName = newValue ? 'row-select' : 'row-unselect';
if (this.isSingleSelectionMode()) {
this.resetSelection();
this.selectRow(row, newValue);
this.emitRowSelectionEvent(domEventName, row);
this.selectRow(row, true);
this.emitRowSelectionEvent('row-select', row);
}
if (this.isMultiSelectionMode()) {
const modifier = e.metaKey || e.ctrlKey;
const modifier = e && (e.metaKey || e.ctrlKey);
const newValue = modifier ? !row.isSelected : true;
const domEventName = newValue ? 'row-select' : 'row-unselect';
if (!modifier) {
this.resetSelection();
}