diff --git a/packages/material-ui-lab/src/TreeItem/TreeItem.js b/packages/material-ui-lab/src/TreeItem/TreeItem.js
index 5371c5e8addabf..3146ee0c6bc955 100644
--- a/packages/material-ui-lab/src/TreeItem/TreeItem.js
+++ b/packages/material-ui-lab/src/TreeItem/TreeItem.js
@@ -195,14 +195,6 @@ const TreeItem = React.forwardRef(function TreeItem(props, ref) {
}
};
- const printableCharacter = (event, key) => {
- if (isPrintableCharacter(key)) {
- focusByFirstCharacter(nodeId, key);
- return true;
- }
- return false;
- };
-
const handleNextArrow = (event) => {
if (expandable) {
if (expanded) {
@@ -306,8 +298,9 @@ const TreeItem = React.forwardRef(function TreeItem(props, ref) {
flag = true;
} else if (multiSelect && ctrlPressed && key.toLowerCase() === 'a') {
flag = selectAllNodes(event);
- } else if (isPrintableCharacter(key)) {
- flag = printableCharacter(event, key);
+ } else if (!ctrlPressed && !event.shiftKey && isPrintableCharacter(key)) {
+ focusByFirstCharacter(nodeId, key);
+ flag = true;
}
}
diff --git a/packages/material-ui-lab/src/TreeItem/TreeItem.test.js b/packages/material-ui-lab/src/TreeItem/TreeItem.test.js
index abbcc4604fe6e7..bb4404b731179e 100644
--- a/packages/material-ui-lab/src/TreeItem/TreeItem.test.js
+++ b/packages/material-ui-lab/src/TreeItem/TreeItem.test.js
@@ -651,6 +651,28 @@ describe('', () => {
fireEvent.keyDown(document.activeElement, { key: 't' });
expect(getByTestId('two')).to.have.focus;
});
+
+ it('should not move focus when pressing a modifier key + letter', () => {
+ const { getByTestId } = render(
+
+
+
+
+
+ ,
+ );
+
+ getByTestId('apple').focus();
+ expect(getByTestId('apple')).to.have.focus;
+ fireEvent.keyDown(document.activeElement, { key: 'v', ctrlKey: true });
+ expect(getByTestId('apple')).to.have.focus;
+
+ fireEvent.keyDown(document.activeElement, { key: 'v', metaKey: true });
+ expect(getByTestId('apple')).to.have.focus;
+
+ fireEvent.keyDown(document.activeElement, { key: 'v', shiftKey: true });
+ expect(getByTestId('apple')).to.have.focus;
+ });
});
describe('asterisk key interaction', () => {