File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -41,28 +41,24 @@ class ButtonsExample extends React.Component {
4141 < Button size = "lg" > Large (lg)</ Button >
4242 </ p >
4343 < p > Button Group</ p >
44- < p >
44+ < ButtonGroup className = "m-b-1" >
45+ < Button > Left</ Button >
46+ < Button > Middle</ Button >
47+ < Button > Right</ Button >
48+ </ ButtonGroup >
49+ < p > Button Toolbar</ p >
50+ < ButtonToolbar className = "m-b-1" >
4551 < ButtonGroup >
4652 < Button > Left</ Button >
4753 < Button > Middle</ Button >
4854 < Button > Right</ Button >
4955 </ ButtonGroup >
50- </ p >
51- < p > Button Toolbar</ p >
52- < p >
53- < ButtonToolbar >
54- < ButtonGroup >
55- < Button > Left</ Button >
56- < Button > Middle</ Button >
57- < Button > Right</ Button >
58- </ ButtonGroup >
59- < ButtonGroup >
60- < Button > Left</ Button >
61- < Button > Middle</ Button >
62- < Button > Right</ Button >
63- </ ButtonGroup >
64- </ ButtonToolbar >
65- </ p >
56+ < ButtonGroup >
57+ < Button > Left</ Button >
58+ < Button > Middle</ Button >
59+ < Button > Right</ Button >
60+ </ ButtonGroup >
61+ </ ButtonToolbar >
6662 </ div >
6763 ) ;
6864 }
Original file line number Diff line number Diff line change @@ -24,8 +24,10 @@ class Button extends React.Component {
2424
2525 onClick ( e ) {
2626 if ( this . props . disabled ) {
27- e . preventDefault ( ) ;
28- } else {
27+ return e . preventDefault ( ) ;
28+ }
29+
30+ if ( this . props . onClick ) {
2931 this . props . onClick ( e ) ;
3032 }
3133 }
Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ describe('Button', () => {
4545 } ) ;
4646
4747 describe ( 'onClick' , ( ) => {
48- it ( 'is called when passed as property ' , ( ) => {
48+ it ( 'calls props.onClick if it exists ' , ( ) => {
4949 const onClick = jasmine . createSpy ( 'onClick' ) ;
5050 const wrapper = mount ( < Button onClick = { onClick } > Testing Click</ Button > ) ;
5151
@@ -55,11 +55,13 @@ describe('Button', () => {
5555
5656 it ( 'is not called when disabled' , ( ) => {
5757 const e = jasmine . createSpyObj ( 'e' , [ 'preventDefault' ] ) ;
58- const onClick = jasmine . createSpy ( 'onClick' ) ;
59- const wrapper = mount ( < Button onClick = { onClick } disabled > Testing Click</ Button > ) ;
58+ const wrapper = mount ( < Button > Testing Click</ Button > ) ;
59+
60+ wrapper . instance ( ) . onClick ( e ) ;
61+ expect ( e . preventDefault ) . not . toHaveBeenCalled ( ) ;
6062
63+ wrapper . setProps ( { disabled : true } ) ;
6164 wrapper . instance ( ) . onClick ( e ) ;
62- expect ( onClick ) . not . toHaveBeenCalled ( ) ;
6365 expect ( e . preventDefault ) . toHaveBeenCalled ( ) ;
6466 } ) ;
6567 } ) ;
You can’t perform that action at this time.
0 commit comments