File tree Expand file tree Collapse file tree 3 files changed +25
-4
lines changed Top Open diff view settings Expand file tree Collapse file tree 3 files changed +25
-4
lines changed Top Open diff view settings Original file line number Diff line number Diff line change @@ -16,14 +16,15 @@ class ListGroup extends React.Component {
1616 } else if ( React . Children . count ( this . props . children ) === 1 && ! Array . isArray ( this . props . children ) ) {
1717 let child = this . props . children ;
1818
19- childrenAnchors = child . props . href ? true : false ;
19+ childrenAnchors = this . isAnchor ( child . props ) ;
2020
2121 } else {
2222
2323 childrenAnchors = Array . prototype . some . call ( this . props . children , ( child ) => {
24- return ! Array . isArray ( child ) ? child . props . href : Array . prototype . some . call ( child , ( subChild ) => {
25- return subChild . props . href ;
24+ return ! Array . isArray ( child ) ? this . isAnchor ( child . props ) : Array . prototype . some . call ( child , ( subChild ) => {
25+ return this . isAnchor ( subChild . props ) ;
2626 } ) ;
27+
2728 } ) ;
2829
2930 }
@@ -35,6 +36,10 @@ class ListGroup extends React.Component {
3536 }
3637 }
3738
39+ isAnchor ( props ) {
40+ return ( props . href || props . onClick ) ;
41+ }
42+
3843 renderUL ( items ) {
3944 let listItems = ValidComponentChildren . map ( items ,
4045 ( item , index ) => cloneElement ( item , { listItem : true } )
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ const ListGroupItem = React.createClass({
3131 classes . active = this . props . active ;
3232 classes . disabled = this . props . disabled ;
3333
34- if ( this . props . href || this . props . target || this . props . onClick ) {
34+ if ( this . props . href || this . props . onClick ) {
3535 return this . renderAnchor ( classes ) ;
3636 } else if ( this . props . listItem ) {
3737 return this . renderLi ( classes ) ;
Original file line number Diff line number Diff line change @@ -120,4 +120,20 @@ describe('ListGroup', function () {
120120 assert . equal ( React . findDOMNode ( instance ) . lastChild . nodeName , 'SPAN' ) ;
121121 assert . ok ( ReactTestUtils . findRenderedDOMComponentWithClass ( instance , 'list-group' ) ) ;
122122 } ) ;
123+
124+
125+
126+ it ( 'Should output a "div" when "ListGroupItem" children have an onClick handler' , function ( ) {
127+ let instance = ReactTestUtils . renderIntoDocument (
128+ < ListGroup >
129+ < ListGroupItem onClick = { ( ) => null } > 1st Child</ ListGroupItem >
130+ < ListGroupItem > 2nd Child</ ListGroupItem >
131+ </ ListGroup >
132+ ) ;
133+ assert . equal ( React . findDOMNode ( instance ) . nodeName , 'DIV' ) ;
134+ assert . equal ( React . findDOMNode ( instance ) . firstChild . nodeName , 'A' ) ;
135+ assert . equal ( React . findDOMNode ( instance ) . lastChild . nodeName , 'SPAN' ) ;
136+ assert . ok ( ReactTestUtils . findRenderedDOMComponentWithClass ( instance , 'list-group' ) ) ;
137+ } ) ;
138+
123139} ) ;
You can’t perform that action at this time.
0 commit comments