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

[TreeView] Improve RTL support #18855

Merged
merged 2 commits into from
Dec 17, 2019
Merged
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
36 changes: 27 additions & 9 deletions packages/material-ui-lab/src/TreeItem/TreeItem.js
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import clsx from 'clsx';
import PropTypes from 'prop-types';
import Typography from '@material-ui/core/Typography';
import Collapse from '@material-ui/core/Collapse';
import { withStyles } from '@material-ui/core/styles';
import { withStyles, useTheme } from '@material-ui/core/styles';
import { useForkRef } from '@material-ui/core/utils';
import TreeViewContext from '../TreeView/TreeViewContext';

@@ -102,6 +102,7 @@ const TreeItem = React.forwardRef(function TreeItem(props, ref) {
const focused = isFocused ? isFocused(nodeId) : false;
const tabable = isTabable ? isTabable(nodeId) : false;
const icons = contextIcons || {};
const theme = useTheme();

if (!icon) {
if (expandable) {
@@ -146,6 +147,20 @@ const TreeItem = React.forwardRef(function TreeItem(props, ref) {
return false;
};

const handleNextArrow = event => {
if (expandable) {
if (expanded) {
focusNextNode(nodeId);
} else {
toggle(event);
}
}
};

const handlePreviousArrow = event => {
handleLeftArrow(nodeId, event);
};

const handleKeyDown = event => {
let flag = false;
const key = event.key;
@@ -178,17 +193,20 @@ const TreeItem = React.forwardRef(function TreeItem(props, ref) {
flag = true;
break;
case 'ArrowRight':
if (expandable) {
if (expanded) {
focusNextNode(nodeId);
} else {
toggle(event);
}
if (theme.direction === 'rtl') {
handlePreviousArrow(event);
} else {
handleNextArrow(event);
flag = true;
}
flag = true;
break;
case 'ArrowLeft':
handleLeftArrow(nodeId, event);
if (theme.direction === 'rtl') {
handleNextArrow(event);
flag = true;
} else {
handlePreviousArrow(event);
}
break;
case 'Home':
focusFirstNode();