Skip to content

Initialize aria-pressed for toggle buttons#42713

Open
Kevinjohn wants to merge 1 commit into
twbs:mainfrom
Kevinjohn:fix-button-aria-pressed-init
Open

Initialize aria-pressed for toggle buttons#42713
Kevinjohn wants to merge 1 commit into
twbs:mainfrom
Kevinjohn:fix-button-aria-pressed-init

Conversation

@Kevinjohn

@Kevinjohn Kevinjohn commented Jul 20, 2026

Copy link
Copy Markdown

Toggle buttons initialized without aria-pressed are not exposed as toggle buttons to assistive technologies until their first activation.

Description

  • Initialize a missing aria-pressed value from the button's current .active state.
  • Preserve an explicit author-provided aria-pressed value.
  • Cover inactive, pre-active, and explicitly configured buttons with a regression test.

Motivation & Context

Fixes #42328.

Observable sequence:

  • Create inactive and pre-active elements with data-bs-toggle="button".
  • Initialize the Button plugin for each element.
  • Expected: aria-pressed="false" and aria-pressed="true", matching each element's initial state.
  • Actual: both attributes remain absent until the button is toggled.

This replaces #42466 with a focused change based on current main and expands coverage for explicit author-provided values.

Type of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change)
  • 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 pnpm run js-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

Actual screenshots

Before (current main): the regression test receives null instead of the expected initial ARIA state.

Before: aria-pressed initialization regression test fails

After (this PR): the same Chrome Headless run reports 810/810 successful tests.

After: Bootstrap JavaScript tests report 810 successes

Validation

  • pnpm exec karma start js/tests/karma.conf.js --single-run: 810/810 successful
  • pnpm run js-lint: passes with 18 pre-existing warning-comment warnings
  • git diff --check

The local Karma process prints its existing full-page-reload shutdown warning after the test result.

Related issues

@Kevinjohn
Kevinjohn marked this pull request as ready for review July 20, 2026 03:54
@Kevinjohn
Kevinjohn requested a review from a team as a code owner July 20, 2026 03:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing aria-pressed="false" at toggle buttons initialization (button plugin)

2 participants