Check for data-interval on the first slide of carousel#31818
Conversation
Johann-S
left a comment
There was a problem hiding this comment.
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
|
Let me know if you want the patch for V4 too.. #31820 |
|
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. |
|
Hmm, true. I guess your v4-dev PR is fine then; I can change the commit message when merging that later. |
|
@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? |
|
@XhmikosR thanks! Sure, here you go: https://codepen.io/mitchellbryson/pen/poyXXMd |
|
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. :/ |
|
@XhmikosR Yep same here, it's not working with transitions. Looking into this now. |
|
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 |
|
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. |
|
@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. |
|
@XhmikosR yep, I think that's a very good idea :) |
|
_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. |
|
@XhmikosR thinks LGTM here 👍 |
|
I'd still like tests to include the previous failed attempt which wasn't caught :/ |
|
@XhmikosR is https://github.com/twbs/bootstrap/pull/31818/files#diff-5eae769087ca4f58ffb64ddef2d4b0e1R877 not sufficient? I added the 2nd cycle() call (which was missing before). |
|
@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. |
|
I updated the pen to show the 2nd bugfix working too: https://codepen.io/mitchellbryson/pen/ZEWgBEN?editors=1011 |
|
I can confirm that tests fail propery on main BTW :) |
|
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. |
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