Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
SelectionWithScrollsComponent,
SelectionWithTransactionsComponent,
CellSelectionNoneComponent,
CellSelectionSingleComponent
CellSelectionSingleComponent,
IgxGridRowEditingWithoutEditableColumnsComponent
} from '../../test-utils/grid-samples.spec';
import { IgxStringFilteringOperand } from '../../data-operations/filtering-condition';
import { UIInteractions, wait } from '../../test-utils/ui-interactions.spec';
Expand All @@ -26,7 +27,8 @@ describe('IgxGrid - Cell selection #grid', () => {
SelectionWithScrollsComponent,
SelectionWithTransactionsComponent,
CellSelectionNoneComponent,
CellSelectionSingleComponent
CellSelectionSingleComponent,
IgxGridRowEditingWithoutEditableColumnsComponent
]
}).compileComponents();
}));
Expand Down Expand Up @@ -256,6 +258,31 @@ describe('IgxGrid - Cell selection #grid', () => {
expect(grid.selectedCells.length).toBe(1);
});

it('Should not trigger range selection when CellTemplate is used and the user clicks on element inside it', () => {
fix = TestBed.createComponent(IgxGridRowEditingWithoutEditableColumnsComponent);
fix.detectChanges();

const component = fix.componentInstance;
grid = fix.componentInstance.grid;

expect(component.customCell).toBeDefined();

const column = grid.getColumnByName('ProductID');
column.bodyTemplate = component.customCell;
fix.detectChanges();

const selectionChangeSpy = spyOn<any>(grid.rangeSelected, 'emit').and.callThrough();
const cell = grid.gridAPI.get_cell_by_index(1, 'ProductID');
const cellElement = cell.nativeElement;
const span = cellElement.querySelector('span');

expect(span).not.toBeNull();

UIInteractions.simulateClickAndSelectEvent(span);
fix.detectChanges();
expect(selectionChangeSpy).not.toHaveBeenCalled();
});

it('Should be able to select range when click on a cell and hold Shift key and click on another Cell', () => {
const firstCell = grid.gridAPI.get_cell_by_index(3, 'HireDate');
const secondCell = grid.gridAPI.get_cell_by_index(1, 'ID');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ export class IgxGridSelectionService {
if (this.areEqualCollections(currSelection, newSelection)) {
return;
}

const args: IRowSelectionEventArgs = {
owner: this.grid,
oldSelection: currSelection,
Expand Down Expand Up @@ -857,8 +857,7 @@ export class IgxGridSelectionService {
this.pointerEventInGridBody = false;
this.grid.document.body.removeEventListener('pointerup', this.pointerOriginHandler);

const targetTagName = event.target.tagName.toLowerCase();
if (targetTagName !== 'igx-grid-cell' && targetTagName !== 'igx-tree-grid-cell') {
if (!event.target.closest('igx-grid-cell') && !event.target.closest('igx-tree-grid-cell')) {
this.pointerUp(this._lastSelectedNode, this.grid.rangeSelected, true);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1407,11 +1407,18 @@ export class IgxGridRowEditingComponent extends BasicGridComponent {
<igx-column field="ReorderLevel" header="Reorder Lever" [dataType]="'number'" [editable]="true" width="100px"></igx-column>
<igx-column field="ProductName" header="Product Name" [dataType]="'string'" width="150px"></igx-column>
<igx-column field="OrderDate" header="Order Date" [dataType]="'date'" width="150px" [editable]="false"></igx-column>
<ng-template #customCell igxCell let-cell="cell" let-val>
<span style="background-color: red;">val</span>
<br>
{{val}}
</ng-template>
</igx-grid>`,
imports: [IgxGridComponent, IgxColumnComponent, IgxCellTemplateDirective]
})
export class IgxGridRowEditingWithoutEditableColumnsComponent extends BasicGridComponent {
public override data = SampleTestData.foodProductData();
@ViewChild('customCell', { static: true })
public customCell!: TemplateRef<any>;
}

@Component({
Expand Down
Loading