amp-carousel 0.2 `goToSlide` action does not work well with string valued `index` argument
I am trying to implement customized carousel buttons with amp carousel 0.2 and amp-selector.
https://amp-playground.appspot.com/amp/5764640680181760
In the above example, the autoplay behavior of amp-carousel is unpredictable, slide advances in strange order. I also got errors in console:
Uncaught TypeError: Cannot read property 'style' of undefined
at y (style.js:119)
at K (dimensions.js:122)
at Ma (carousel.js:1276)
at Ka (carousel.js:1305)
at carousel.js:1179
at mutate (resources-impl.js:618)
at Rl (vsync-impl.js:470)
at Nl.f.vh (vsync-impl.js:426)
I suspect the cause is that
<amp-selector on="select:carousel.goToSlide(index=event.targetOption)">
passes a string valued index to carousel. But it is the same as in this example
https://amp.dev/documentation/examples/multimedia-animations/image_galleries_with_amp-carousel/#image-gallery-with-preview
so I assume it's a legitimate usage.
When carousel autoplay advances to next slide, it triggers amp-selector's select action to update its state, and in turn triggers the goToSlide action again with the same index, which should do nothing to the carousel. But this line
https://github.com/ampproject/amphtml/blob/9f67e4a06ef56f3918eb524c3390232829af24e7/extensions/amp-carousel/0.2/amp-carousel.js#L50
does not convert args['index'] to number before calling goToSlide, although JS auto converts string to number in many cases, this comparison fails
https://github.com/ampproject/amphtml/blob/9f67e4a06ef56f3918eb524c3390232829af24e7/extensions/amp-base-carousel/0.1/carousel.js#L486
which makes the code execution keep going as if the carousel needs to go to a different slide.
Which AMP version is affected?
1912120230490
/cc @sparhami
@caroqliu Hello Caroline, could you help take a look at the issue? Thanks!