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-wrap on the carousel element.
  • modules/bs_slider_bootstrap/templates/bs-slider--bootstrap-carousel.html.twig: data-target and data-slide-to on the indicators, data-slide on the prev/next controls. The
    controls also use sr-only, which Bootstrap 5 renamed to visually-hidden.

Steps to reproduce

  1. Install bs_slider with bs_slider_bootstrap on 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.js from Bootstrap
    5.3).
  2. Render a slider with the Bootstrap carousel plugin, controls and indicators enabled, ride set to carousel.
  3. 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 controls data-slide="prev"; Bootstrap 5's
    Carousel selects [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 to data-interval, data-keyboard, data-pause, data-ride and data-wrap also set
    data-bs-interval, data-bs-keyboard, data-bs-pause, data-bs-ride and data-bs-wrap.
  • bs-slider--bootstrap-carousel.html.twig: indicators keep the <li> and get data-bs-target and data-bs-slide-to next 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 get data-bs-slide next to data-slide; the control labels
    get visually-hidden next to sr-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

Command icon 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

pivica created an issue. See original summary.

pivica’s picture

Version: 1.0.0-alpha8 » 1.x-dev

pivica’s picture

Status: Active » Needs review

Bootstrap 5.3 dropped list-style: none from .carousel-indicators, so the <ol> showed its numbers; added Bootstrap's list-unstyled, which Bootstrap 4 also has.

  • pivica committed 07a5ab96 on 1.x
    fix: #3624708 Bootstrap carousel slider does not initialize on Bootstrap...
pivica’s picture

Status: Needs review » Fixed

Merged.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.