-
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
Improve keyboard navigation in filtering #2964
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bd73494
fix(igx-grid): Improve keyboard navigation in filtering, #2951
sstoyanovIG 35ad755
fix(igx-grid): Get scroll from first row, when there is one, #2951
sstoyanovIG 938d241
chore(igx-grid): Refactor code, #2951
sstoyanovIG acb1c82
Merge branch '6.2.x' into sstoyanov/bug-fix-#2951
bkulov 00cc67a
chore(igx-grid): Add cases for groupbyrow and pinned columns, #2951
sstoyanovIG 3d10f2e
Merge branch '6.2.x' into sstoyanov/bug-fix-#2951
bkulov 947daa4
chore(igx-grid): Fix lint errors, #2951
sstoyanovIG 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,52 +96,40 @@ export class IgxGridFilteringCellComponent implements AfterViewInit, OnInit { | |
} | ||
|
||
ngOnInit(): void { | ||
this.filteringService.columnToChipToFocus.set(this.column.field, false); | ||
this.filteringService.columnToMoreIconHidden.set(this.column.field, true); | ||
} | ||
|
||
ngAfterViewInit(): void { | ||
this.updateFilterCellArea(); | ||
} | ||
|
||
@HostListener('keydown.shift.tab', ['$event']) | ||
@HostListener('keydown.tab', ['$event']) | ||
public onTabKeyDown(eventArgs) { | ||
if (eventArgs.shiftKey) { | ||
if (this.column.visibleIndex > 0 && !this.navService.isColumnLeftFullyVisible(this.column.visibleIndex - 1)) { | ||
eventArgs.preventDefault(); | ||
this.filteringService.grid.headerContainer.scrollTo(this.column.visibleIndex - 1); | ||
} else if (this.column.visibleIndex === 0) { | ||
eventArgs.preventDefault(); | ||
} | ||
} else { | ||
if (this.isLastElementFocused()) { | ||
if (this.column.visibleIndex === this.filteringService.grid.columnList.length - 1) { | ||
if (this.currentTemplate === this.defaultFilter) { | ||
if (this.isMoreIconVisible() === false) { | ||
if (this.moreIcon.nativeElement === document.activeElement) { | ||
this.navService.goToFirstCell(); | ||
} | ||
} else if (this.chipsArea.chipsList.last.elementRef.nativeElement.querySelector(`.igx-chip__item`) === | ||
document.activeElement) { | ||
this.navService.goToFirstCell(); | ||
} | ||
} else { | ||
eventArgs.preventDefault(); | ||
if (!this.filteringService.grid.filteredData || this.filteringService.grid.filteredData.length > 0) { | ||
this.navService.goToFirstCell(); | ||
} | ||
} else if (!this.navService.isColumnFullyVisible(this.column.visibleIndex + 1)) { | ||
eventArgs.preventDefault(); | ||
this.filteringService.grid.headerContainer.scrollTo(this.column.visibleIndex + 1); | ||
this.ScrollToChip(this.column.visibleIndex + 1, true); | ||
} | ||
} | ||
|
||
eventArgs.stopPropagation(); | ||
} | ||
|
||
/** | ||
* Returns the chip to be focused. | ||
*/ | ||
public getChipToFocus() { | ||
return this.filteringService.columnToChipToFocus.get(this.column.field); | ||
@HostListener('keydown.shift.tab', ['$event']) | ||
public onShiftTabKeyDown(eventArgs) { | ||
if (this.isFirstElementFocused()) { | ||
if (this.column.visibleIndex > 0 && !this.navService.isColumnLeftFullyVisible(this.column.visibleIndex - 1)) { | ||
eventArgs.preventDefault(); | ||
this.ScrollToChip(this.column.visibleIndex - 1, false); | ||
} else if (this.column.visibleIndex === 0) { | ||
eventArgs.preventDefault(); | ||
} | ||
} | ||
eventArgs.stopPropagation(); | ||
} | ||
|
||
/** | ||
|
@@ -199,6 +187,7 @@ export class IgxGridFilteringCellComponent implements AfterViewInit, OnInit { | |
public onChipRemoved(eventArgs: IBaseChipEventArgs, item: ExpressionUI): void { | ||
const indexToRemove = this.expressionsList.indexOf(item); | ||
this.removeExpression(indexToRemove); | ||
this.focusChip(); | ||
} | ||
|
||
/** | ||
|
@@ -224,20 +213,20 @@ export class IgxGridFilteringCellComponent implements AfterViewInit, OnInit { | |
*/ | ||
public filteringIndicatorClass() { | ||
return { | ||
[this.baseClass]: !this.isMoreIconVisible(), | ||
[`${this.baseClass}--hidden`]: this.isMoreIconVisible() | ||
[this.baseClass]: !this.isMoreIconHidden(), | ||
[`${this.baseClass}--hidden`]: this.isMoreIconHidden() | ||
}; | ||
} | ||
|
||
/** | ||
* Focus a chip depending on the current visible template. | ||
*/ | ||
public focusChip() { | ||
public focusChip(focusFirst: boolean = false) { | ||
if (this.currentTemplate === this.defaultFilter) { | ||
if (this.isMoreIconVisible() === false) { | ||
this.moreIcon.nativeElement.focus(); | ||
if (focusFirst) { | ||
this.focusFirstElement(); | ||
} else { | ||
this.chipsArea.chipsList.last.elementRef.nativeElement.querySelector(`.igx-chip__item`).focus(); | ||
this.focusElement(); | ||
} | ||
} else if (this.currentTemplate === this.emptyFilter) { | ||
this.ghostChip.elementRef.nativeElement.querySelector(`.igx-chip__item`).focus(); | ||
|
@@ -264,7 +253,7 @@ export class IgxGridFilteringCellComponent implements AfterViewInit, OnInit { | |
this.filteringService.filter(this.column.field, this.rootExpressionsTree); | ||
} | ||
|
||
private isMoreIconVisible(): boolean { | ||
private isMoreIconHidden(): boolean { | ||
return this.filteringService.columnToMoreIconHidden.get(this.column.field); | ||
} | ||
|
||
|
@@ -309,4 +298,52 @@ export class IgxGridFilteringCellComponent implements AfterViewInit, OnInit { | |
this.cdr.detectChanges(); | ||
} | ||
} | ||
|
||
private ScrollToChip(columnIndex: number, shouldFocusNext: boolean) { | ||
this.filteringService.grid.nativeElement.focus({preventScroll: true}); | ||
this.filteringService.columnToFocus = this.filteringService.grid.visibleColumns[columnIndex]; | ||
this.filteringService.shouldFocusNext = shouldFocusNext; | ||
this.filteringService.grid.headerContainer.scrollTo(columnIndex); | ||
} | ||
|
||
private isFirstElementFocused(): boolean { | ||
return !(this.chipsArea && this.chipsArea.chipsList.length > 0 && | ||
this.chipsArea.chipsList.first.elementRef.nativeElement.querySelector(`.igx-chip__item`) !== document.activeElement); | ||
} | ||
|
||
private isLastElementFocused(): boolean { | ||
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. You could simplify this method. Too many if/else clauses. |
||
if (this.chipsArea) { | ||
if (this.isMoreIconHidden() && this.chipsArea.chipsList.last.elementRef.nativeElement.querySelector(`.igx-chip__remove`) !== | ||
document.activeElement) { | ||
return false; | ||
} else if (!this.isMoreIconHidden() && this.moreIcon.nativeElement !== document.activeElement) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
private focusFirstElement(): void { | ||
if (this.chipsArea.chipsList.length > 0) { | ||
this.chipsArea.chipsList.first.elementRef.nativeElement.querySelector(`.igx-chip__item`).focus(); | ||
} else { | ||
this.moreIcon.nativeElement.focus(); | ||
} | ||
} | ||
|
||
private focusElement(): void { | ||
if (this.filteringService.shouldFocusNext) { | ||
if (!this.isMoreIconHidden() && this.chipsArea.chipsList.length === 0) { | ||
this.moreIcon.nativeElement.focus(); | ||
} else { | ||
this.chipsArea.chipsList.first.elementRef.nativeElement.querySelector(`.igx-chip__item`).focus(); | ||
} | ||
} else { | ||
if (!this.isMoreIconHidden()) { | ||
this.moreIcon.nativeElement.focus(); | ||
} else { | ||
this.chipsArea.chipsList.last.elementRef.nativeElement.querySelector(`.igx-chip__remove`).focus(); | ||
} | ||
} | ||
} | ||
} |
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
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
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.
Setting
columnToFocus
andfocusNext
happens only in filtering cell component and in navigation service. And in the both places these two fields are set together and are never read. So in order to make the code a little bit easier to use and error prone we could create a method in the filtering service to set those two fields. They are only used in the service so make them private.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.
focusNext is read in the filtering cell when we decide in which direction we should move the focus.