File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -69,7 +69,13 @@ class Button extends React.Component {
6969 }
7070
7171 return (
72- < Tag { ...attributes } className = { classes } ref = { getRef } onClick = { this . onClick } />
72+ < Tag
73+ type = { Tag === 'button' ? 'button' : undefined }
74+ { ...attributes }
75+ className = { classes }
76+ ref = { getRef }
77+ onClick = { this . onClick }
78+ />
7379 ) ;
7480 }
7581}
Original file line number Diff line number Diff line change @@ -83,6 +83,7 @@ class DropdownItem extends React.Component {
8383
8484 return (
8585 < Tag
86+ type = { Tag === 'button' ? 'button' : undefined }
8687 { ...props }
8788 tabIndex = { tabIndex }
8889 className = { classes }
Original file line number Diff line number Diff line change @@ -24,6 +24,34 @@ describe('Button', () => {
2424 expect ( wrapper . text ( ) ) . toBe ( 'Home' ) ;
2525 } ) ;
2626
27+ it ( 'should render type as "button" by default when tag is "button"' , ( ) => {
28+ const wrapper = mount ( < Button > Home</ Button > ) ;
29+
30+ expect ( wrapper . find ( 'button' ) . prop ( 'type' ) ) . toBe ( 'button' ) ;
31+ expect ( wrapper . text ( ) ) . toBe ( 'Home' ) ;
32+ } ) ;
33+
34+ it ( 'should render type as user defined when defined by the user' , ( ) => {
35+ const wrapper = mount ( < Button type = "submit" > Home</ Button > ) ;
36+
37+ expect ( wrapper . find ( 'button' ) . prop ( 'type' ) ) . toBe ( 'submit' ) ;
38+ expect ( wrapper . text ( ) ) . toBe ( 'Home' ) ;
39+ } ) ;
40+
41+ it ( 'should not render type by default when the type is not defined and the tag is not "button"' , ( ) => {
42+ const wrapper = mount ( < Button tag = "a" > Home</ Button > ) ;
43+
44+ expect ( wrapper . find ( 'a' ) . prop ( 'type' ) ) . toBe ( undefined ) ;
45+ expect ( wrapper . text ( ) ) . toBe ( 'Home' ) ;
46+ } ) ;
47+
48+ it ( 'should not render type by default when the type is not defined and the href is defined' , ( ) => {
49+ const wrapper = mount ( < Button href = "#" > Home</ Button > ) ;
50+
51+ expect ( wrapper . find ( 'a' ) . prop ( 'type' ) ) . toBe ( undefined ) ;
52+ expect ( wrapper . text ( ) ) . toBe ( 'Home' ) ;
53+ } ) ;
54+
2755 it ( 'should render buttons with default color' , ( ) => {
2856 const wrapper = shallow ( < Button > Default Button</ Button > ) ;
2957
Original file line number Diff line number Diff line change @@ -19,6 +19,27 @@ describe('DropdownItem', () => {
1919 expect ( wrapper . find ( 'button' ) . length ) . toBe ( 1 ) ;
2020 } ) ;
2121
22+ it ( 'should render type as "button" by default when tag is "button"' , ( ) => {
23+ const wrapper = mount ( < DropdownItem > Home</ DropdownItem > ) ;
24+
25+ expect ( wrapper . find ( 'button' ) . prop ( 'type' ) ) . toBe ( 'button' ) ;
26+ expect ( wrapper . text ( ) ) . toBe ( 'Home' ) ;
27+ } ) ;
28+
29+ it ( 'should render type as user defined when defined by the user' , ( ) => {
30+ const wrapper = mount ( < DropdownItem type = "submit" > Home</ DropdownItem > ) ;
31+
32+ expect ( wrapper . find ( 'button' ) . prop ( 'type' ) ) . toBe ( 'submit' ) ;
33+ expect ( wrapper . text ( ) ) . toBe ( 'Home' ) ;
34+ } ) ;
35+
36+ it ( 'should not render type by default when the type is not defined and the tag is not "button"' , ( ) => {
37+ const wrapper = mount ( < DropdownItem tag = "a" > Home</ DropdownItem > ) ;
38+
39+ expect ( wrapper . find ( 'a' ) . prop ( 'type' ) ) . toBe ( undefined ) ;
40+ expect ( wrapper . text ( ) ) . toBe ( 'Home' ) ;
41+ } ) ;
42+
2243 it ( 'should render custom element' , ( ) => {
2344 const Link = ( props ) => < a href = "/home" { ...props } > { props . children } </ a > ;
2445 const wrapper = mount ( < DropdownItem tag = { Link } > Home</ DropdownItem > ) ;
You can’t perform that action at this time.
0 commit comments