forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ListItem] Move the selected prop from MenuItem to ListItem (mui#12602)
* Added selected property to ListItem * Added selected example in ListItem documentation * Modified tests to include testing of ListItem'selected property * Removed selected property from MenuItem. Modified doc to specify selected property is from ListItem. Updated test * Corrected example. Fixed missing style * Modified components spec * Updated docs API * Prettified demo * should be ready to be merged
- Loading branch information
1 parent
c61d059
commit 43bcede
Showing
16 changed files
with
145 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { withStyles } from '@material-ui/core/styles'; | ||
import List from '@material-ui/core/List'; | ||
import ListItem from '@material-ui/core/ListItem'; | ||
import ListItemIcon from '@material-ui/core/ListItemIcon'; | ||
import ListItemText from '@material-ui/core/ListItemText'; | ||
import Divider from '@material-ui/core/Divider'; | ||
import InboxIcon from '@material-ui/icons/Inbox'; | ||
import DraftsIcon from '@material-ui/icons/Drafts'; | ||
|
||
const styles = theme => ({ | ||
root: { | ||
width: '100%', | ||
maxWidth: 360, | ||
backgroundColor: theme.palette.background.paper, | ||
}, | ||
}); | ||
|
||
class SelectedListItem extends React.Component { | ||
state = { | ||
selectedIndex: 1, | ||
}; | ||
|
||
handleListItemClick = (event, index) => { | ||
this.setState({ selectedIndex: index }); | ||
}; | ||
|
||
render() { | ||
const { classes } = this.props; | ||
|
||
return ( | ||
<div className={classes.root}> | ||
<List component="nav"> | ||
<ListItem | ||
button | ||
selected={this.state.selectedIndex === 0} | ||
onClick={event => this.handleListItemClick(event, 0)} | ||
> | ||
<ListItemIcon> | ||
<InboxIcon /> | ||
</ListItemIcon> | ||
<ListItemText primary="Inbox" /> | ||
</ListItem> | ||
<ListItem | ||
button | ||
selected={this.state.selectedIndex === 1} | ||
onClick={event => this.handleListItemClick(event, 1)} | ||
> | ||
<ListItemIcon> | ||
<DraftsIcon /> | ||
</ListItemIcon> | ||
<ListItemText primary="Drafts" /> | ||
</ListItem> | ||
</List> | ||
<Divider /> | ||
<List component="nav"> | ||
<ListItem | ||
button | ||
selected={this.state.selectedIndex === 2} | ||
onClick={event => this.handleListItemClick(event, 2)} | ||
> | ||
<ListItemText primary="Trash" /> | ||
</ListItem> | ||
<ListItem | ||
button | ||
selected={this.state.selectedIndex === 3} | ||
onClick={event => this.handleListItemClick(event, 3)} | ||
> | ||
<ListItemText primary="Spam" /> | ||
</ListItem> | ||
</List> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
SelectedListItem.propTypes = { | ||
classes: PropTypes.object.isRequired, | ||
}; | ||
|
||
export default withStyles(styles)(SelectedListItem); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters