Skip to content

Commit

Permalink
Merge pull request #2726 from mikedklein/master
Browse files Browse the repository at this point in the history
[ListItem] Issue #2723: ListItem when disabled className is not returned
  • Loading branch information
oliviertassinari committed Jan 16, 2016
2 parents 4f16a41 + 06096ab commit 952a289
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/lists/list-item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ const ListItem = React.createClass({
}
},

_createDisabledElement(styles, contentChildren) {
_createDisabledElement(styles, contentChildren, additionalProps) {
const {
innerDivStyle,
style,
Expand All @@ -261,7 +261,14 @@ const ListItem = React.createClass({
style
);

return React.createElement('div', {style: this.prepareStyles(mergedDivStyles)}, contentChildren);
return (
<div
{...additionalProps}
style={mergedDivStyles}
>
{contentChildren}
</div>
);
},

_createLabelElement(styles, contentChildren) {
Expand Down Expand Up @@ -633,7 +640,7 @@ const ListItem = React.createClass({
<div>
{
hasCheckbox ? this._createLabelElement(styles, contentChildren) :
disabled ? this._createDisabledElement(styles, contentChildren) : (
disabled ? this._createDisabledElement(styles, contentChildren, other) : (
<EnhancedButton
{...other}
disabled={disabled}
Expand Down
77 changes: 77 additions & 0 deletions test/lists/list-item-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import React from 'react';
import ListItem from 'lists/list-item';
import injectTheme from '../fixtures/inject-theme';
import TestUtils from 'react-addons-test-utils';

describe('ListItem', () => {
let ThemedListItem;

beforeEach(() => {
ThemedListItem = injectTheme(ListItem);
});

it('should display a list-item', () => {
let render = TestUtils.renderIntoDocument(
<ThemedListItem />
);
let nodeTree = TestUtils.scryRenderedDOMComponentsWithTag(render, 'div');
let itemSpan = nodeTree[0].firstChild;

expect(itemSpan.tagName).to.equal('SPAN');
});

it('should display a list-item with text if primaryText is specified', () => {
let testText = 'Primary Text';
let render = TestUtils.renderIntoDocument(
<ThemedListItem
primaryText = {testText}
/>
);
let nodeTree = TestUtils.scryRenderedDOMComponentsWithTag(render, 'div');
let itemSpan = nodeTree[0].firstChild;

expect(itemSpan.childNodes[0].innerText).to.equal(testText);
});

it('should display a list-item elment with a class if specified', () => {
let testClass = 'test-class';
let render = TestUtils.renderIntoDocument(
<ThemedListItem
className = {testClass}
/>
);
let nodeTree = TestUtils.scryRenderedDOMComponentsWithTag(render, 'div');
let itemSpan = nodeTree[0].firstChild;

expect(itemSpan.hasAttribute('class')).to.be.true;
expect(itemSpan.getAttribute('class')).to.equal(testClass);
});

it('should display a disabled list-item if specified.', () => {
let render = TestUtils.renderIntoDocument(
<ThemedListItem
disabled = {true}
/>
);
let nodeTree = TestUtils.scryRenderedDOMComponentsWithTag(render, 'div');
let itemDiv = nodeTree[0].firstChild;

expect(itemDiv.tagName).to.equal('DIV');
});

it('should display a disabled list-item with a class if specified.', () => {
let testClass = 'test-class';
let render = TestUtils.renderIntoDocument(
<ThemedListItem
className = {testClass}
disabled = {true}
/>
);
let nodeTree = TestUtils.scryRenderedDOMComponentsWithTag(render, 'div');
let itemDiv = nodeTree[0].firstChild;

expect(itemDiv.tagName).to.equal('DIV');
expect(itemDiv.hasAttribute('class')).to.be.true;
expect(itemDiv.getAttribute('class')).to.equal(testClass);
});
});

0 comments on commit 952a289

Please sign in to comment.