Skip to content

Commit 5a19a24

Browse files
committed
fix(material/expansion): able to tab into descendants with visibility 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.
1 parent 92863cc commit 5a19a24

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/dev-app/expansion/expansion-demo.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ <h1>Single Expansion Panel</h1>
88
<mat-panel-title>Panel Title</mat-panel-title>
99
</mat-expansion-panel-header>
1010

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

1615
<mat-action-row>
1716
<button mat-button (click)="myPanel.expanded = false">CANCEL</button>

src/material/expansion/expansion-panel.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@
4848
display: flex;
4949
flex-direction: column;
5050
overflow: visible;
51+
52+
// Usually the `visibility: hidden` added by the animation is enough to prevent focus from
53+
// entering the collapsed content, but children with their own `visibility` can override it.
54+
// In other components we set a `display: none` at the root to stop focus from reaching the
55+
// elements, however we can't do that here, because the content can determine the width
56+
// of an expansion panel. The most practical fallback is to use `!important` to override
57+
// any custom visibility.
58+
&[style*='visibility: hidden'] * {
59+
visibility: hidden !important;
60+
}
5161
}
5262

5363
.mat-expansion-panel-body {

0 commit comments

Comments
 (0)