@@ -19,6 +19,7 @@ class Image extends CloudinaryComponent {
1919 constructor ( props , context ) {
2020 super ( props , context ) ;
2121 this . imgElement = createRef ( ) ;
22+ this . placeholderElement = createRef ( ) ;
2223 this . state = { isLoaded : false }
2324 this . listenerRemovers = [ ] ;
2425 }
@@ -96,8 +97,18 @@ class Image extends CloudinaryComponent {
9697 } else {
9798 // Handle responsive only if lazy loading wasn't requested or already handled
9899 if ( this . isResponsive ( ) ) {
99- const removeListener = makeElementResponsive ( this . imgElement . current , this . getOptions ( ) ) ;
100- this . listenerRemovers . push ( removeListener ) ;
100+ const options = this . getOptions ( ) ;
101+ const placeholder = this . getPlaceholderType ( ) ;
102+
103+ // Make placeholder responsive
104+ if ( placeholder ) {
105+ const removePlaceholderListener = makeElementResponsive ( this . placeholderElement . current , { ...options , placeholder} ) ;
106+ this . listenerRemovers . push ( removePlaceholderListener ) ;
107+ }
108+
109+ // Make original image responsive
110+ const removeImgListener = makeElementResponsive ( this . imgElement . current , options ) ;
111+ this . listenerRemovers . push ( removeImgListener ) ;
101112 }
102113 }
103114 }
@@ -158,17 +169,18 @@ class Image extends CloudinaryComponent {
158169 } ) ;
159170 } ;
160171
172+
161173 renderPlaceholder = ( placeholder , attributes ) => {
162174 attributes . style = { ...( attributes . style || { } ) , opacity : 0 , position : 'absolute' }
163175 attributes . onLoad = this . handleImageLoaded ;
164176 const placeholderWrapperStyle = { display : 'inline' }
165- const placeholderAttributes = this . getAttributes ( { placeholder : placeholder . props . type } ) ;
177+ const placeholderAttributes = this . getAttributes ( { placeholder} ) ;
166178
167179 return (
168180 < Fragment >
169181 { this . renderImage ( attributes ) }
170182 < div style = { placeholderWrapperStyle } >
171- < img { ...placeholderAttributes } />
183+ < img ref = { this . placeholderElement } { ...placeholderAttributes } />
172184 </ div >
173185 </ Fragment >
174186 ) ;
@@ -178,11 +190,17 @@ class Image extends CloudinaryComponent {
178190 return < img ref = { this . attachRef } { ...attributes } />
179191 }
180192
181- render ( ) {
182- const { isLoaded} = this . state ;
193+ getPlaceholderType = ( ) => {
183194 const { children} = this . getExtendedProps ( ) ;
184195 const placeholder = this . getChildPlaceholder ( children ) ;
196+
197+ return placeholder ? placeholder . props . type : null ;
198+ }
199+
200+ render ( ) {
201+ const { isLoaded} = this . state ;
185202 const attributes = this . getAttributes ( ) ;
203+ const placeholder = this . getPlaceholderType ( ) ;
186204
187205 //If image wasn't loaded and there's a child placeholder then we render it.
188206 if ( ! isLoaded && placeholder ) {
0 commit comments