Skip to content

fix(aria/accordion): move listeners to trigger - #34053

Merged
crisbeto merged 1 commit into
angular:mainfrom
crisbeto:34011/aria-accordion-trigger
Nov 4, 2026
Merged

crisbeto merged 1 commit into
angular:mainfrom
crisbeto:34011/aria-accordion-trigger

Conversation

@crisbeto

@crisbeto crisbeto commented Nov 3, 2026

Copy link
Copy Markdown
Member

Currently the accordion listens to events on the entire accordion group. This is problematic, because it can end up picking up events from the accordion's content and we need to remember to filter them out on each usage.

These changes try to address the root cause by listening for events only on the triggers.

Fixes #34011.

Currently the accordion listens to events on the entire accordion group. This is problematic, because it can end up picking up events from the accordion's content and we need to remember to filter them out on each usage.

These changes try to address the root cause by listening for events only on the triggers.

Fixes angular#34011.
@crisbeto
crisbeto requested a review from ok7sai November 3, 2026 11:46
@crisbeto crisbeto added the target: patch This PR is targeted for the next patch release label Nov 3, 2026
@pullapprove
pullapprove Bot requested a review from andrewseguin November 3, 2026 11:46
'[attr.aria-disabled]': '_pattern.disabled()',
'[attr.disabled]': '_pattern.hardDisabled() ? true : null',
'[attr.tabindex]': '_pattern.tabIndex()',
'(keydown)': '_pattern.onKeydown($event)',

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: there are other ways to resolve the issue, but this one seemed like the most sustainable long-term. I might be missing some context on why we had the top-level listeners though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason was mostly for performance (one event listener handles all navigation items), but it's probably not a big deal for accordion as I can't imagine a use case there are hundreds of them in one group. ¯\_(ツ)_/¯

If we want to keep it single handler binding, then another possible solution might be passing down the event manually to the target/active child to separate the triggering logic (a similar way has been done in Grid https://github.com/angular/components/blob/main/src/aria/private/grid/grid.ts#L219), but I also doubt if it's sustainable for long-term.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair although my thinking is that there likely won't be that many accordions on a page for it to matter. I also suspect some of those gains might be offset by us trying to route the event to the right element.

@crisbeto crisbeto added the action: merge The PR is ready for merge by the caretaker label Nov 4, 2026
@crisbeto
crisbeto removed the request for review from andrewseguin November 4, 2026 08:37
@crisbeto
crisbeto merged commit c665617 into angular:main Nov 4, 2026
36 checks passed
@crisbeto

crisbeto commented Nov 4, 2026

Copy link
Copy Markdown
Member Author

This PR was merged into the repository. The changes were merged into the following branches:

crisbeto added a commit that referenced this pull request Nov 4, 2026
Currently the accordion listens to events on the entire accordion group. This is problematic, because it can end up picking up events from the accordion's content and we need to remember to filter them out on each usage.

These changes try to address the root cause by listening for events only on the triggers.

Fixes #34011.

(cherry picked from commit c665617)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: aria/accordion target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(aria/accordion): Enter/Space inside a panel toggles the accordion instead of activating the focused element

2 participants