This repository was archived by the owner on Sep 20, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed
packages/chakra-ui-core/src/CImage Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ const CImage = {
25
25
mixins : [ createStyledAttrsMixin ( 'CImage' ) ] ,
26
26
props : {
27
27
src : String ,
28
+ srcset : String ,
28
29
fallbackSrc : String ,
29
30
ignoreFalback : Boolean ,
30
31
htmlWidth : String ,
@@ -48,12 +49,13 @@ const CImage = {
48
49
created ( ) {
49
50
// Should only invoke window.Image in the browser.
50
51
if ( process . browser ) {
51
- this . loadImage ( this . src )
52
+ this . loadImage ( this . src , this . srcset )
52
53
}
53
54
} ,
54
55
methods : {
55
- loadImage ( src ) {
56
+ loadImage ( src , srcset ) {
56
57
const image = new window . Image ( )
58
+ image . srcset = srcset
57
59
image . src = src
58
60
59
61
image . onload = ( event ) => {
@@ -70,9 +72,9 @@ const CImage = {
70
72
render ( h ) {
71
73
let imageProps
72
74
if ( this . ignoreFallback ) {
73
- imageProps = { src : this . src }
75
+ imageProps = { src : this . src , srcset : this . srcset }
74
76
} else {
75
- imageProps = { src : this . hasLoaded ? this . src : this . fallbackSrc }
77
+ imageProps = { src : this . hasLoaded ? this . src : this . fallbackSrc , srcset : this . srcset }
76
78
}
77
79
return h ( CNoSsr , [
78
80
h ( 'img' , {
Original file line number Diff line number Diff line change @@ -45,3 +45,10 @@ it('fallback src works', async () => {
45
45
expect ( screen . getByAltText ( / M e s u t K o c a / i) ) . toHaveAttribute ( 'src' , 'LOAD_FALLBACK_SRC' )
46
46
} )
47
47
} )
48
+
49
+ it ( 'srcset works' , async ( ) => {
50
+ renderComponent ( { template : '<CImage alt="My Image Description" src="LOAD_SUCCESS_SRC" srcset="LOAD_SUCCESS_SRC 400w" />' } )
51
+ await wait ( ( ) => {
52
+ expect ( screen . getByAltText ( / M y I m a g e D e s c r i p t i o n / i) ) . toHaveAttribute ( 'srcset' , 'LOAD_SUCCESS_SRC 400w' )
53
+ } )
54
+ } )
You can’t perform that action at this time.
0 commit comments