From b86e03e542aa174c1fec90436c15695e40a18de0 Mon Sep 17 00:00:00 2001 From: Gerald Yeo Date: Sun, 26 Apr 2015 21:40:07 +0800 Subject: [PATCH] [fixed] ListGroup rendering a ul when ListGroupItem has onClick handler remove props.target check in ListGroup and ListGroupItem --- src/ListGroup.js | 11 ++++++++--- src/ListGroupItem.js | 2 +- test/ListGroupSpec.js | 16 ++++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/ListGroup.js b/src/ListGroup.js index 14714a6fb8..601e6c562a 100644 --- a/src/ListGroup.js +++ b/src/ListGroup.js @@ -16,14 +16,15 @@ class ListGroup extends React.Component { } else if (React.Children.count(this.props.children) === 1 && !Array.isArray(this.props.children)) { let child = this.props.children; - childrenAnchors = child.props.href ? true : false; + childrenAnchors = this.isAnchor(child.props); } else { childrenAnchors = Array.prototype.some.call(this.props.children, (child) => { - return !Array.isArray(child) ? child.props.href : Array.prototype.some.call(child, (subChild) => { - return subChild.props.href; + return !Array.isArray(child) ? this.isAnchor(child.props) : Array.prototype.some.call(child, (subChild) => { + return this.isAnchor(subChild.props); }); + }); } @@ -35,6 +36,10 @@ class ListGroup extends React.Component { } } + isAnchor(props){ + return (props.href || props.onClick); + } + renderUL(items) { let listItems = ValidComponentChildren.map(items, (item, index) => cloneElement(item, { listItem: true }) diff --git a/src/ListGroupItem.js b/src/ListGroupItem.js index 50e3ab2f64..dae133d54f 100644 --- a/src/ListGroupItem.js +++ b/src/ListGroupItem.js @@ -31,7 +31,7 @@ const ListGroupItem = React.createClass({ classes.active = this.props.active; classes.disabled = this.props.disabled; - if (this.props.href || this.props.target || this.props.onClick) { + if (this.props.href || this.props.onClick) { return this.renderAnchor(classes); } else if (this.props.listItem) { return this.renderLi(classes); diff --git a/test/ListGroupSpec.js b/test/ListGroupSpec.js index 98ba2958b8..e28c64b04a 100644 --- a/test/ListGroupSpec.js +++ b/test/ListGroupSpec.js @@ -120,4 +120,20 @@ describe('ListGroup', function () { assert.equal(React.findDOMNode(instance).lastChild.nodeName, 'SPAN'); assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'list-group')); }); + + + + it('Should output a "div" when "ListGroupItem" children have an onClick handler', function () { + let instance = ReactTestUtils.renderIntoDocument( + + null}>1st Child + 2nd Child + + ); + assert.equal(React.findDOMNode(instance).nodeName, 'DIV'); + assert.equal(React.findDOMNode(instance).firstChild.nodeName, 'A'); + assert.equal(React.findDOMNode(instance).lastChild.nodeName, 'SPAN'); + assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'list-group')); + }); + });