@@ -42,14 +42,15 @@ typeKnobsMap.forEach(({ name, knob, args = [] }, weight) => addKnobResolver({
4242} ) )
4343
4444const optionsReducer = ( res , value ) => ( { ...res , [ value ] : value } )
45- const withDefaultOption = ( options ) => ( { '' : ' --', ...options } )
46- const createSelect = ( propName , elements , defaultProps ) => {
45+ const withDefaultOption = ( options ) => ( { '--' : undefined , ...options } )
46+ const createSelect = ( propName , elements , defaultProps , isRequired ) => {
4747 try {
4848 const options = elements
4949 // Cleanup string quotes, if any.
5050 . map ( value => value . value . replace ( / ^ [ ' " ] ( .* ) [ ' " ] $ / , '$1' ) )
5151 . reduce ( optionsReducer , { } )
52- return select ( propName , withDefaultOption ( options ) , defaultProps [ propName ] )
52+ const value = defaultProps [ propName ] || ( isRequired && Object . values ( options ) [ 0 ] ) || undefined
53+ return select ( propName , isRequired ? options : withDefaultOption ( options ) , value )
5354 }
5455 catch ( e ) { }
5556}
@@ -59,11 +60,11 @@ addKnobResolver({
5960 name : 'PropTypes.oneOf' ,
6061 resolver : ( propName , propType , value , propTypes , defaultProps ) => {
6162 if ( propType . type . name === 'enum' && propType . type . value . length ) {
62- return createSelect ( propName , propType . type . value , defaultProps )
63+ return createSelect ( propName , propType . type . value , defaultProps , propType . required )
6364 }
6465 // for flow support
6566 if ( propType . type . name === 'union' && propType . type . elements ) {
66- return createSelect ( propName , propType . type . elements , defaultProps )
67+ return createSelect ( propName , propType . type . elements , defaultProps , propType . required )
6768 }
6869 }
6970} )
@@ -102,13 +103,13 @@ const getNewProps = (target, context, opts) => {
102103
103104const mutateChildren = ( component , context , opts ) => {
104105 return cloneElement ( component , { children : Children . map ( component . props . children , ( child ) => {
105- if ( child . type . __docgenInfo ) {
106+ if ( child . type && child . type . __docgenInfo ) {
106107 const newProps = getNewProps ( child , context , opts )
107108
108109 return cloneElement ( child , { ...child . props , ...newProps } )
109110 }
110111
111- if ( child . props . children ) {
112+ if ( child . props && child . props . children ) {
112113 return mutateChildren ( child , context , opts )
113114 }
114115
0 commit comments