Skip to content

Commit

Permalink
Move from nested function to sibling
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwooding committed Nov 8, 2019
1 parent eb24625 commit 4ed379a
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions packages/material-ui-lab/src/TreeItem/TreeItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,28 +133,31 @@ const TreeItem = React.forwardRef(function TreeItem(props, ref) {
}
};

const printableCharacter = (event, key) => {
if (key === '*') {
expandAllSiblings(event, nodeId);
return true;
}

if (isPrintableCharacter(key)) {
setFocusByFirstCharacter(nodeId, key);
return true;
}
return false;
};

const handleKeyDown = event => {
let flag = false;
const key = event.key;

const printableCharacter = e => {
if (key === '*') {
expandAllSiblings(e, nodeId);
flag = true;
} else if (isPrintableCharacter(key)) {
setFocusByFirstCharacter(nodeId, key);
flag = true;
}
};

if (event.altKey || event.ctrlKey || event.metaKey) {
return;
}
if (event.shift) {
if (key === ' ' || key === 'Enter') {
event.stopPropagation();
} else if (isPrintableCharacter(key)) {
printableCharacter(event);
flag = printableCharacter(event, key);
}
} else {
switch (key) {
Expand Down Expand Up @@ -197,7 +200,7 @@ const TreeItem = React.forwardRef(function TreeItem(props, ref) {
break;
default:
if (isPrintableCharacter(key)) {
printableCharacter(event);
flag = printableCharacter(event, key);
}
}
}
Expand Down

0 comments on commit 4ed379a

Please sign in to comment.