Skip to content

fix(aria/accordion): update panel visibility when the trigger links after first render - #34198

Open
DuncanFaulkner wants to merge 1 commit into
angular:mainfrom
DuncanFaulkner:fix/aria-accordion-panel-visible
Open

DuncanFaulkner wants to merge 1 commit into
angular:mainfrom
DuncanFaulkner:fix/aria-accordion-panel-visible

Conversation

@DuncanFaulkner

@DuncanFaulkner DuncanFaulkner commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Since #34061, AccordionTrigger links itself to its panel (panel._pattern = this._pattern) inside an effect, which can run after the panel's first render. AccordionPanel.visible is a computed over _pattern, and _pattern was a plain field. If anything reads visible() before the trigger has linked the panel, the computed caches false with no reactive dependencies and never re-evaluates.

A template that styles the panel from its public visible() signal is enough to hit this:

<div ngAccordionGroup>
  <button ngAccordionTrigger [panel]="panel">Trigger</button>
  <div ngAccordionPanel #panel="ngAccordionPanel" [class.is-hidden]="!panel.visible()">
    <ng-template ngAccordionContent>Content</ng-template>
  </div>
</div>

With @angular/aria 22.2.7 and 22.3.0, clicking the trigger sets aria-expanded="true", but visible() stays false, so the panel keeps the class and the panel's own [attr.inert] host binding (which reads the same computed) keeps it inert. The content is unreachable by keyboard and screen reader even though the trigger says it is expanded. The documented markup without a template read of visible() is not affected. It worked in 22.2.6 and earlier, when the link was made before the first render.

We hit this in a component library that hides the panel with [class.x]="!panel.visible()": every section stayed closed for anyone on the latest @angular/aria.

Fix

The panel's _pattern field is replaced by a _triggerPattern signal. The trigger sets it when it links or unlinks the panel, and the panel's visible, host bindings, expand()/collapse()/toggle() and dev-mode checks read it. The trigger's ownership check reads the signal directly instead of casting to any.

Tests

New spec AccordionPanel visibility > should update visible() when a template reads it before the trigger links the panel: a panel with [class.is-hidden]="!panel.visible()" is expanded and collapsed through the trigger, checking the class, inert, aria-expanded, aria-labelledby and the rendered content.

Validation

  • //src/aria/accordion:unit_tests (chromium and firefox) pass with the fix. With the previous accordion-panel.ts, the new spec fails in both browsers (Expected is-hidden not to contain 'is-hidden').
  • After that run I moved the spec into its own describe and added the aria-expanded / aria-labelledby assertions; those last edits are verified by this PR's CI.
  • The API golden (goldens/aria/accordion/index.api.md) is updated by hand; //goldens:aria_api runs in CI.
  • The review follow-up was type-checked locally on the accordion files; unit tests and the API golden run in this PR's CI.
  • Prettier and commit-message validation pass.
* This is set by the trigger when it initializes.
* There is no need for a panel pattern, as the trigger has all the necessary logic.
*/
_pattern?: AccordionTriggerPattern;

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.

This is with an underscore so it doesn't need to be backwards compatible. We can just expose the _triggerPattern.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@crisbeto will update and resubmit

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, done. The panel's _pattern is now a _triggerPattern signal that the trigger sets directly, and the getter/setter is gone. The specs and the API golden are updated to match.

…fter first render

Since angular#34061, `AccordionTrigger` links itself to its panel inside an effect, which can run after
the panel's first render. `AccordionPanel.visible` is a computed over `_pattern`, which was a plain
field. If anything reads `visible()` before the trigger links (for example a template binding such
as `[class.hidden]="!panel.visible()"`), the computed caches `false` with no reactive
dependencies and never re-evaluates. The panel's own `[attr.inert]` host binding reads the same
computed, so the panel stays hidden and inert even though the trigger reports
`aria-expanded="true"`.

The panel's `_pattern` field is replaced by a `_triggerPattern` signal that the trigger sets, so
`visible()` updates when the trigger links or unlinks the panel.
@DuncanFaulkner
DuncanFaulkner force-pushed the fix/aria-accordion-panel-visible branch from d1899b1 to 3e2574a Compare November 30, 2026 09:16

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

2 participants