@@ -94,42 +94,25 @@ export default class Dialog extends React.Component<Props, void> {
9494 render ( ) {
9595 const { children, dismissable, onDismiss, visible, style } = this . props ;
9696
97- const childrenArray = React . Children . toArray ( children ) ;
98- const title = childrenArray . find (
99- child => React . isValidElement ( child ) && child . type === DialogTitle
100- ) ;
101- const actionBtnsChildren = childrenArray . filter (
102- child => React . isValidElement ( child ) && child . type === DialogActions
103- ) ;
104- const restOfChildren = childrenArray . filter (
105- child =>
106- React . isValidElement ( child ) &&
107- child . type !== DialogActions &&
108- child . type !== DialogTitle
109- ) ;
110- let restOfChildrenWithoutTitle = restOfChildren ;
111- if ( ! title ) {
112- let found = false ;
113- restOfChildrenWithoutTitle = restOfChildren . map ( child => {
114- if (
115- React . isValidElement ( child ) &&
116- child . type === DialogContent &&
117- ! found
118- ) {
119- found = true ;
120- return React . cloneElement ( child , {
121- style : { paddingTop : 24 } ,
122- } ) ;
123- }
124- return child ;
125- } ) ;
126- }
12797 return (
12898 < Modal dismissable = { dismissable } onDismiss = { onDismiss } visible = { visible } >
12999 < AnimatedSurface style = { [ styles . container , style ] } >
130- { title }
131- { restOfChildrenWithoutTitle }
132- { actionBtnsChildren }
100+ { React . Children . toArray ( children )
101+ . filter ( Boolean )
102+ . map ( ( child , i ) => {
103+ if (
104+ i === 0 &&
105+ React . isValidElement ( child ) &&
106+ child . type === DialogContent
107+ ) {
108+ // Dialog content is the first item, so we add a top padding
109+ return React . cloneElement ( child , {
110+ style : [ { paddingTop : 24 } , child . props . style ] ,
111+ } ) ;
112+ }
113+
114+ return child ;
115+ } ) }
133116 </ AnimatedSurface >
134117 </ Modal >
135118 ) ;
0 commit comments