-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend Grid API to allow custom keyboard navigation #4646
Merged
Merged
Changes from 36 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
1d8cbb6
chore(IgxCell): remove unnecessary blur from cell
ddincheva 2df3da1
refactor(GridNavigation): add check if vertical scroll will be performed
ddincheva 95c2d07
Merge branch '7.2.x' of https://github.com/IgniteUI/igniteui-angular …
ddincheva 452dcae
Merge branch '7.2.x' of https://github.com/IgniteUI/igniteui-angular …
ddincheva 0816d58
chore(IgxGroupByRow): go to first cell if activeEl column is hidden
ddincheva 26afde1
Merge branch '7.2.x' of https://github.com/IgniteUI/igniteui-angular …
ddincheva 851f47e
Merge branch '7.2.x' of https://github.com/IgniteUI/igniteui-angular …
ddincheva 15aa10e
Merge branch '7.2.x' of https://github.com/IgniteUI/igniteui-angular …
ddincheva 494d126
Merge branch '7.2.x' of https://github.com/IgniteUI/igniteui-angular …
ddincheva 0c21a5f
chore(IgxGrid): calc should prerform vertical scroll
ddincheva 23cab5c
Merge branch '7.2.x' of https://github.com/IgniteUI/igniteui-angular …
ddincheva 2ed6f14
feat(IgxGroupByRow): refactored keydown and emit the new gridKeyDown …
ddincheva 4145824
refactor(SummaryCell): prevent handle not supported keys in summary c…
ddincheva 5dd1cd6
feat(IgxGrid): emit onGridKeydown event to allow custom keyboard nav …
ddincheva 6ba7ad9
feat(IgxGrid): add navigateTo method to allow custom KB navigation #4054
ddincheva c608a6b
feat(IgxCell): emit onGridKeydown event #4054
ddincheva ab993df
chore(*): add custom keyboard navigation to editing sample
ddincheva 76ae131
merge 7.2.x
ddincheva 3379720
chore(igxGrid): fix linting errors
ddincheva 2efe631
chore(IgxCell): prevent default on keydown alt
ddincheva 6abb77f
Merge branch '7.2.x' into ddincheva/customKBNav
ddincheva b787a7d
Merge branch '7.2.x' into ddincheva/customKBNav
ddincheva 5eea2ae
Merge branch '7.2.x' into ddincheva/customKBNav
ddincheva e67e3d5
Merge branch '7.2.x' into ddincheva/customKBNav
ddincheva e6d0214
Merge branch '7.2.x' of https://github.com/IgniteUI/igniteui-angular …
ddincheva fe8753c
Merge branch '7.2.x' of https://github.com/IgniteUI/igniteui-angular …
ddincheva 5e62fe8
Merge branch '7.2.x' of https://github.com/IgniteUI/igniteui-angular …
ddincheva 4304208
feat(IgxGrid): deprecate onFocusChange event #4054
ddincheva c1ddc3c
test(IgxGrid): add test for navigateTo method #4054
ddincheva 2a8a2b8
chore(*): update the changelog with the newly added KB navigation API
ddincheva 541a7ca
Merge branch '7.2.x' into ddincheva/customKBNav
ddincheva 6e24aca
Merge branch '7.2.x' of https://github.com/IgniteUI/igniteui-angular …
ddincheva 2c6179b
Merge branch 'ddincheva/customKBNav' of https://github.com/IgniteUI/i…
ddincheva 63827af
Merge branch '7.2.x' into ddincheva/customKBNav
ddincheva 9b68d7b
Merge branch 'ddincheva/customKBNav' of https://github.com/IgniteUI/i…
ddincheva d72368c
chore(IgxGrid): address the requested changes
ddincheva b665477
chore(*): update the description of navigateTo method
ddincheva 18ade19
fix(IgxGrid): add validation to getPrevious/Next cell methods #4054
ddincheva 7df61af
test(IgxGridComponent): add basic tests for getNext/Previous cell met…
ddincheva 4fc2a88
chore(*): sort the visible column list
ddincheva a57233d
Merge branch '7.2.x' into ddincheva/customKBNav
ddincheva 05cb0ae
Merge branch 'ddincheva/customKBNav' of https://github.com/IgniteUI/i…
ddincheva 4ba73fb
chore(*): additional check to return correctly next/prev cell
ddincheva 78c9df4
chore(*): check for groupBy row and summary
ddincheva 1af97d1
Merge branch '7.2.x' into ddincheva/customKBNav
zdrawku File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,7 +75,7 @@ import { IGridResourceStrings } from '../core/i18n/grid-resources'; | |
import { CurrentResourceStrings } from '../core/i18n/resources'; | ||
import { IgxGridSummaryService } from './summaries/grid-summary.service'; | ||
import { IgxSummaryRowComponent } from './summaries/summary-row.component'; | ||
import { DeprecateMethod } from '../core/deprecateDecorators'; | ||
import { DeprecateMethod, DeprecateProperty } from '../core/deprecateDecorators'; | ||
import { IgxGridSelectionService, GridSelectionRange, IgxGridCRUDService, IgxRow, IgxCell } from '../core/grid-selection'; | ||
import { DragScrollDirection } from './drag-select.directive'; | ||
import { ICachedViewLoadedEventArgs } from '../directives/template-outlet/template_outlet.directive'; | ||
|
@@ -173,13 +173,20 @@ export interface IColumnMovingEndEventArgs { | |
source: IgxColumnComponent; | ||
target: IgxColumnComponent; | ||
} | ||
|
||
// TODO: to be deleted when onFocusChange event is removed #4054 | ||
export interface IFocusChangeEventArgs { | ||
cell: IgxGridCellComponent; | ||
event: Event; | ||
cancel: boolean; | ||
} | ||
|
||
export interface IGridKeydownEventArgs { | ||
targetType: GridKeydownTargetType; | ||
target: Object; | ||
event: Event; | ||
cancel: boolean; | ||
} | ||
|
||
export interface IGridDataBindable { | ||
data: any[]; | ||
filteredData: any[]; | ||
|
@@ -201,6 +208,12 @@ export enum FilterMode { | |
excelStyleFilter = 'excelStyleFilter' | ||
} | ||
|
||
export enum GridKeydownTargetType { | ||
dataCell = 'dataCell', | ||
summaryCell = 'summaryCell', | ||
groupRow = 'groupRow' | ||
} | ||
|
||
export abstract class IgxGridBaseComponent extends DisplayDensityBase implements OnInit, OnDestroy, AfterContentInit, AfterViewInit { | ||
private _scrollWidth: number; | ||
|
||
|
@@ -1431,19 +1444,27 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements | |
public onColumnMovingEnd = new EventEmitter<IColumnMovingEndEventArgs>(); | ||
|
||
/** | ||
* Emitted when changing the focus while navigating with the keyboard. | ||
* Return the focused cell or focused group row. This event is cancelable. | ||
* @deprecated you should use onGridKeydown event | ||
*/ | ||
@Output() | ||
@DeprecateProperty('onFocusChange event is deprecated. Use onGridKeydown event instead.') | ||
public onFocusChange = new EventEmitter<IFocusChangeEventArgs>(); | ||
|
||
/** | ||
* Emitted when keydown is triggered over element inside grid's body. | ||
* This event is fired only if the key combination is supported in the grid. | ||
* Return the target type, target object and the original event. This event is cancelable. | ||
* ```typescript | ||
* changeFocus(event: IGridFocusChangeEventArgs) { | ||
* const changedFocus = event; | ||
* customKeydown(args: IGridKeydownEventArgs) { | ||
* const keydownEvent = args.event; | ||
* } | ||
* ``` | ||
* ```html | ||
* * <igx-grid (onFocusChange)="changeFocus($event)"></igx-grid> | ||
* <igx-grid (onGridKeydown)="customKeydown($event)"></igx-grid> | ||
* ``` | ||
*/ | ||
*/ | ||
@Output() | ||
public onFocusChange = new EventEmitter<IFocusChangeEventArgs>(); | ||
public onGridKeydown = new EventEmitter<IGridKeydownEventArgs>(); | ||
|
||
/** | ||
* @hidden | ||
|
@@ -4872,6 +4893,113 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements | |
directive.scrollTo(goal); | ||
} | ||
|
||
public navigateTo(rowIndex: number, visibleColIndex = -1, cb: Function = null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Public API. Doesn't have description and code snippet. |
||
if (rowIndex < 0 || rowIndex > this.verticalScrollContainer.igxForOf.length - 1 | ||
|| (visibleColIndex !== -1 && this.columnList.map(col => col.visibleIndex).indexOf(visibleColIndex) === -1)) { | ||
return; | ||
} | ||
this.wheelHandler(); | ||
if (visibleColIndex === -1 || (this.navigation.isColumnFullyVisible(visibleColIndex) | ||
&& this.navigation.isColumnLeftFullyVisible(visibleColIndex))) { | ||
if (this.navigation.shouldPerformVerticalScroll(rowIndex)) { | ||
this.verticalScrollContainer.scrollTo(rowIndex); | ||
this.verticalScrollContainer.onChunkLoad | ||
.pipe(first()).subscribe(() => { | ||
this.executeCallback(rowIndex, visibleColIndex, cb); | ||
}); | ||
} else { | ||
this.executeCallback(rowIndex, visibleColIndex, cb); | ||
} | ||
} else { | ||
const unpinnedIndex = this.navigation.getColumnUnpinnedIndex(visibleColIndex); | ||
this.parentVirtDir.onChunkLoad | ||
.pipe(first()) | ||
.subscribe(() => { | ||
if (this.navigation.shouldPerformVerticalScroll(rowIndex)) { | ||
this.verticalScrollContainer.scrollTo(rowIndex); | ||
this.verticalScrollContainer.onChunkLoad | ||
.pipe(first()).subscribe(() => { | ||
this.executeCallback(rowIndex, visibleColIndex, cb); | ||
}); | ||
} else { | ||
this.executeCallback(rowIndex, visibleColIndex, cb); | ||
} | ||
|
||
}); | ||
this.navigation.horizontalScroll(rowIndex).scrollTo(unpinnedIndex); | ||
} | ||
} | ||
|
||
public getNextCell(currRowIndex, curVisibleColIndex, callback: (IgxColumnComponent) => boolean = null) { | ||
const visibleColIndex = curVisibleColIndex; | ||
const colIndexes = callback ? this.columnList.filter((col) => callback(col)).map(editCol => editCol.visibleIndex) : | ||
this.columnList.map(editCol => editCol.visibleIndex); | ||
const nextCellIndex = colIndexes.find(index => index > visibleColIndex); | ||
if (nextCellIndex !== undefined) { | ||
return {rowIndex: currRowIndex, visibleColumnIndex: nextCellIndex}; | ||
} else { | ||
if (this.getNextDataRowIndex(currRowIndex) === currRowIndex) { | ||
return {rowIndex: this.getNextDataRowIndex(currRowIndex), visibleColumnIndex: visibleColIndex}; | ||
} else { | ||
return {rowIndex: this.getNextDataRowIndex(currRowIndex), visibleColumnIndex: colIndexes[0]}; | ||
} | ||
} | ||
} | ||
|
||
public getPreviousCell(currRowIndex, curVisibleColIndex, callback: (IgxColumnComponent) => boolean = null) { | ||
const visibleColIndex = curVisibleColIndex; | ||
const colIndexes = callback ? this.columnList.filter((col) => callback(col)).map(editCol => editCol.visibleIndex) : | ||
this.columnList.map(editCol => editCol.visibleIndex); | ||
const prevCellIndex = colIndexes.reverse().find(index => index < visibleColIndex); | ||
if (prevCellIndex !== undefined) { | ||
return {rowIndex: currRowIndex, visibleColumnIndex: prevCellIndex}; | ||
} else { | ||
if (this.getPrevDataRowIndex(currRowIndex) === currRowIndex) { | ||
return {rowIndex: this.getPrevDataRowIndex(currRowIndex), visibleColumnIndex: visibleColIndex}; | ||
} else { | ||
return {rowIndex: this.getPrevDataRowIndex(currRowIndex), visibleColumnIndex: colIndexes[0]}; | ||
} | ||
} | ||
} | ||
|
||
private executeCallback(rowIndex, visibleColIndex = -1, cb: Function = null) { | ||
if (!cb) { return; } | ||
let targetType, target; | ||
const row = this.summariesRowList.filter(s => s.index !== 0).concat(this.rowList.toArray()).find(r => r.index === rowIndex); | ||
if (!row) { return; } | ||
switch (row.nativeElement.tagName.toLowerCase()) { | ||
case 'igx-grid-groupby-row': | ||
targetType = GridKeydownTargetType.groupRow; | ||
target = row; | ||
break; | ||
case 'igx-grid-summary-row': | ||
targetType = GridKeydownTargetType.summaryCell; | ||
target = visibleColIndex !== -1 ? | ||
row.summaryCells.find(c => c.visibleColumnIndex === visibleColIndex) : row.summaryCells.first; | ||
break; | ||
default: | ||
targetType = GridKeydownTargetType.dataCell; | ||
target = visibleColIndex !== -1 ? row.cells.find(c => c.visibleColumnIndex === visibleColIndex) : row.cells.first; | ||
break; | ||
} | ||
const args = { targetType: targetType, target: target }; | ||
cb(args); | ||
} | ||
|
||
private getPrevDataRowIndex(currentRowIndex): number { | ||
if (currentRowIndex <= 0) { return currentRowIndex; } | ||
const prevRow = this.verticalScrollContainer.igxForOf.slice(0, currentRowIndex).reverse() | ||
.find(rec => !rec.expression && !rec.summaries); | ||
return prevRow ? this.verticalScrollContainer.igxForOf.indexOf(prevRow) : currentRowIndex; | ||
} | ||
|
||
private getNextDataRowIndex(currentRowIndex): number { | ||
if (currentRowIndex === this.verticalScrollContainer.igxForOf.length) {return currentRowIndex; } | ||
const nextRow = this.verticalScrollContainer.igxForOf.slice(currentRowIndex + 1, this.verticalScrollContainer.igxForOf.length) | ||
.find(rec => !rec.expression && !rec.summaries); | ||
return nextRow ? this.verticalScrollContainer.igxForOf.indexOf(nextRow) : currentRowIndex; | ||
} | ||
|
||
private rebuildMatchCache() { | ||
this.lastSearchInfo.matchInfoCache = []; | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.