On a site running Bootstrap 5 (bs_base 2.x / bs_lib 2.x) the bs_slider_bootstrap carousel renders but does not slide: no autoplay, the prev/next controls and the indicators do nothing, and no JavaScript error
is thrown. Bootstrap 5 renamed every data attribute of its components from data-* to data-bs-* and its carousel plugin only reads the new names, so a carousel marked up with the Bootstrap 4 names is
never initialized.
The Bootstrap 4 names are emitted in two places:
modules/bs_slider_bootstrap/src/Plugin/BsSlider/BsSliderBootstrapCarousel.php,preprocess():data-interval,data-keyboard,data-pause,
data-ride,data-wrapon the carousel element.modules/bs_slider_bootstrap/templates/bs-slider--bootstrap-carousel.html.twig:data-targetanddata-slide-toon the indicators,data-slideon the prev/next controls. The
controls also usesr-only, which Bootstrap 5 renamed tovisually-hidden.
Steps to reproduce
- Install bs_slider with
bs_slider_bootstrapon a site with Bootstrap 5 (for example bs_base 2.0.0-alpha2 and bs_lib 2.0.0-alpha2, which load/libraries/bootstrap/js/dist/carousel.jsfrom Bootstrap
5.3). - Render a slider with the Bootstrap carousel plugin, controls and indicators enabled,
rideset tocarousel. - The first slide shows; nothing slides, clicking the controls or the indicators does nothing. In the DOM the carousel carries
data-ride="carousel"and the controlsdata-slide="prev"; Bootstrap 5's
Carouselselects[data-bs-ride="carousel"]and[data-bs-slide].
Proposed resolution
Stay on 1.x and emit both attribute sets, since Bootstrap 4 ignores data-bs-* and Bootstrap 5 ignores data-*:
BsSliderBootstrapCarousel::preprocess(): next todata-interval,data-keyboard,data-pause,data-rideanddata-wrapalso set
data-bs-interval,data-bs-keyboard,data-bs-pause,data-bs-rideanddata-bs-wrap.bs-slider--bootstrap-carousel.html.twig: indicators keep the<li>and getdata-bs-targetanddata-bs-slide-tonext to the old names (this also fixes
data-slide-to="loop.index0", which outputs the literal string instead of{{ loop.index0 }}); the prev/next controls getdata-bs-slidenext todata-slide; the control labels
getvisually-hiddennext tosr-only.
The jQuery plugin calls in js/gallery.js (.carousel('dispose'), .carousel(index)) keep working on both versions: Bootstrap 5 still registers its jQuery interface when jQuery is
present.
The Bootstrap 4 names can be dropped when 1.x stops supporting Bootstrap 4.
Remaining tasks
- Apply the change on 1.x, test controls, indicators, autoplay and the gallery mode on a Bootstrap 5 site and on a Bootstrap 4 site.
- Tag a release so sites on Bootstrap 5 can drop the patch.
Issue fork bs_slider-3624708
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
pivica commentedComment #4
pivica commentedBootstrap 5.3 dropped
list-style: nonefrom.carousel-indicators, so the<ol>showed its numbers; added Bootstrap'slist-unstyled, which Bootstrap 4 also has.Comment #6
pivica commentedMerged.