Skip to content

Commit fc204e4

Browse files
crisbetoandrewseguin
authored andcommitted
fix(material/sidenav): prevent focus from entering hidden sidenav if child element has a visibility
This is a similar fix that we've made for other components. Usually we set `visibility: hidden` on the sidenav which is enough to prevent the user from tabbing into it, however one of the children could override it with `visibility: visible`. These changes add an extra `display: none` on top which will prevent such issues. This has come up on AIO recently angular/angular#44990.
1 parent 72a07fc commit fc204e4

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

Diff for: src/cdk/overlay/dispatchers/overlay-outside-click-dispatcher.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ describe('OverlayOutsideClickDispatcher', () => {
304304
});
305305

306306
it(
307-
'should not throw an error when when closing out related components via the ' +
307+
'should not throw an error when closing out related components via the ' +
308308
'outsidePointerEvents emitter on background click',
309309
fakeAsync(() => {
310310
const firstOverlayRef = overlay.create();

Diff for: src/material-experimental/mdc-tabs/tab-body.scss

+11
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,15 @@
3131
.mat-mdc-tab-group-dynamic-height & {
3232
overflow: hidden;
3333
}
34+
35+
// Usually the `visibility: hidden` added by the animation is enough to prevent focus from
36+
// entering the collapsed content, but children with their own `visibility` can override it.
37+
// This is a fallback that completely hides the content when the element becomes hidden.
38+
// Note that we can't do this in the animation definition, because the style gets recomputed too
39+
// late, breaking the animation because Angular didn't have time to figure out the target height.
40+
// This can also be achieved with JS, but it has issues when starting an animation before
41+
// the previous one has finished.
42+
&[style*='visibility: hidden'] {
43+
display: none;
44+
}
3445
}

Diff for: src/material/sidenav/drawer.scss

+11
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,17 @@ $drawer-over-drawer-z-index: 4;
150150
transform: translate3d(-100%, 0, 0);
151151
}
152152
}
153+
154+
// Usually the `visibility: hidden` added by the animation is enough to prevent focus from
155+
// entering the hidden drawer content, but children with their own `visibility` can override it.
156+
// This is a fallback that completely hides the content when the element becomes hidden.
157+
// Note that we can't do this in the animation definition, because the style gets recomputed too
158+
// late, breaking the animation because Angular didn't have time to figure out the target
159+
// transform. This can also be achieved with JS, but it has issues when starting an
160+
// animation before the previous one has finished.
161+
&[style*='visibility: hidden'] {
162+
display: none;
163+
}
153164
}
154165

155166
// Note that this div isn't strictly necessary on all browsers, however we need it in

Diff for: src/material/tabs/tab-body.scss

+11
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,15 @@
55
.mat-tab-group-dynamic-height & {
66
overflow: hidden;
77
}
8+
9+
// Usually the `visibility: hidden` added by the animation is enough to prevent focus from
10+
// entering the collapsed content, but children with their own `visibility` can override it.
11+
// This is a fallback that completely hides the content when the element becomes hidden.
12+
// Note that we can't do this in the animation definition, because the style gets recomputed too
13+
// late, breaking the animation because Angular didn't have time to figure out the target height.
14+
// This can also be achieved with JS, but it has issues when starting an animation before
15+
// the previous one has finished.
16+
&[style*='visibility: hidden'] {
17+
display: none;
18+
}
819
}

0 commit comments

Comments
 (0)