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 = {
2525 mixins : [ createStyledAttrsMixin ( 'CImage' ) ] ,
2626 props : {
2727 src : String ,
28+ srcset : String ,
2829 fallbackSrc : String ,
2930 ignoreFalback : Boolean ,
3031 htmlWidth : String ,
@@ -48,12 +49,13 @@ const CImage = {
4849 created ( ) {
4950 // Should only invoke window.Image in the browser.
5051 if ( process . browser ) {
51- this . loadImage ( this . src )
52+ this . loadImage ( this . src , this . srcset )
5253 }
5354 } ,
5455 methods : {
55- loadImage ( src ) {
56+ loadImage ( src , srcset ) {
5657 const image = new window . Image ( )
58+ image . srcset = srcset
5759 image . src = src
5860
5961 image . onload = ( event ) => {
@@ -70,9 +72,9 @@ const CImage = {
7072 render ( h ) {
7173 let imageProps
7274 if ( this . ignoreFallback ) {
73- imageProps = { src : this . src }
75+ imageProps = { src : this . src , srcset : this . srcset }
7476 } else {
75- imageProps = { src : this . hasLoaded ? this . src : this . fallbackSrc }
77+ imageProps = { src : this . hasLoaded ? this . src : this . fallbackSrc , srcset : this . srcset }
7678 }
7779 return h ( CNoSsr , [
7880 h ( 'img' , {
Original file line number Diff line number Diff line change @@ -45,3 +45,10 @@ it('fallback src works', async () => {
4545 expect ( screen . getByAltText ( / M e s u t K o c a / i) ) . toHaveAttribute ( 'src' , 'LOAD_FALLBACK_SRC' )
4646 } )
4747} )
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