-
Notifications
You must be signed in to change notification settings - Fork 1
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
PER-8633: Arrow nav #300
Merged
Merged
PER-8633: Arrow nav #300
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
047f85a
PER-8633: Arrow nav
crisnicandrei a1807b3
Prettier
crisnicandrei b918c7a
PER-8633
crisnicandrei 9f52cca
Prettier
crisnicandrei 0d48199
PER-8633
crisnicandrei ba077e5
Removed console logs
crisnicandrei eddae9a
Linting
crisnicandrei da81aca
Prettier
crisnicandrei 48d7df2
PER-8633
crisnicandrei 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
134 changes: 108 additions & 26 deletions
134
src/app/file-browser/components/edit-tags/edit-tags.component.html
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 |
---|---|---|
|
@@ -69,6 +69,7 @@ export class EditTagsComponent | |
private lastDataStatus: DataStatus; | ||
private lastFolderLinkId: number; | ||
private dialogTagSubscription: Subscription; | ||
private currentIndex: number = 0; | ||
|
||
constructor( | ||
@Optional() @Inject(DIALOG_DATA) public dialogData: any, | ||
|
@@ -83,7 +84,7 @@ export class EditTagsComponent | |
) { | ||
this.subscriptions.push( | ||
this.tagsService.getTags$().subscribe((tags) => { | ||
if (this.allTags.length > tags.length) { | ||
if (this.allTags?.length > tags?.length) { | ||
// The user deleted one of our tags in manage-tags. | ||
// Let's close the editor. | ||
this.endEditing(); | ||
|
@@ -229,15 +230,15 @@ export class EditTagsComponent | |
this.itemTagsById.clear(); | ||
|
||
this.itemTags = this.filterTagsByType( | ||
this.item.TagVOs.map((tag) => | ||
this.allTags?.find((t) => t.tagId === tag.tagId) | ||
).filter( | ||
// Filter out tags that are now null from deletion | ||
(tag) => tag?.name | ||
) | ||
(this.item?.TagVOs || []) | ||
.map((tag) => this.allTags?.find((t) => t.tagId === tag.tagId)) | ||
.filter( | ||
// Filter out tags that are now null from deletion | ||
(tag) => tag?.name | ||
) | ||
); | ||
|
||
if (!this.item.TagVOs?.length) { | ||
if (!this.item?.TagVOs?.length) { | ||
return; | ||
} | ||
|
||
|
@@ -269,4 +270,51 @@ export class EditTagsComponent | |
close() { | ||
this.dialogRef.close(); | ||
} | ||
|
||
onArrowNav(event: KeyboardEvent, index: number) { | ||
event.stopPropagation(); | ||
if (event.key === 'ArrowDown') { | ||
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. We should probably use |
||
event.preventDefault(); | ||
if (index < this.matchingTags.length - 1) { | ||
this.currentIndex++; | ||
this.setFocusToCurrentIndex(index + 1); | ||
} | ||
} else if (event.key === 'ArrowUp') { | ||
event.preventDefault(); | ||
if (index > 0) { | ||
this.setFocusToCurrentIndex(index - 1); | ||
} else if (index === 0) { | ||
this.setFocusToInputOrButton(`new-tag-${this.tagType}`); | ||
} | ||
} | ||
} | ||
|
||
public setFocusToInputOrButton(inputClass) { | ||
const input = this.elementRef.nativeElement.querySelector(`.${inputClass}`); | ||
(input as HTMLElement).focus(); | ||
} | ||
|
||
public setFocusToFirstTagOrButton(event: KeyboardEvent) { | ||
if (event.key === 'ArrowDown') { | ||
event.preventDefault(); | ||
this.setFocusToCurrentIndex(0); | ||
} | ||
if (event.key === 'ArrowRight') { | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
this.setFocusToInputOrButton(`add-tag-${this.tagType}`); | ||
} | ||
if (event.key === 'ArrowLeft') { | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
this.setFocusToInputOrButton(`new-tag-${this.tagType}`); | ||
} | ||
} | ||
|
||
public setFocusToCurrentIndex(index) { | ||
const elements = this.elementRef.nativeElement.querySelectorAll( | ||
`.edit-tag-${this.tagType}` | ||
); | ||
(elements[index] as HTMLElement).focus(); | ||
} | ||
} |
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.
I'm not sure if it's possible, but might it be more effective to test if the proper elements are focused in DOM rather than spying on function calls? Sometimes spies are the most effective way to do testing, but I feel like in this situation if we can test focus directly (I think through
document.activeElement
... but I could be unsure about that!) it'd be the best because we could refactor the function calls later and still have tests pass. I think testing focus might be tricky though, so if it isn't possible these tests are a good compromise.