New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: handle indices properly when cellAlign
is center
or right
#952
Conversation
In order to determine when the slideIndex was intentionally set by a user.
…and slidesToShow > 1
…Align=center|right
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
cy.get('.slide.slide-visible') | ||
.should('have.length', 1) | ||
.find('img') | ||
.should('have.attr', 'data-slide', 'Slide 6'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This modification corresponds to the change in behavior in the scenario laid out in the PR description.
@@ -22,16 +26,13 @@ context('Infinity Carousel', () => { | |||
cy.get('button').contains('Prev').should('not.be.disabled'); | |||
cy.get('button').contains('Next').should('not.be.disabled').click(); | |||
|
|||
cy.wait(500); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cypress will wait for animations to finish, so the cy.wait
s are unnecessary:
https://docs.cypress.io/guides/core-concepts/interacting-with-elements#Animations
Regarding the changes in starting index for right-aligned stories: This has the effect of creating some potentially puzzling offsets if you start from the leftmost end of the carousel, as is default. But when using the carousel from right-to-left, whether it be with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!!!
Description
There are a variety of intertwined bugs related to slide index bounds (what the dots correspond to, also what determines whether prev/next buttons should be disabled) caused when
cellAlign
andscrollMode
are thrown into the mix.With
autoplayReverse
set totrue
andcellAlign
set to something other thanleft
, the component starts with an odd offset: issue repro. Note how the rightmost slide, which we should presumably start from, is partially concealed, and we cannot click the button to move over to it.Autoplay does not go to the last slide with
cellAlign
ofcenter
: issue reproScrolling to the right, we cannot reach slide 4: issue repro
This PR fixes the above, as well as performs a bit of generic refactoring.
NOTE: the fixes change someThis change was omitted, as the flexibility withscrollMode="remainder"
-like behaviors that were baked-in before. For example, this demo disables the "NEXT" button once the sixth slide is in view (e.g.,slideIndex = 4
).With the fixes in this PR, the same scenario (demo from PR preview) would see the "NEXT" button enabled at that point, so the user could click again, resulting in slide 6 on the left side and whitespace on the right.
This could be seen as a breaking change. I tend to see it as making the component more closely follow the behavior that the component props defines. Setting
scrollMode="remainder"
will produce the same result that was baked-in before, if that is what is desired.This change reduces the assumptions we are making about the library user's use case. For example, without the fix, the
current-slide
class will never be assigned to the final slide in the scenario above, whereas it can be assigned with the fix in place.current-slide
I pitched here didn't really make sense when you were jumping two slides at a time (=skipping every other slide) anyway. Also, it seemed like a bit of a trap that you could have three slides shown per page with a collection of 9 slides, and still end up with 4 pages.Type of Change
How Has This Been Tested?
A variety of unit tests appearing in the PR, and manually