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

[ListItem] allowing for nestedindicator with righticonbutton presents #2898

Closed
wants to merge 3 commits 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
16 changes: 13 additions & 3 deletions docs/src/app/components/pages/components/List/ExampleNested.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,27 @@ import ActionGrade from 'material-ui/lib/svg-icons/action/grade';
import ContentInbox from 'material-ui/lib/svg-icons/content/inbox';
import ContentDrafts from 'material-ui/lib/svg-icons/content/drafts';
import ContentSend from 'material-ui/lib/svg-icons/content/send';
import IconButton from 'material-ui/lib/icon-button';

const ListExampleNested = () => (
<MobileTearSheet>
<List subheader="Nested List Items">
<ListItem primaryText="Sent mail" leftIcon={<ContentSend />} />
<ListItem primaryText="Drafts" leftIcon={<ContentDrafts />} />
<ListItem
primaryText="Sent mail"
leftIcon={<ContentSend />}
rightIconButton={<IconButton iconClassName="material-icons">delete</IconButton>}
/>
<ListItem
primaryText="Drafts"
leftIcon={<ContentDrafts />}
rightIconButton={<IconButton iconClassName="material-icons">delete</IconButton>}
/>
<ListItem
primaryText="Inbox"
leftIcon={<ContentInbox />}
initiallyOpen={true}
primaryTogglesNestedList={true}
rightIconButton={<IconButton iconClassName="material-icons">delete</IconButton>}
primaryTogglesNestedList={false}
nestedItems={[
<ListItem
key={1}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"prebuild": "rimraf lib",
"lint": "gulp eslint:src && gulp eslint:docs && gulp eslint:test",
"build": "babel ./src --out-dir ./lib",
"build:watch": "babel ./src --watch --out-dir ./lib",
"prepublish": "npm run build"
},
"keywords": [
Expand Down
71 changes: 47 additions & 24 deletions src/lists/list-item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,13 @@ const ListItem = React.createClass({
WebkitLineClamp: threeLine ? 2 : null,
WebkitBoxOrient: threeLine ? 'vertical' : null,
},

rightIcons: {
display: 'flex',
position: 'absolute',
right: 0,
top: 0,
},
};

let contentChildren = [children];
Expand Down Expand Up @@ -567,33 +574,49 @@ const ListItem = React.createClass({

//RightIconButtonElement
const hasNestListItems = nestedItems.length;
const hasRightElement = rightAvatar || rightIcon || rightIconButton || rightToggle;
const needsNestedIndicator = hasNestListItems && autoGenerateNestedIndicator && !hasRightElement;

if (rightIconButton || needsNestedIndicator) {
let rightIconButtonElement = rightIconButton;
let rightIconButtonHandlers = {
onKeyboardFocus: this._handleRightIconButtonKeyboardFocus,
onMouseEnter: this._handleRightIconButtonMouseEnter,
onMouseLeave: this._handleRightIconButtonMouseLeave,
onTouchTap: this._handleRightIconButtonTouchTap,
onMouseDown: this._handleRightIconButtonMouseUp,
onMouseUp: this._handleRightIconButtonMouseUp,
};

// Create a nested list indicator icon if we don't have an icon on the right
if (needsNestedIndicator) {
rightIconButtonElement = this.state.open ?
<IconButton><OpenIcon /></IconButton> :
<IconButton><CloseIcon /></IconButton>;
rightIconButtonHandlers.onTouchTap = this._handleNestedListToggle;
}
const needsNestedIndicator = hasNestListItems && autoGenerateNestedIndicator;

const rightIcons = [];
let rightIconButtonHandlers = {
onKeyboardFocus: this._handleRightIconButtonKeyboardFocus,
onMouseEnter: this._handleRightIconButtonMouseEnter,
onMouseLeave: this._handleRightIconButtonMouseLeave,
onTouchTap: this._handleRightIconButtonTouchTap,
onMouseDown: this._handleRightIconButtonMouseUp,
onMouseUp: this._handleRightIconButtonMouseUp,
};

if (needsNestedIndicator) {
let nestedIndicator = this.state.open ?
<IconButton><OpenIcon /></IconButton> :
<IconButton><CloseIcon /></IconButton>;
rightIconButtonHandlers.onTouchTap = this._handleNestedListToggle;
rightIcons.push(
React.cloneElement(
nestedIndicator,
{
key: rightIcons.length, ...rightIconButtonHandlers,
}
)
);
}

if (rightIconButton) {
delete rightIconButtonHandlers.onTouchTap;
let rightIconButtonElement = React.cloneElement(
rightIconButton,
{
key: rightIcons.length, ...rightIconButtonHandlers,
}
);
rightIcons.push(rightIconButtonElement);
}

if (rightIcons.length > 0) {
this._pushElement(
contentChildren,
rightIconButtonElement,
this.mergeStyles(styles.rightIconButton),
rightIconButtonHandlers
<div>{rightIcons}</div>,
styles.rightIcons
);
}

Expand Down