Skip to content

Commit

Permalink
Fix #1597 Add option to Toggle Nested List Items on Primary Action
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac Johnston committed Sep 15, 2015
1 parent 0138ce9 commit 7c1e635
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/src/app/components/pages/components/lists.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ class ListsPage extends React.Component {
primaryText="Inbox"
leftIcon={<ContentInbox />}
initiallyOpen={true}
primaryTogglesNestedList={true}
nestedItems={[
<ListItem primaryText="Starred" leftIcon={<ActionGrade />} />,
<ListItem
Expand Down
10 changes: 9 additions & 1 deletion src/lists/list-item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const ListItem = React.createClass({
onKeyboardFocus: React.PropTypes.func,
onMouseEnter: React.PropTypes.func,
onMouseLeave: React.PropTypes.func,
primaryTogglesNestedList: React.PropTypes.bool,
onNestedListToggle: React.PropTypes.func,
onTouchStart: React.PropTypes.func,
rightAvatar: React.PropTypes.element,
Expand Down Expand Up @@ -98,6 +99,7 @@ const ListItem = React.createClass({
secondaryText,
secondaryTextLines,
style,
primaryTogglesNestedList,
...other,
} = this.props;

Expand Down Expand Up @@ -321,6 +323,11 @@ const ListItem = React.createClass({
</NestedList>
) : undefined;

let extraAttributes = {};
if (primaryTogglesNestedList) {
extraAttributes.onTouchTap = this._handleNestedListToggle;
}

return hasCheckbox ? this._createLabelElement(styles, contentChildren) :
disabled ? this._createDisabledElement(styles, contentChildren) : (
<div>
Expand All @@ -334,7 +341,8 @@ const ListItem = React.createClass({
onMouseEnter={this._handleMouseEnter}
onTouchStart={this._handleTouchStart}
ref="enhancedButton"
style={this.mergeAndPrefix(styles.root, style)}>
style={this.mergeAndPrefix(styles.root, style)}
{...extraAttributes}>
<div style={this.mergeAndPrefix(styles.innerDiv, innerDivStyle)}>
{contentChildren}
</div>
Expand Down

0 comments on commit 7c1e635

Please sign in to comment.