Skip to content

Commit

Permalink
Add ArrowLeft and ArrowRight support
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwooding committed Jun 10, 2019
1 parent d491977 commit e9fd648
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/material-ui-lab/src/TreeNode/TreeNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function TreeNode(props) {
focusFirstNode,
focusLastNode,
isFocused,
handleLeftArrow,
} = useTreeState();
const [nodes, setNodes] = React.useState([]);
const nodeRef = React.useRef(null);
Expand Down Expand Up @@ -125,6 +126,20 @@ function TreeNode(props) {
focusPreviousNode(idProp);
flag = true;
break;
case 'ArrowRight':
if (expandable) {
if (expanded) {
focusNextNode(idProp);
} else {
toggle();
}
}
flag = true;
break;
case 'ArrowLeft':
handleLeftArrow(idProp);
flag = true;
break;
case 'Home':
focusFirstNode();
flag = true;
Expand Down
12 changes: 12 additions & 0 deletions packages/material-ui-lab/src/TreeView/TreeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,17 @@ const TreeView = React.forwardRef(function TreeView(props, ref) {
}
};

const handleLeftArrow = id => {
if (isExpanded(id)) {
toggle(id);
} else {
const parent = nodeMap.current[id].parent;
if (parent) {
focus(parent.id);
}
}
};

return (
<TreeViewContext.Provider
value={{
Expand All @@ -195,6 +206,7 @@ const TreeView = React.forwardRef(function TreeView(props, ref) {
focusFirstNode,
focusLastNode,
isFocused,
handleLeftArrow,
}}
>
<ul role="tree" className={classes.root} ref={ref} {...other}>
Expand Down

0 comments on commit e9fd648

Please sign in to comment.