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

Fix #1597 Add option to Toggle Nested List Items on Primary Action #1648

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
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