Skip to content

docs: clarify carousel getInstance timing and pause in events#42358

Open
pierluigilenoci wants to merge 1 commit intotwbs:mainfrom
pierluigilenoci:docs/improve-carousel
Open

docs: clarify carousel getInstance timing and pause in events#42358
pierluigilenoci wants to merge 1 commit intotwbs:mainfrom
pierluigilenoci:docs/improve-carousel

Conversation

@pierluigilenoci
Copy link
Copy Markdown

Description

Add two warning callouts to the carousel documentation addressing the pain points reported in #35722:

  1. "Via JavaScript" section: Document that Carousel.getInstance() returns null for uninitialized carousels. Recommend getOrCreateInstance() (preferred) or deferring code until the window load event as alternatives.

  2. "Events" section: Clarify that calling pause() inside a slide.bs.carousel handler has no effect because the slide transition is already in progress, and recommend using slid.bs.carousel instead.

Motivation & Context

Issue #35722 reports that developers frequently struggle with getInstance() returning null and with pause() not working inside slide events. Two previous PRs (#37062, #38619) attempted to fix this but were closed — one had extraneous formatting changes, the other referenced jQuery which Bootstrap 5 no longer depends on. This PR uses only vanilla JavaScript and makes minimal, targeted additions.

Type of changes

  • Enhancement (non-breaking change)

Checklist

  • I have read the contributing guidelines
  • My change introduces changes to the documentation
  • I have updated the documentation accordingly

Related issues

Fixes #35722

Add two warning callouts to the carousel documentation:

- In "Via JavaScript": document that `Carousel.getInstance` returns
  `null` for uninitialized carousels and recommend `getOrCreateInstance`
  or the `window` `load` event as alternatives.
- In "Events": clarify that calling `pause` inside a `slide.bs.carousel`
  handler has no effect and recommend using `slid.bs.carousel` instead.

Fixes twbs#35722

Signed-off-by: Pierluigi Lenoci <pierluigilenoci@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve docs relating to carousel

1 participant