ampproject / ampproject/amphtml
amp-carousel 0.2 with `loop` and `type=carousel` has buggy looping behavior
- Dominant language
- JavaScript
- Stars
- 14.9k
- Forks
- 4.1k
- PR merge metrics
- No merged PRs in 30d
Description
### Description
When amp-carousel 0.2 is used with the `loop` and `type=carousel` attributes, the left arrow is always displayed on the first slide and the right arrow is always displayed on the last slide. However, clicking on these buttons don't result in expected behaviors.
## Expected
- When it's on the first slide
- After clicking on the left arrow button, the carousel jumps back to display the last slide, since it's a "loop". There should be no "blank slides".
- When it's on the last slide
- After clicking on the right arrow button, the carousel jumps back to display the first slide.
## Actual
- When it's on the first slide
- clicking on the left arrow button doesn't do anything
- It will actually scroll the first slide slightly to the right and display a blank region on the left
- When it's on the last slide
- clicking on the right arrow button doesn't do anything
See video:
https://user-images.githubusercontent.com/743034/142740556-e81f3063-a952-4e4b-870d-a3ed32bcd1c9.mp4
/CC @caroqliu
### Reproduction Steps
This can be reproduced with the following AMP HTML:
```
amp-carousel
body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}
```
[Playground link](https://playground.amp.dev/?format=websites&_gl=1*glz6dj*_ga*YW1wLVd5NUFON2hWN2tJZW8xam5zUzEtTUE.&mode=Responsive#share=PCFkb2N0eXBlIGh0bWw+CjxodG1sIOKaoSBsYW5nPSJlbiI+CjxoZWFkPgo8bWV0YSBjaGFyc2V0PSJ1dGYtOCI+CiAgPHRpdGxlPmFtc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CIgaGVpZ2h0PSIzMDAiIGFsdD0iYW5kIGFub3RoZXIgc2FtcGxlIGltYWdlIj48L2FtcC1pbWc+CiAgPC9hbXAtY2Fyb3VzZWw+IAo8L2JvZHk+PC9odG1sPg==)
### Relevant Logs
_No response_
### Browser(s) Affected
_No response_
### OS(s) Affected
_No response_
### Device(s) Affected
_No response_
### AMP Version Affected
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.