Skip to content

Commit 3c0a42e

Browse files
authored
Merge pull request #7270 from IgniteUI/ddincheva/kbNavBugFix
Keyboard Navigation bug fixes
2 parents 720f0e8 + 98bfb55 commit 3c0a42e

File tree

11 files changed

+111
-79
lines changed

11 files changed

+111
-79
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ All notable changes for each version of this project will be documented in this
145145
- The first cell in the first body row;
146146
- The first cell in column summary if exists;
147147
- Pager UI;
148-
- `onGridKeydown` event is deprecated. Now you can directly bind to keydown on the IgxGrid component in order to perform custom keyboard navigation.
149148

150149
- `IgxCombo`:
151150
- Added `autoFocusSearch` input that allows to manipulate the combo's opening behavior. When the property is `true` (by default), the combo's search input is focused on open. When set to `false`, the focus goes to the combo items container, which can be used to prevent the software keyboard from activating on mobile devices when opening the combo.

projects/igniteui-angular/src/lib/grids/grid-base.directive.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ import { IgxGridColumnResizerComponent } from './resizing/resizer.component';
100100
import { IgxGridFilteringRowComponent } from './filtering/base/grid-filtering-row.component';
101101
import { CharSeparatedValueData } from '../services/csv/char-separated-value-data';
102102
import { IgxColumnResizingService } from './resizing/resizing.service';
103-
import { DeprecateProperty } from '../core/deprecateDecorators';
104103
import { IFilteringStrategy } from '../data-operations/filtering-strategy';
105104
import {
106105
IgxRowExpandedIndicatorDirective, IgxRowCollapsedIndicatorDirective,
@@ -1342,7 +1341,6 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
13421341
* <igx-grid (onGridKeydown)="customKeydown($event)"></igx-grid>
13431342
* ```
13441343
*/
1345-
@DeprecateProperty('onGridKeydown event is deprecated. Now you can directly bind to keydown on the IgxGrid component.')
13461344
@Output()
13471345
public onGridKeydown = new EventEmitter<IGridKeydownEventArgs>();
13481346

@@ -2806,7 +2804,6 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
28062804

28072805
_setupListeners() {
28082806
const destructor = takeUntil<any>(this.destroy$);
2809-
28102807
this.onRowAdded.pipe(destructor).subscribe(args => this.refreshGridState(args));
28112808
this.onRowDeleted.pipe(destructor).subscribe(args => {
28122809
this.summaryService.deleteOperation = true;
@@ -5683,10 +5680,21 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
56835680
const shouldScrollVertically = this.navigation.shouldPerformVerticalScroll(rowIndex, visibleColIndex);
56845681
const shouldScrollHorizontally = this.navigation.shouldPerformHorizontalScroll(visibleColIndex, rowIndex);
56855682
if (shouldScrollVertically) {
5686-
this.navigation.performVerticalScrollToCell(rowIndex, visibleColIndex,
5687-
() => { this.navigateTo(rowIndex, visibleColIndex, cb); });
5683+
this.navigation.performVerticalScrollToCell(rowIndex, visibleColIndex, () => {
5684+
if (shouldScrollHorizontally) {
5685+
this.navigation.performHorizontalScrollToCell(visibleColIndex, () =>
5686+
this.executeCallback(rowIndex, visibleColIndex, cb));
5687+
} else {
5688+
this.executeCallback(rowIndex, visibleColIndex, cb);
5689+
}});
56885690
} else if (shouldScrollHorizontally) {
5689-
this.navigation.performHorizontalScrollToCell(visibleColIndex, () => { this.navigateTo(rowIndex, visibleColIndex, cb); });
5691+
this.navigation.performHorizontalScrollToCell(visibleColIndex, () => {
5692+
if (shouldScrollVertically) {
5693+
this.navigation.performVerticalScrollToCell(rowIndex, visibleColIndex, () =>
5694+
this.executeCallback(rowIndex, visibleColIndex, cb));
5695+
} else {
5696+
this.executeCallback(rowIndex, visibleColIndex, cb);
5697+
}});
56905698
} else {
56915699
this.executeCallback(rowIndex, visibleColIndex, cb);
56925700
}

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { IgxGridBaseDirective } from './grid-base.directive';
33
import { first } from 'rxjs/operators';
44
import { IgxColumnComponent } from './columns/column.component';
55
import { IgxGridNavigationService } from './grid-navigation.service';
6-
import { HORIZONTAL_NAV_KEYS } from '../core/utils';
6+
import { HORIZONTAL_NAV_KEYS, HEADER_KEYS } from '../core/utils';
77

88
/** @hidden */
99
@Injectable()
@@ -35,11 +35,11 @@ export class IgxGridMRLNavigationService extends IgxGridNavigationService {
3535
break;
3636
case 'arrowleft':
3737
case 'left':
38-
colIndex = ctrl ? this.firstIndexPerRow : this.getNextHorizontalCellPositon(true).column;
38+
colIndex = ctrl ? this.firstIndexPerRow : this.getNextHorizontalCellPosition(true).column;
3939
break;
4040
case 'arrowright':
4141
case 'right':
42-
colIndex = ctrl ? this.lastIndexPerRow : this.getNextHorizontalCellPositon().column;
42+
colIndex = ctrl ? this.lastIndexPerRow : this.getNextHorizontalCellPosition().column;
4343
break;
4444
case 'arrowup':
4545
case 'up':
@@ -162,7 +162,7 @@ export class IgxGridMRLNavigationService extends IgxGridNavigationService {
162162
});
163163
}
164164

165-
getNextHorizontalCellPositon(previous = false) {
165+
getNextHorizontalCellPosition(previous = false) {
166166
const parent = this.parentByChildIndex(this.activeNode.column);
167167
if (!this.hasNextHorizontalPosition(previous, parent)) {
168168
return { row: this.activeNode.row, column: this.activeNode.column };
@@ -214,11 +214,15 @@ export class IgxGridMRLNavigationService extends IgxGridNavigationService {
214214

215215
headerNavigation(event: KeyboardEvent) {
216216
const key = event.key.toLowerCase();
217+
if (!HEADER_KEYS.has(key)) { return; }
218+
event.preventDefault();
217219
if (!this.activeNode.layout) {
218220
this.activeNode.layout = this.layout(this.activeNode.column || 0);
219221
}
220-
if (key.includes('down') || key.includes('up')) {
221-
event.preventDefault();
222+
const alt = event.altKey;
223+
const ctrl = event.ctrlKey;
224+
this.performHeaderKeyCombination(this.grid.getColumnByVisibleIndex(this.activeNode.column), key, event.shiftKey, ctrl, alt);
225+
if (!ctrl && !alt && (key.includes('down') || key.includes('up'))) {
222226
const children = this.parentByChildIndex(this.activeNode.column).children;
223227
const col = key.includes('down') ? this.getNextRowIndex(children, false) : this.getPreviousRowIndex(children, false);
224228
if (!col) { return; }
@@ -232,14 +236,13 @@ export class IgxGridMRLNavigationService extends IgxGridNavigationService {
232236

233237
protected horizontalNav(event: KeyboardEvent, key: string, rowIndex: number) {
234238
const ctrl = event.ctrlKey;
235-
if (!HORIZONTAL_NAV_KEYS.has(key)) { return; }
236-
event.preventDefault();
239+
if (!HORIZONTAL_NAV_KEYS.has(key) || event.altKey) { return; }
237240
this.activeNode.row = rowIndex;
238241
if ((key.includes('left') || key === 'home') && this.activeNode.column > 0) {
239-
this.activeNode.column = ctrl || key === 'home' ? this.firstIndexPerRow : this.getNextHorizontalCellPositon(true).column;
242+
this.activeNode.column = ctrl || key === 'home' ? this.firstIndexPerRow : this.getNextHorizontalCellPosition(true).column;
240243
}
241244
if ((key.includes('right') || key === 'end') && this.activeNode.column !== this.lastIndexPerRow) {
242-
this.activeNode.column = ctrl || key === 'end' ? this.lastIndexPerRow : this.getNextHorizontalCellPositon().column;
245+
this.activeNode.column = ctrl || key === 'end' ? this.lastIndexPerRow : this.getNextHorizontalCellPosition().column;
243246
}
244247
const newLayout = this.layout(this.activeNode.column);
245248
Object.assign(this.activeNode.layout, {colStart: newLayout.colStart, rowEnd: newLayout.rowEnd});

0 commit comments

Comments
 (0)