Skip to content

Carousel: don't throw when no indicator is active - #42974

Open
njarrar wants to merge 1 commit into
twbs:v5-devfrom
njarrar:carousel-no-active-indicator
Open

njarrar wants to merge 1 commit into
twbs:v5-devfrom
njarrar:carousel-no-active-indicator

Conversation

@njarrar

@njarrar njarrar commented Oct 2, 2026 •

Copy link
Copy Markdown

Requested by Najeeb · project thread

Description

Carousel#_setActiveIndicatorElement() assumed one indicator always has the .active class. If a carousel has indicators but none is marked active, sliding throws TypeError: Cannot read properties of null (reading 'classList') and the new indicator never becomes active.

This change skips the reset when no indicator is active, so the new indicator is still marked active.

Motivation & Context

Markup where no indicator starts as active (for example when the active slide is set server side but the indicators are not) breaks the carousel on the first slide change. The fix makes the carousel tolerate that markup instead of throwing.

Type of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (non-breaking change)
  • Breaking change (fix or feature that would change existing functionality)

Checklist

  • I have read the contributing guidelines
  • My code follows the code style of the project (using npm run lint)
  • My change introduces changes to the documentation
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed

The new test fails on main with the TypeError above and passes with this change. npm run js-test-karma: 810 of 810 pass.

If the carousel has indicators but none of them has the `.active`
class, sliding threw a TypeError because the current indicator was
assumed to exist. Skip the reset when there is no active indicator so
the new one still gets marked as active.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RCK6vggtNiub9nuny85at8
@njarrar
njarrar requested a review from a team as a code owner October 2, 2026 15:45
@julien-deramond julien-deramond added js JavaScript or TypeScript sources and plugins v5 v5, the v5-dev branch labels Oct 3, 2026
@julien-deramond julien-deramond added the bug Something does not work as documented label Oct 10, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something does not work as documented js JavaScript or TypeScript sources and plugins v5 v5, the v5-dev branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants