Repository navigation
fix(aria/accordion): update panel visibility when the trigger links after first render - #34198
Open
DuncanFaulkner wants to merge 1 commit into
Open
DuncanFaulkner wants to merge 1 commit into
DuncanFaulkner wants to merge 1 commit into
Conversation
…fter first render Since angular#34061, `AccordionTrigger` links itself to its panel (`panel._pattern = ...`) 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"`. `_pattern` is now backed by a signal through a getter and setter, so `visible()` updates when the trigger links or unlinks the panel. Callers that assign `panel._pattern` keep working.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Since #34061,
AccordionTriggerlinks itself to its panel (panel._pattern = this._pattern) inside aneffect, which can run after the panel's first render.AccordionPanel.visibleis acomputedover_pattern, and_patternwas a plain field. If anything readsvisible()before the trigger has linked the panel, the computed cachesfalsewith no reactive dependencies and never re-evaluates.A template that styles the panel from its public
visible()signal is enough to hit this:With
@angular/aria22.2.7 and 22.3.0, clicking the trigger setsaria-expanded="true", butvisible()staysfalse, so the panel keeps the class and the panel's own[attr.inert]host binding (which reads the same computed) keeps itinert. The content is unreachable by keyboard and screen reader even though the trigger says it is expanded. The documented markup without a template read ofvisible()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
_patternis now backed by a private signal through a getter and setter, sovisible()(and the other readers of_pattern) update when the trigger links or unlinks the panel. The trigger'spanel._pattern = ...assignments and the existing spec assertions onpanel._patternare unchanged.A plain
_pattern = signal(...)would also work; it would change the trigger, the panel's host bindings and the existing specs to_pattern()/.set(). I kept the accessor to keep the change small, and can switch if you prefer.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-labelledbyand the rendered content.Validation
//src/aria/accordion:unit_tests(chromium and firefox) pass with the fix. With the previousaccordion-panel.ts, the new spec fails in both browsers (Expected is-hidden not to contain 'is-hidden').describeand added thearia-expanded/aria-labelledbyassertions; those last edits are verified by this PR's CI.goldens/aria/accordion/index.api.md) is updated by hand for the field to accessor change;//goldens:aria_apiruns in CI.