Skip to content

Commit e67a16a

Browse files
author
Fabian Nickel
committed
highlight an item
1 parent 4c5ad3c commit e67a16a

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/components/MuiTreeView/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const tree = [
2525
<MuiTreeView
2626
defaultExpanded
2727
onLeafClick={node => alert(JSON.stringify(node))}
28+
highlightId="example-id"
2829
tree={tree}
2930
/>
3031
```

src/components/MuiTreeView/index.jsx

Lines changed: 7 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(138, 138, 138)',
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+
/** Id of a leaf which will be highlighted by adding the class */
89+
highlightId: oneOfType[(string, number)],
8590
};
8691

8792
static defaultProps = {
@@ -117,6 +122,7 @@ class MuiTreeView extends Component {
117122
expansionPanelSummaryProps,
118123
expansionPanelDetailsProps,
119124
listItemProps,
125+
highlightId,
120126
...props
121127
} = this.props;
122128
const value = this.getNodeValue(node);
@@ -140,6 +146,7 @@ class MuiTreeView extends Component {
140146
value={value}
141147
onClick={() => this.handleLeafClick({ value, parent, id })}
142148
button
149+
classes={highlightId === id ? { root: classes.highlightItem } : {}}
143150
{...listItemProps}>
144151
<div className={classes.text}>{value}</div>
145152
</ListItem>

0 commit comments

Comments
 (0)