Skip to content

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

Open

Description

@Sekky61

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

Pressing Enter on a link (or Space on a button) inside an expanded ngAccordionPanel collapses the panel instead of activating the link/button.

ngAccordionGroup handles keydown for the whole group, including panel content, and calls preventDefault() on Enter/Space, so the focused element never gets activated. Arrow keys and Home/End are affected too, e.g. Home in an input inside a panel moves focus to the trigger.

The click handler only reacts to events coming from a trigger (_findTriggerPattern), the keydown handler doesn't check that:

readonly keydown = computed(() => {
return new KeyboardEventManager()
.on(this.prevKey, () => this.navigationBehavior.prev(), {ignoreRepeat: false})
.on(this.nextKey, () => this.navigationBehavior.next(), {ignoreRepeat: false})
.on('Home', () => this.navigationBehavior.first())
.on('End', () => this.navigationBehavior.last())
.on(' ', () => this.toggle())
.on('Enter', () => this.toggle());
});
/** The click event manager for the accordion trigger. */
readonly click = computed(() => {
return new ClickEventManager<PointerEvent>().on((e: PointerEvent) => {
const item = this._findTriggerPattern(_getEventTarget(e));
if (!item) return;
this.navigationBehavior.goto(item);
this.expansionBehavior.toggle(item);
});
});
/** Handles keydown events on the trigger, delegating to the group if not disabled. */
onKeydown(event: KeyboardEvent): void {
this.keydown().handle(event);
}

Reproduction

StackBlitz link: https://stackblitz.com/edit/z5sxyaq6?file=src%2Fmain.ts

Steps to reproduce:

  1. Expand "Section 1".
  2. Tab to "Link inside panel" or "Button inside panel" and press Enter / Space.
  3. Expand it again, click into the input and press Home.

Expected Behavior

The link/button is activated (shows up in the log) and the panel stays open. Home moves the caret in the input.

Actual Behavior

The panel collapses, nothing is activated. Home moves focus to the trigger.

Environment

  • Angular: 22.2.3
  • CDK/Material: @angular/aria 22.2.4 (also 22.1.6)
  • Browser(s): Chrome 155
  • Operating System (e.g. Windows, macOS, Ubuntu): Linux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: aria/accordiongemini-triagedLabel noting that an issue has been triaged by geminineeds triageThis issue needs to be triaged by the team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions