Skip to content

Commit 1d6ac39

Browse files
author
Fabian Nickel
committed
add a highlight for a given path
1 parent 707a36c commit 1d6ac39

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/components/MuiTreeView/index.jsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ const styles = theme => ({
6363
maxWidth: '75vw',
6464
},
6565
expandIcon: {},
66+
highlightItem: {
67+
backgroundColor: 'rgb(220, 227, 239)',
68+
},
6669
});
6770

6871
/**
@@ -82,6 +85,8 @@ class MuiTreeView extends Component {
8285
expansionPanelDetailsProps: object,
8386
/** Properties applied to the ListItem element. */
8487
listItemProps: object,
88+
/** Value path for some leaf to highlight */
89+
highlightItem: arrayOf(string),
8590
};
8691

8792
static defaultProps = {
@@ -90,6 +95,7 @@ class MuiTreeView extends Component {
9095
expansionPanelSummaryProps: null,
9196
expansionPanelDetailsProps: null,
9297
listItemProps: null,
98+
highlightItem: null,
9399
};
94100

95101
createFilteredTree = memoize(
@@ -117,6 +123,7 @@ class MuiTreeView extends Component {
117123
expansionPanelSummaryProps,
118124
expansionPanelDetailsProps,
119125
listItemProps,
126+
highlightItem,
120127
...props
121128
} = this.props;
122129
const value = this.getNodeValue(node);
@@ -131,6 +138,14 @@ class MuiTreeView extends Component {
131138
}
132139

133140
if (isLeaf) {
141+
let isHighlighted = false;
142+
143+
if (highlightItem) {
144+
if (JSON.stringify(currentPath) === JSON.stringify(highlightItem)) {
145+
isHighlighted = true;
146+
}
147+
}
148+
134149
return (
135150
<ListItem
136151
disableGutters
@@ -140,6 +155,7 @@ class MuiTreeView extends Component {
140155
value={value}
141156
onClick={() => this.handleLeafClick({ value, parent, id })}
142157
button
158+
classes={isHighlighted ? { root: classes.highlightItem } : {}}
143159
{...listItemProps}>
144160
<div className={classes.text}>{value}</div>
145161
</ListItem>

0 commit comments

Comments
 (0)