Skip to content

Commit 1b60e91

Browse files
authored
Merge branch 'master' into dpetev/deprecated-contributing
2 parents 974e0fd + 9b41b0a commit 1b60e91

File tree

4 files changed

+82
-5
lines changed

4 files changed

+82
-5
lines changed

projects/igniteui-angular/src/lib/core/styles/typography/_bootstrap.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@
8989
title: 'h5'
9090
));
9191
@include navdrawer-typography();
92-
@include radio-typography();
92+
@include radio-typography($categories: (
93+
label: 'body-1'
94+
));
9395
@include slider-typography();
9496
@include snackbar-typography();
9597
@include switch-typography();

projects/igniteui-angular/src/lib/grids/common/crud.service.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,13 @@ export class IgxCellCrudState {
250250
if (!this.cell) {
251251
return;
252252
}
253+
// this is needed when we are not using ngModel to update the editValue
254+
// so that the change event of the inlineEditorTemplate is hit before
255+
// trying to update any cell
256+
const cellNode = this.grid.gridAPI.get_cell_by_index(this.cell.id.rowIndex, this.cell.column.field).nativeElement;
257+
const document = cellNode.getRootNode() as Document | ShadowRoot;
258+
const activeElement = document.activeElement as HTMLElement;
259+
activeElement.blur();
253260

254261
const formControl = this.grid.validation.getFormControl(this.cell.id.rowID, this.cell.column.field);
255262
if (this.grid.validationTrigger === 'blur' && this.cell.pendingValue !== undefined) {
@@ -276,6 +283,8 @@ export class IgxCellCrudState {
276283

277284
const args = this.cellEdit(event);
278285
if (args.cancel) {
286+
// the focus is needed when we cancel the cellEdit so that the activeElement stays on the editor template
287+
activeElement.focus();
279288
return args;
280289
}
281290

projects/igniteui-angular/src/lib/grids/grid/grid-cell-editing.spec.ts

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import { GridFunctions } from '../../test-utils/grid-functions.spec';
99
import {
1010
CellEditingTestComponent, CellEditingScrollTestComponent,
1111
SelectionWithTransactionsComponent,
12-
ColumnEditablePropertyTestComponent
12+
ColumnEditablePropertyTestComponent,
13+
CellEditingCustomEditorTestComponent
1314
} from '../../test-utils/grid-samples.spec';
1415
import { DebugElement } from '@angular/core';
15-
import { takeUntil } from 'rxjs/operators';
16-
import { Subject } from 'rxjs';
16+
import { first, takeUntil } from 'rxjs/operators';
17+
import { Subject, fromEvent } from 'rxjs';
1718
import { SortingDirection } from '../../data-operations/sorting-strategy';
1819
import { IGridEditDoneEventArgs, IGridEditEventArgs, IgxColumnComponent } from '../public_api';
1920

@@ -328,6 +329,38 @@ describe('IgxGrid - Cell Editing #grid', () => {
328329
expect((document.activeElement as HTMLInputElement).selectionStart).toEqual(0)
329330
expect((document.activeElement as HTMLInputElement).selectionEnd).toEqual(10)
330331
}));
332+
333+
it('should work correct when not using ngModel but value and change event', fakeAsync(() => {
334+
fixture = TestBed.createComponent(CellEditingCustomEditorTestComponent);
335+
fixture.detectChanges();
336+
grid = fixture.componentInstance.grid;
337+
gridContent = GridFunctions.getGridContent(fixture);
338+
grid.getColumnByName("fullName").inlineEditorTemplate = fixture.componentInstance.templateCell;
339+
fixture.detectChanges();
340+
341+
const cell = grid.gridAPI.get_cell_by_index(0, 'fullName');
342+
343+
UIInteractions.simulateDoubleClickAndSelectEvent(cell);
344+
fixture.detectChanges();
345+
tick(16); // trigger igxFocus
346+
347+
expect(cell.editMode).toBe(true);
348+
const newValue = 'new value';
349+
350+
const editTemplate = fixture.debugElement.query(By.css('input'));
351+
fromEvent(editTemplate.nativeElement, "blur").pipe(first()).subscribe(() => {
352+
// needed because we cannot simulate entirely user input (change event needs it)
353+
editTemplate.nativeElement.dispatchEvent(new Event('change'));
354+
fixture.detectChanges();
355+
});
356+
UIInteractions.clickAndSendInputElementValue(editTemplate, newValue);
357+
fixture.detectChanges();
358+
359+
UIInteractions.triggerEventHandlerKeyDown('enter', gridContent);
360+
fixture.detectChanges();
361+
expect(cell.editMode).toBe(false);
362+
expect(cell.value).toBe(newValue);
363+
}));
331364
});
332365

333366
describe('Scroll, pin and blur', () => {

projects/igniteui-angular/src/lib/test-utils/grid-samples.spec.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ import { IgxGridToolbarActionsComponent } from '../grids/toolbar/common';
3737
import { IgxGridToolbarHidingComponent } from '../grids/toolbar/grid-toolbar-hiding.component';
3838
import { IgxButtonDirective } from '../directives/button/button.directive';
3939
import { IgxGridEditingActionsComponent } from '../action-strip/grid-actions/grid-editing-actions.component';
40-
import { IgxCellHeaderTemplateDirective, IgxCellTemplateDirective, IgxCollapsibleIndicatorTemplateDirective, IgxFilterCellTemplateDirective } from '../grids/columns/templates.directive';
40+
import { IgxCellEditorTemplateDirective, IgxCellHeaderTemplateDirective, IgxCellTemplateDirective, IgxCollapsibleIndicatorTemplateDirective, IgxFilterCellTemplateDirective } from '../grids/columns/templates.directive';
4141
import { IgxGroupByRowSelectorDirective, IgxHeadSelectorDirective, IgxRowSelectorDirective } from '../grids/selection/row-selectors';
4242
import { CellType, ColumnType, IgxAdvancedFilteringDialogComponent } from '../grids/public_api';
4343
import { IgxGridComponent } from '../grids/grid/public_api';
4444
import { OverlaySettings } from '../services/public_api';
45+
import { IgxFocusDirective } from '../directives/focus/focus.directive';
4546

4647
@Component({
4748
template: GridTemplateStrings.declareGrid('', '',
@@ -1732,6 +1733,38 @@ export class IgxGridGroupByComponent extends DataParent implements OnInit {
17321733
}
17331734
}
17341735

1736+
@Component({
1737+
template: `
1738+
<igx-grid [data]="data">
1739+
<igx-column [editable]="true" field="fullName">
1740+
</igx-column>
1741+
<igx-column field="age" [editable]="true" [dataType]="'number'">
1742+
</igx-column>
1743+
<igx-column field="isActive" [editable]="true" [dataType]="'boolean'"></igx-column>
1744+
<igx-column field="birthday" [editable]="true" [dataType]="'date'"></igx-column>
1745+
<igx-column [editable]="true" field="personNumber" [dataType]="'number'">
1746+
</igx-column>
1747+
</igx-grid>
1748+
<ng-template #cellEdit igxCellEditor let-cell="cell">
1749+
<input name="fullName" [value]="cell.editValue" (change)="onChange($event,cell)" [igxFocus]="true"/>
1750+
</ng-template>
1751+
`,
1752+
standalone: true,
1753+
imports: [IgxGridComponent, IgxColumnComponent, IgxCellTemplateDirective, IgxCellEditorTemplateDirective, IgxFocusDirective]
1754+
})
1755+
export class CellEditingCustomEditorTestComponent extends BasicGridComponent {
1756+
@ViewChild('cellEdit', { read: TemplateRef }) public templateCell;
1757+
public override data = [
1758+
{ personNumber: 0, fullName: 'John Brown', age: 20, isActive: true, birthday: new Date('08/08/2001') },
1759+
{ personNumber: 1, fullName: 'Ben Affleck', age: 30, isActive: false, birthday: new Date('08/08/1991') },
1760+
{ personNumber: 2, fullName: 'Tom Riddle', age: 50, isActive: true, birthday: new Date('08/08/1961') }
1761+
];
1762+
1763+
public onChange(event: any, cell: CellType) {
1764+
cell.editValue = event.target.value;
1765+
}
1766+
}
1767+
17351768
@Component({
17361769
template: `
17371770
<igx-grid [data]="data">

0 commit comments

Comments
 (0)