Skip to content

Commit 3a21536

Browse files
fix(cell-selection): add default selection in edit mode - master (#12493)
* fix(cell-selection): add default selection in edit mode * fix(cell-selection): add test for new selectio in edit mode Co-authored-by: Hristo <[email protected]>
1 parent b415352 commit 3a21536

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

projects/igniteui-angular/src/lib/directives/date-time-editor/date-time-editor.directive.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ export class IgxDateTimeEditorDirective extends IgxMaskDirective implements OnCh
474474
this.onTouchCallback();
475475
this.updateMask();
476476
super.onFocus();
477+
this.nativeElement.select();
477478
}
478479

479480
/** @hidden @internal */

projects/igniteui-angular/src/lib/grids/cell.component.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
[attr.aria-describedby]="ariaDescribeBy"
7878
[attr.aria-invalid]="isInvalid"
7979
[igxFocus]="true"
80+
[igxTextSelection]="true"
8081
[formControl]="formControl"
8182
(compositionstart)="grid.crudService.isInCompositionMode = true"
8283
(compositionend)="grid.crudService.isInCompositionMode = false"
@@ -90,6 +91,7 @@
9091
[attr.aria-describedby]="ariaDescribeBy"
9192
[attr.aria-invalid]="isInvalid"
9293
[igxFocus]="true"
94+
[igxTextSelection]="true"
9395
[step]="step"
9496
type="number"
9597
[formControl]="formControl"
@@ -150,6 +152,7 @@
150152
[attr.aria-describedby]="ariaDescribeBy"
151153
[attr.aria-invalid]="isInvalid"
152154
[igxFocus]="true"
155+
[igxTextSelection]="true"
153156
[step]="step"
154157
type="number"
155158
[formControl]="formControl"
@@ -164,6 +167,7 @@
164167
[attr.aria-describedby]="ariaDescribeBy"
165168
[attr.aria-invalid]="isInvalid"
166169
[igxFocus]="true"
170+
[igxTextSelection]="true"
167171
[step]="step"
168172
type="number"
169173
[formControl]="formControl"

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,24 @@ describe('IgxGrid - Cell Editing #grid', () => {
309309

310310
expect(cell.editMode).toBe(false);
311311
});
312+
313+
it('should focus the first cell when editing mode is cell', fakeAsync(() => {
314+
const cell = grid.gridAPI.get_cell_by_index(0, 'fullName');
315+
expect(cell.editMode).toBe(false);
316+
expect(document.activeElement.nodeName).toEqual('BODY')
317+
318+
// Enter cell edit mode
319+
UIInteractions.simulateDoubleClickAndSelectEvent(cell);
320+
fixture.detectChanges();
321+
tick(100);
322+
323+
// Check focused element and selection
324+
expect(cell.editMode).toBe(true);
325+
expect(document.activeElement.nodeName).toEqual('INPUT')
326+
expect((document.activeElement as HTMLInputElement).value).toBe('John Brown');
327+
expect((document.activeElement as HTMLInputElement).selectionStart).toEqual(0)
328+
expect((document.activeElement as HTMLInputElement).selectionEnd).toEqual(10)
329+
}));
312330
});
313331

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

src/app/grid-cellEditing/grid-cellEditing.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ export class GridCellEditingComponent {
170170
public updateSelectedCell() {
171171
let newValue;
172172
const selectedCell = this.gridWithoutPK.selectedCells[0];
173-
console.log(selectedCell.column.dataType);
174173
switch (selectedCell.column.dataType) {
175174
case 'string': newValue = 'UpdatedCell'; break;
176175
case 'number': newValue = 0; break;

0 commit comments

Comments
 (0)