Skip to content

Commit dddfbd1

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 1c44c17 commit dddfbd1

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
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();

src/material-experimental/mdc-tabs/tab-body.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
// This is a fallback that completely hides the content when the element becomes hidden.
3838
// Note that we can't do this in the animation definition, because the style gets recomputed too
3939
// 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 when starting an animation before
40+
// This can also be achieved with JS, but it has issues when starting an animation before
4141
// the previous one has finished.
4242
&[style*='visibility: hidden'] {
4343
display: none;

src/material/sidenav/drawer.scss

Lines changed: 11 additions & 0 deletions
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

src/material/tabs/tab-body.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// This is a fallback that completely hides the content when the element becomes hidden.
1212
// Note that we can't do this in the animation definition, because the style gets recomputed too
1313
// 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 when starting an animation before
14+
// This can also be achieved with JS, but it has issues when starting an animation before
1515
// the previous one has finished.
1616
&[style*='visibility: hidden'] {
1717
display: none;

0 commit comments

Comments
 (0)