Skip to content

Commit dcb80b6

Browse files
authored
Merge pull request #426 from youda97/data-grid
prevent default and fix sticky header bug in data grid
2 parents 6eeae0c + 80955d0 commit dcb80b6

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/table/data-grid-focus.directive.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ export class DataGridFocus {
4242
}
4343
}
4444

45-
@HostListener("keyup", ["$event"])
46-
keyUp(event: KeyboardEvent) {
45+
@HostListener("keydown", ["$event"])
46+
keyDown(event: KeyboardEvent) {
4747
if (!this.ibmDataGridFocus) {
4848
return;
4949
}
@@ -57,7 +57,9 @@ export class DataGridFocus {
5757
switch (event.key) {
5858
case "Right": // IE specific value
5959
case "ArrowRight":
60-
if (element.nextElementSibling && Array.from(headerRow).indexOf(element.nextElementSibling) < headerRow.length - 1) {
60+
const firstBodyRow = rows[1].querySelectorAll("td");
61+
event.preventDefault();
62+
if (element.nextElementSibling && Array.from(headerRow).indexOf(element.nextElementSibling) < firstBodyRow.length) {
6163
this.columnIndex++;
6264
const nextSibling = element.nextElementSibling;
6365
Table.setTabIndex(element, -1);
@@ -67,6 +69,7 @@ export class DataGridFocus {
6769
break;
6870
case "Left": // IE specific value
6971
case "ArrowLeft":
72+
event.preventDefault();
7073
if (element.previousElementSibling) {
7174
this.columnIndex--;
7275
const previousSibling = element.previousElementSibling;
@@ -77,6 +80,7 @@ export class DataGridFocus {
7780
break;
7881
case "Down": // IE specific value
7982
case "ArrowDown":
83+
event.preventDefault();
8084
if (rowIndex < rows.length - 1) {
8185
rowIndex++;
8286
const row = rows[rowIndex].querySelectorAll("td");
@@ -95,6 +99,7 @@ export class DataGridFocus {
9599
break;
96100
case "Up": // IE specific value
97101
case "ArrowUp":
102+
event.preventDefault();
98103
if ((rowIndex === 1 && Array.from(headerRow).every(th => getFocusElementList(th, tabbableSelectorIgnoreTabIndex).length === 0)) ||
99104
rowIndex === 0) {
100105
return;
@@ -114,6 +119,7 @@ export class DataGridFocus {
114119
}
115120
break;
116121
case "Home":
122+
event.preventDefault();
117123
this.columnIndex = 0;
118124
Table.setTabIndex(element, -1);
119125
if (event.ctrlKey) {
@@ -132,6 +138,7 @@ export class DataGridFocus {
132138
}
133139
break;
134140
case "End":
141+
event.preventDefault();
135142
const lastRow = rows[rows.length - 1].querySelectorAll("td");
136143
Table.setTabIndex(element, -1);
137144
if (event.ctrlKey) {

src/table/table.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ import { I18n } from "./../i18n/i18n.module";
207207
[draggable]="columnsDraggable"
208208
(dragstart)="columnDragStart($event, i)"
209209
(dragend)="columnDragEnd($event, i)"
210-
(click)="setIndex($event, i)">
210+
(click)="setIndex(i)">
211211
<span *ngIf="skeleton"></span>
212212
<div
213213
*ngIf="columnsResizable"
@@ -359,7 +359,7 @@ import { I18n } from "./../i18n/i18n.module";
359359
[ngStyle]="model.header[j].style"
360360
[ibmDataGridFocus]="isDataGrid"
361361
[(columnIndex)]="columnIndex"
362-
(click)="setIndex($event, j)">
362+
(click)="setIndex(j)">
363363
<ng-container *ngIf="!item.template">{{item.data}}</ng-container>
364364
<ng-template
365365
[ngTemplateOutlet]="item.template" [ngTemplateOutletContext]="{data: item.data}">
@@ -932,7 +932,7 @@ export class Table implements AfterViewInit {
932932
});
933933
}
934934

935-
setIndex(event, columnIndex) {
935+
setIndex(columnIndex) {
936936
if (this.model.hasExpandableRows() && this.showSelectionColumn) {
937937
this.columnIndex = columnIndex + 2;
938938
} else if (this.model.hasExpandableRows() || this.showSelectionColumn) {

0 commit comments

Comments
 (0)