Skip to content
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

Check for data-interval on the first slide of carousel #31818

Merged
merged 14 commits into from
Nov 1, 2020

Conversation

mitchellfyi
Copy link
Contributor

When starting a cycle for a carousel, it only checks for a default interval, and not an interval defined on the slide element via data props. This adds a check in before creating the interval to move to the next slide.

Fixes #31716

@mitchellfyi mitchellfyi requested a review from a team as a code owner October 2, 2020 08:52
Copy link
Member

@Johann-S Johann-S left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mitchellbryson,

Thanks for your work 👍

A few changes left:

  • Adding a unit test
  • Creating a private method to update the interval according to the next/current element

js/src/carousel.js Outdated Show resolved Hide resolved
@mitchellfyi
Copy link
Contributor Author

Let me know if you want the patch for V4 too.. #31820

@XhmikosR
Copy link
Member

XhmikosR commented Oct 2, 2020

We handle backports ourselves usually by cherry picking. And I'd prefer if we did the same here too. Only the tests need to be adapted, but we'll see after this lands.

@mitchellfyi
Copy link
Contributor Author

We handle backports ourselves usually by cherry picking. And I'd prefer if we did the same here too. Only the tests need to be adapted, but we'll see after this lands.

Ok. FYI this change includes using SelectorEngine, V4 doesn't.

@XhmikosR
Copy link
Member

XhmikosR commented Oct 2, 2020

Hmm, true. I guess your v4-dev PR is fine then; I can change the commit message when merging that later.

Johann-S
Johann-S previously approved these changes Oct 2, 2020
@XhmikosR
Copy link
Member

XhmikosR commented Oct 2, 2020

@mitchellbryson thanks for the PRs! Pretty solid contributions. :)

One last thing before merging: can you please update (or make a new ones) https://codepen.io/Johann-S/pen/zYqeNNO?editors=1010 to print the duration of the first slider too?

@mitchellfyi
Copy link
Contributor Author

@XhmikosR thanks!

Sure, here you go: https://codepen.io/mitchellbryson/pen/poyXXMd

@XhmikosR
Copy link
Member

XhmikosR commented Oct 2, 2020

Maybe I'm missing something but I'm getting inconsistent/wrong results. Isn't the second slider's duration supposed to be ~2s? I'm getting ~10s.

https://codepen.io/XhmikosR/pen/yLOdmgE?editors=1111

EDIT: and then after the first round is done, I'm getting ~5s for the first slider, 10s for the second. Either I'm missing something or the issue isn't fixed. :/

@mitchellfyi
Copy link
Contributor Author

@XhmikosR Yep same here, it's not working with transitions. Looking into this now.

@mitchellfyi
Copy link
Contributor Author

mitchellfyi commented Oct 2, 2020

The last commit fixes the issue with transitions by setting _activeElement to nextElement at the end of slide() but not after the transition is complete - I'm not familiar enough to know if this is going to be a problem or not so let me know.

A better approach might be to track nextElement on the instance too, but that would require more of a rewrite and I wanted to keep this PR simple until told otherwise.

EDIT: new codepen for testing: https://codepen.io/mitchellbryson/pen/ZEWgBEN?editors=1011

@XhmikosR
Copy link
Member

XhmikosR commented Oct 3, 2020

I checked again with https://codepen.io/XhmikosR/pen/yLOdmgE?editors=1011 and it seems to work right :)

EDIT: BTW the Codepen is mixing v4 CSS and v5 JS, but it seems it doesn't affect it for testing purposes only.
EDIT2: Update the pen to use v5 CSS too

@XhmikosR
Copy link
Member

XhmikosR commented Oct 3, 2020

@mitchellbryson I don't suppose you can update the tests so the previous regression is caught? If I didn't try with the Codepen, the patch would have been wrong.

@mitchellfyi
Copy link
Contributor Author

@XhmikosR yep, I think that's a very good idea :)

@mitchellfyi
Copy link
Contributor Author

_slide() no longer deals with updating the _config.interval, it only updates the _activeElement (just like it does with updating the active indicators through _setActiveIndicatorElement()) and now only cycle() updates the _config.interval, based on the current _activeElement.

_updateInterval() now uses an already set _activeElement, or it finds one (first run).

Updates to the tests reflect that next() is no longer dealing with intervals, only cycle() is.

js/src/carousel.js Outdated Show resolved Hide resolved
@Johann-S
Copy link
Member

Johann-S commented Oct 5, 2020

@XhmikosR thinks LGTM here 👍

@XhmikosR
Copy link
Member

XhmikosR commented Oct 5, 2020

I'd still like tests to include the previous failed attempt which wasn't caught :/

@mitchellfyi
Copy link
Contributor Author

@XhmikosR is https://github.com/twbs/bootstrap/pull/31818/files#diff-5eae769087ca4f58ffb64ddef2d4b0e1R877 not sufficient? I added the 2nd cycle() call (which was missing before).

@XhmikosR
Copy link
Member

XhmikosR commented Oct 5, 2020

@mitchellbryson oh I didn't see that patch, sorry. I think it should be covered now, indeed. @Johann-S please confirm that this covers all cases.

@mitchellfyi
Copy link
Contributor Author

mitchellfyi commented Oct 5, 2020

I updated the pen to show the 2nd bugfix working too: https://codepen.io/mitchellbryson/pen/ZEWgBEN?editors=1011

@XhmikosR XhmikosR requested a review from Johann-S October 5, 2020 13:20
@XhmikosR
Copy link
Member

XhmikosR commented Oct 5, 2020

I can confirm that tests fail propery on main BTW :)

Chrome Headless 85.0.4183.121 (Windows 10) Carousel cycle should get interval from data attribute on the active item element FAILED
        Error: Expected 1814 to equal 7.
            at <Jasmine>
            at UserContext.<anonymous> (js/tests/unit/js/tests/unit/carousel.spec.js:898:41 <- js/tests/unit/carousel.spec.js:16886:43)
            at <Jasmine>
        Error: Expected 1814 to equal 9385.
            at <Jasmine>
            at UserContext.<anonymous> (js/tests/unit/js/tests/unit/carousel.spec.js:903:41 <- js/tests/unit/carousel.spec.js:16889:43)
            at <Jasmine>
Chrome Headless 85.0.4183.121 (Windows 10) Carousel cycle should get interval from data attribute on the active item element FAILED
        Error: Expected 1814 to equal 7.
            at <Jasmine>
            at UserContext.<anonymous> (js/tests/unit/js/tests/unit/carousel.spec.js:898:41 <- js/tests/unit/carousel.spec.js:16886:43)
            at <Jasmine>
        Error: Expected 1814 to equal 9385.
            at <Jasmine>
            at UserContext.<anonymous> (js/tests/unit/js/tests/unit/carousel.spec.js:903:41 <- js/tests/unit/carousel.spec.js:16889:43)
            at <Jasmine>
........................................
Chrome Headless 85.0.4183.121 (Windows 10) Carousel next should update the active element to the next item before sliding FAILED
        Error: Expected null to equal <div id="secondItem" class="carousel-item carousel-item-next carousel-item-left">...</div>.
            at <Jasmine>
            at UserContext.<anonymous> (js/tests/unit/js/tests/unit/carousel.spec.js:656:39 <- js/tests/unit/carousel.spec.js:16779:41)
            at <Jasmine>
Chrome Headless 85.0.4183.121 (Windows 10) Carousel next should update the active element to the next item before sliding FAILED
        Error: Expected null to equal <div id="secondItem" class="carousel-item carousel-item-next carousel-item-left">...</div>.
            at <Jasmine>
            at UserContext.<anonymous> (js/tests/unit/js/tests/unit/carousel.spec.js:656:39 <- js/tests/unit/carousel.spec.js:16779:41)
            at <Jasmine>
...
Chrome Headless 85.0.4183.121 (Windows 10): Executed 450 of 450 (2 FAILED) (5.366 secs / 4.968 secs)
TOTAL: 2 FAILED, 448 SUCCESS

@XhmikosR XhmikosR changed the title Check for data-interval on the first slide of carousel (#31716) Check for data-interval on the first slide of carousel Oct 7, 2020
@XhmikosR
Copy link
Member

FYI @mitchellbryson I just wait for another review; unfortunately it seems we are a little stuck (lack of JS-involved people). I'd like to get this patch into alpha3 and #31820 assuming you reopen it and adapt it after this one is merged.

@XhmikosR XhmikosR merged commit 3a5f9f5 into twbs:main Nov 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Carousel data-interval is always 5000 on first item
3 participants