Problem/Motivation

When the same Views Bootstrap Accordion display is rendered more than once on a page with different arguments (for example two embeddings of the same view with different contextual filters), the markup produces duplicate id attributes. Duplicate IDs are an accessibility issue: they break the unique-ID requirement in HTML and can confuse assistive technologies.

Collapse panel IDs already use the unique instance prefix from ViewsBootstrap::getUniqueId() / Html::getUniqueId():

{{ id }}-collapse-{{ clean_key }}

Header IDs do not. They are built only from the group key:

heading{{ clean_key }}

With identical group values (e.g. years 2026, 2025, 2024), both accordions emit the same header IDs (headingkey--2026, etc.). aria-labelledby on the second accordion’s panels then points at the first accordion’s headers, so assistive tech can announce the wrong label.

Steps to reproduce

  1. Create a view using the Bootstrap Accordion style, with grouping that produces stable keys (e.g. year).
  2. Place that view display twice on the same page with different arguments (e.g. two embeddings of the same display with different contextual filter values).
  3. Inspect the markup.
  4. Observe duplicated header IDs such as headingkey--2026, and aria-labelledby on the second accordion resolving to headers from the first.

Proposed resolution

Prefix accordion header IDs with the same unique {{ id }} already used for collapse panels, and keep aria-labelledby in sync:

{% set heading_id = id ~ '-heading-' ~ clean_key %}

Use id="{{ heading_id }}" on the header and aria-labelledby="{{ heading_id }}" on the panel. data-bs-target / data-bs-parent are already unique and do not need changes.

Remaining tasks

  • Review the patch / merge request
  • Commit and tag a new release once the fix is merged

User interface changes

None.

API changes

None.

Data model changes

None.

CommentFileSizeAuthor
#3 fix-accordion-duplicate-heading-ids.patch1.52 KBtiago
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

tiago created an issue. See original summary.

tiago’s picture

Status: Active » Needs review
StatusFileSize
new1.52 KB

MR!62 solves the issue.
I have also attached the patch file here.

shelane made their first commit to this issue’s fork.

  • shelane committed 408172af on 5.5.x authored by tiago
    fix: #3614071 Accordion header IDs collide when the same view display is...
shelane’s picture

Status: Needs review » Fixed

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.