File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ class Button extends React.Component {
4343 size,
4444 ...attributes
4545 } = this . props ;
46+ let Tag = 'button' ;
4647
4748 const classes = classNames (
4849 className ,
@@ -54,21 +55,17 @@ class Button extends React.Component {
5455 ) ;
5556
5657 if ( El ) {
57- return (
58- < El { ...attributes }
59- className = { classes }
60- onClick = { this . onClick } >
61- { children }
62- </ El >
63- ) ;
58+ Tag = El ;
59+ } else if ( attributes . href ) {
60+ Tag = 'a' ;
6461 }
6562
6663 return (
67- < button { ...attributes }
64+ < Tag { ...attributes }
6865 className = { classes }
6966 onClick = { this . onClick } >
7067 { children }
71- </ button >
68+ </ Tag >
7269 ) ;
7370 }
7471}
Original file line number Diff line number Diff line change @@ -18,6 +18,13 @@ describe('Button', () => {
1818 expect ( wrapper . text ( ) ) . toBe ( 'Home' ) ;
1919 } ) ;
2020
21+ it ( 'should render an anchor element if href exists' , ( ) => {
22+ const wrapper = mount ( < Button href = "/home" > Home</ Button > ) ;
23+
24+ expect ( wrapper . find ( 'a' ) . length ) . toBe ( 1 ) ;
25+ expect ( wrapper . text ( ) ) . toBe ( 'Home' ) ;
26+ } ) ;
27+
2128 it ( 'should render buttons with default color' , ( ) => {
2229 const wrapper = shallow ( < Button > Default Button</ Button > ) ;
2330
You can’t perform that action at this time.
0 commit comments