Skip to content

Commit

Permalink
fix(material/expansion): able to tab into descendants with visibility…
Browse files Browse the repository at this point in the history
… while closed

The expansion panel sets `visibility: hidden` while it's closed in order to prevent users from tabbing into the content. This breaks down if a child has its own `visibility`, because it overrides the one coming from the parent. We can't use `display` in the animation definition, because it prevents the animations module from calculating the height when animating.

These changes add some CSS that will set `display: none` once the animation has settled.
  • Loading branch information
crisbeto committed Mar 8, 2022
1 parent 92863cc commit 5a19a24
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/dev-app/expansion/expansion-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ <h1>Single Expansion Panel</h1>
<mat-panel-title>Panel Title</mat-panel-title>
</mat-expansion-panel-header>

<ng-template matExpansionPanelContent>
This is the content text that makes sense here.
<mat-checkbox>Trigger a ripple</mat-checkbox>
</ng-template>
This is the content text that makes sense here.
<mat-checkbox>Trigger a ripple</mat-checkbox>
<button style="visibility: visible;">Hello</button>

<mat-action-row>
<button mat-button (click)="myPanel.expanded = false">CANCEL</button>
Expand Down
10 changes: 10 additions & 0 deletions src/material/expansion/expansion-panel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@
display: flex;
flex-direction: column;
overflow: visible;

// Usually the `visibility: hidden` added by the animation is enough to prevent focus from
// entering the collapsed content, but children with their own `visibility` can override it.
// In other components we set a `display: none` at the root to stop focus from reaching the
// elements, however we can't do that here, because the content can determine the width
// of an expansion panel. The most practical fallback is to use `!important` to override
// any custom visibility.
&[style*='visibility: hidden'] * {
visibility: hidden !important;
}
}

.mat-expansion-panel-body {
Expand Down

0 comments on commit 5a19a24

Please sign in to comment.