Skip to content

Commit a14d068

Browse files
MKirovaMKirova
authored andcommitted
chore(*): Removing handling for tab/shift+tab from/to last element focusable element in details view. Updating tests.
1 parent 086d377 commit a14d068

File tree

4 files changed

+17
-26
lines changed

4 files changed

+17
-26
lines changed

projects/igniteui-angular/src/lib/grids/grid-navigation.service.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,10 +562,6 @@ export class IgxGridNavigationService {
562562
let target = currentRowEl.previousElementSibling;
563563
const applyFocusFunc = () => {
564564
target = this.getRowByIndex(rowIndex - 1, '');
565-
const focusable = target.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
566-
if (focusable.length > 0 ) {
567-
target = focusable[focusable.length - 1];
568-
}
569565
target.focus({ preventScroll: true });
570566
};
571567
if (target) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
</div>
9595

9696
<div igxGridBody (keydown.control.c)="copyHandlerIE()" (copy)="copyHandler($event)" class="igx-grid__tbody">
97-
<div class="igx-grid__tbody-content" role="rowgroup" (onDragStop)="selectionService.dragMode = $event"
97+
<div class="igx-grid__tbody-content" role="rowgroup" (onDragStop)="selectionService.dragMode = $event" (scroll)='preventContainerScroll($event)'
9898
(onDragScroll)="dragScroll($event)" [igxGridDragSelect]="selectionService.dragMode"
9999
[style.height.px]='calcHeight' [style.width.px]='calcWidth || null' #tbody>
100100
<span *ngIf="hasMovableColumns && draggedColumn && pinnedColumns.length <= 0"

projects/igniteui-angular/src/lib/grids/grid/grid.component.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { IGroupByExpandState } from '../../data-operations/groupby-expand-state.
1515
import { IBaseChipEventArgs, IChipClickEventArgs, IChipKeyDownEventArgs } from '../../chips/chip.component';
1616
import { IChipsAreaReorderEventArgs } from '../../chips/chips-area.component';
1717
import { IgxColumnComponent } from '../columns/column.component';
18-
import { takeUntil } from 'rxjs/operators';
18+
import { takeUntil, first } from 'rxjs/operators';
1919
import { IgxFilteringService } from '../filtering/grid-filtering.service';
2020
import { IGroupingExpression } from '../../data-operations/grouping-expression.interface';
2121
import { IgxColumnResizingService } from '../resizing/resizing.service';
@@ -675,6 +675,18 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
675675
};
676676
}
677677

678+
public preventContainerScroll(evt) {
679+
if (evt.target.scrollTop !== 0) {
680+
const activeElem = document.activeElement;
681+
this.verticalScrollContainer.addScrollTop(evt.target.scrollTop);
682+
evt.target.scrollTop = 0;
683+
this.verticalScrollContainer.onChunkLoad.pipe(first()).subscribe(() => {
684+
// Some browsers (like Edge/IE) lose focus after scrolling.
685+
(activeElem as any).focus();
686+
});
687+
}
688+
}
689+
678690
public detailsKeyboardHandler(event, rowIndex, container) {
679691
const colIndex = this.selectionService.activeElement ? this.selectionService.activeElement.column : 0;
680692
const shift = event.shiftKey;
@@ -689,15 +701,6 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
689701
const lastColIndex = this.unpinnedColumns[this.unpinnedColumns.length - 1].visibleIndex;
690702
this.navigateTo(rowIndex - 1, lastColIndex,
691703
(args) => args.target.nativeElement.focus());
692-
} else if (!shift) {
693-
const focusable = container
694-
.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
695-
const lastFocusable = focusable[focusable.length - 1];
696-
if (lastFocusable === target || (focusable.length === 0 && container === target)) {
697-
event.preventDefault();
698-
this.navigateTo(rowIndex + 1, 0,
699-
(args) => args.target.nativeElement.focus());
700-
}
701704
}
702705
} else if (key === 'arrowup' && !ctrl && target === container) {
703706
this.navigation.navigateUp(container, {row: rowIndex, column: colIndex});

projects/igniteui-angular/src/lib/grids/grid/grid.master-detail.spec.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -395,32 +395,24 @@ describe('IgxGrid Master Detail #grid', () => {
395395
expect(GridFunctions.elementInGridView(grid, detailRow)).toBeTruthy();
396396
});
397397

398-
it(`Should focus detail row first, then continue to the focusable elements in
399-
it and continue onto the next row when using Tab.`, async() => {
398+
it(`Should focus detail row after hitting Tab on last cell in prev data row.`, async() => {
400399
const row = grid.getRowByIndex(0) as IgxGridRowComponent;
401400
const targetCellElement = grid.getCellByColumn(0, 'CompanyName');
402401
UIInteractions.triggerKeyDownEvtUponElem('tab', targetCellElement, true);
403402
await wait(DEBOUNCETIME);
404403
fix.detectChanges();
405404
const detailRow = GridFunctions.getMasterRowDetail(row);
406405
expect(document.activeElement).toBe(detailRow);
407-
const lastTabbable = detailRow.querySelector('input[name="Comment"]');
408-
UIInteractions.triggerKeyDownEvtUponElem('tab', lastTabbable, true);
409-
await wait(DEBOUNCETIME);
410-
fix.detectChanges();
411-
expect(document.activeElement).toBe(grid.getCellByColumn(2, 'ContactName').nativeElement);
412406
});
413407

414-
it(`Should focus the last focusable element in detail first
415-
and go in reverse order of all elements when tabbing through detail view using Shift+Tab.`, async() => {
408+
it(`Should focus detail row after hitting Shift+Tab on first cell in next data row and continue to the prev row.`, async() => {
416409
const prevRow = grid.getRowByIndex(0) as IgxGridRowComponent;
417410
const targetCellElement = grid.getCellByColumn(2, 'ContactName');
418411
UIInteractions.triggerKeyDownEvtUponElem('tab', targetCellElement, true, false, true);
419412
await wait(DEBOUNCETIME);
420413
fix.detectChanges();
421414
const detailRow = GridFunctions.getMasterRowDetail(prevRow);
422-
const lastTabbable = detailRow.querySelector('input[name="Comment"]');
423-
expect(document.activeElement).toBe(lastTabbable);
415+
expect(document.activeElement).toBe(detailRow);
424416
UIInteractions.triggerKeyDownEvtUponElem('tab', detailRow, true, false, true);
425417
await wait(DEBOUNCETIME);
426418
fix.detectChanges();

0 commit comments

Comments
 (0)