Skip to content
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

fix keyboarding behavior for right and left arrow keys in Tree View #5899

Merged
merged 5 commits into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix keyboarding behavior for right and left arrow keys in Tree View",
"packageName": "@microsoft/fast-foundation",
"email": "chhol@microsoft.com",
"dependentChangeType": "patch"
}
20 changes: 18 additions & 2 deletions packages/web-components/fast-foundation/src/tree-view/tree-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,32 @@ export class TreeView extends FoundationElement {
case keyArrowLeft:
if (e.target && this.isFocusableElement(e.target as HTMLElement)) {
const item = e.target as HTMLElement;
if (item instanceof TreeItem && item.childItemLength() > 0) {

if (
item instanceof TreeItem &&
item.childItemLength() > 0 &&
item.expanded
) {
Comment on lines +151 to +155
Copy link
Member Author

@chrisdholt chrisdholt Apr 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left arrow on an open parent node closes the node without moving focus.

item.expanded = false;
} else if (
item instanceof TreeItem &&
item.parentElement instanceof TreeItem
) {
TreeItem.focusItem(item.parentElement);
}
Comment on lines +157 to 162
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left arrow on either a child node or a closed node moves focus to its parent (if one exists).

}
return false;
case keyArrowRight:
if (e.target && this.isFocusableElement(e.target as HTMLElement)) {
const item = e.target as HTMLElement;
if (item instanceof TreeItem && item.childItemLength() > 0) {
if (
item instanceof TreeItem &&
item.childItemLength() > 0 &&
!item.expanded
) {
item.expanded = true;
Comment on lines +168 to 173
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right arrow on a closed node expands the node without moving focus.

} else if (item instanceof TreeItem && item.childItemLength() > 0) {
this.focusNextNode(1, e.target as TreeItem);
Comment on lines +174 to +175
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right arrow on expanded parent node focus its first child node.

}
}
return;
Expand Down