This repository was archived by the owner on Mar 4, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +21
-12
lines changed Expand file tree Collapse file tree 3 files changed +21
-12
lines changed Original file line number Diff line number Diff line change @@ -105,16 +105,18 @@ function createShorthandFromValue(
105
105
const valIsNoop = _ . isNil ( value ) || typeof value === 'boolean'
106
106
if ( valIsNoop && ! options . render ) return null
107
107
108
- // return value as is if it a ReactElement
109
- if ( React . isValidElement ( value ) ) {
110
- return value as React . ReactElement < Props >
111
- }
112
-
113
108
const valIsPrimitive = typeof value === 'string' || typeof value === 'number'
114
109
const valIsPropsObject = _ . isPlainObject ( value )
110
+ const valIsReactElement = React . isValidElement ( value )
115
111
116
112
// unhandled type warning
117
- if ( process . env . NODE_ENV !== 'production' && ! valIsPrimitive && ! valIsPropsObject && ! valIsNoop ) {
113
+ if (
114
+ process . env . NODE_ENV !== 'production' &&
115
+ ! valIsPrimitive &&
116
+ ! valIsPropsObject &&
117
+ ! valIsReactElement &&
118
+ ! valIsNoop
119
+ ) {
118
120
console . error (
119
121
[
120
122
'Shorthand value must be a string|number|object|ReactElements.' ,
@@ -124,6 +126,11 @@ function createShorthandFromValue(
124
126
)
125
127
}
126
128
129
+ // return value 'as is' if it a ReactElement
130
+ if ( valIsReactElement ) {
131
+ return value as React . ReactElement < Props >
132
+ }
133
+
127
134
// ----------------------------------------
128
135
// Build up props
129
136
// ----------------------------------------
Original file line number Diff line number Diff line change @@ -103,7 +103,7 @@ describe('RadioGroup', () => {
103
103
104
104
if ( isShorthandApiTest ) {
105
105
describe ( 'click event handler' , ( ) => {
106
- it ( 'should set the value when item is clicked' , ( ) => {
106
+ it ( 'should set "checked" when item is clicked' , ( ) => {
107
107
const checkedValueChanged = jest . fn ( )
108
108
const wrapper = mountWithProvider (
109
109
< RadioGroup items = { getItems ( ) } checkedValueChanged = { checkedValueChanged } /> ,
@@ -150,7 +150,7 @@ describe('RadioGroup', () => {
150
150
} )
151
151
152
152
if ( isShorthandApiTest ) {
153
- it ( 'should not set the value when disabled item is clicked' , ( ) => {
153
+ it ( 'should not set "checked" when disabled item is clicked' , ( ) => {
154
154
const wrapper = mountWithProvider ( < RadioGroup items = { getItems ( { disabledItem : 1 } ) } /> )
155
155
const radioGroupItems = wrapper . find ( 'RadioGroupItem' )
156
156
Original file line number Diff line number Diff line change @@ -525,11 +525,13 @@ describe('factories', () => {
525
525
testCreateShorthand (
526
526
{
527
527
Component : 'p' ,
528
- value : < span { ...{ common : 'user' , user : true } as any } /> ,
529
- defaultProps : { common : 'default' , default : true } ,
530
- overrideProps : { common : 'override' , override : true } ,
528
+ value : (
529
+ < span { ...{ commonProp : 'originalElement' , originalElementProp : true } as any } />
530
+ ) ,
531
+ defaultProps : { commonProp : 'default' , defaultProp : true } ,
532
+ overrideProps : { commonProp : 'override' , overrideProp : true } ,
531
533
} ,
532
- { common : 'user ' , user : true } ,
534
+ { commonProp : 'originalElement ' , originalElementProp : true } ,
533
535
)
534
536
} )
535
537
} )
You can’t perform that action at this time.
0 commit comments