Skip to content

Commit

Permalink
[removed] non-standard onClick props for ListGroup and ListGroupItem
Browse files Browse the repository at this point in the history
Old behaviour can be implemented using custom onClick handlers.
  • Loading branch information
stefanfisk committed Feb 24, 2015
1 parent f26e39f commit c822837
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 56 deletions.
1 change: 0 additions & 1 deletion src/ListGroup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ var ListGroup = React.createClass({

renderListItem: function (child, index) {
return cloneWithProps(child, {
onClick: createChainedFunction(child.props.onClick, this.props.onClick),
ref: child.ref,
key: child.key ? child.key : index
});
Expand Down
9 changes: 1 addition & 8 deletions src/ListGroupItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var ListGroupItem = React.createClass({
<a
{...this.props}
className={joinClasses(this.props.className, classSet(classes))}
onClick={this.handleClick}>
>
{this.props.header ? this.renderStructuredContent() : this.props.children}
</a>
);
Expand Down Expand Up @@ -82,13 +82,6 @@ var ListGroupItem = React.createClass({
header: header,
content: content
};
},

handleClick: function (e) {
if (this.props.onClick) {
e.preventDefault();
this.props.onClick(this.props.eventKey, this.props.href, this.props.target);
}
}
});

Expand Down
22 changes: 0 additions & 22 deletions test/ListGroupItemSpec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,4 @@ describe('ListGroupItem', function () {
assert.ok(instance.getDOMNode().lastChild.className.match(/\blist-group-item-text\b/));
});

it('Should call "onClick" when item is clicked', function (done) {
function handleClick(key, href) {
assert.equal(key, '2');
assert.equal(href, "#link");
done();
}
var instance = ReactTestUtils.renderIntoDocument(
<ListGroupItem onClick={handleClick} eventKey='2' href="#link">Item</ListGroupItem>
);
ReactTestUtils.Simulate.click(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a'));
});

it('Should call "onClick" with target attribute', function (done) {
function handleClick(key, href, target) {
assert.equal(target, '_blank');
done();
}
var instance = ReactTestUtils.renderIntoDocument(
<ListGroupItem onClick={handleClick} eventKey='2' href="#link" target='_blank'>Item</ListGroupItem>
);
ReactTestUtils.Simulate.click(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'a'));
});
});
25 changes: 0 additions & 25 deletions test/ListGroupSpec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,4 @@ describe('ListGroup', function () {
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance.refs.child2, 'list-group-item'));
});

it('Should call "onClick" when child item is clicked', function (done) {
var item1Called = false,
item2Called = false;
function handleClick(key, href) {
if (key === 1) {
item1Called = true;
} else if (key === 2) {
item2Called = true;
}
if (item1Called && item2Called) {
done();
}
}
var instance = ReactTestUtils.renderIntoDocument(
<ListGroup onClick={handleClick}>
<ListGroupItem eventKey={1} ref="item1">Item 1</ListGroupItem>
<ListGroupItem eventKey={2} ref="item2">Item 2</ListGroupItem>
<ListGroupItem eventKey={3} ref="item3">Item 3</ListGroupItem>
</ListGroup>
);
ReactTestUtils.Simulate.click(ReactTestUtils.findRenderedDOMComponentWithTag(instance.refs.item3, 'a'));
ReactTestUtils.Simulate.click(ReactTestUtils.findRenderedDOMComponentWithTag(instance.refs.item2, 'a'));
ReactTestUtils.Simulate.click(ReactTestUtils.findRenderedDOMComponentWithTag(instance.refs.item1, 'a'));
});

});

0 comments on commit c822837

Please sign in to comment.