Skip to content

Commit 357ee4c

Browse files
robertmesserlejelbourn
authored andcommitted
fix(sidenav): switches to translate3d() for content positioning (#484)
* fix(sidenav): overflow should be set to auto rather than scroll * fix(sidenav): switches to `translate3d()` for content positioning
1 parent d83f062 commit 357ee4c

File tree

4 files changed

+33
-14
lines changed

4 files changed

+33
-14
lines changed

src/components/sidenav/sidenav-transitions.scss

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55

66

77
:host {
8-
& > .md-sidenav-backdrop {
8+
> .md-sidenav-backdrop {
99
&.md-sidenav-shown {
1010
transition: background-color $swift-ease-out-duration $swift-ease-out-timing-function;
1111
}
1212
}
1313

14-
& > md-content {
15-
transition: left $swift-ease-out-duration $swift-ease-out-timing-function,
16-
right $swift-ease-out-duration $swift-ease-out-timing-function;
14+
> md-content {
15+
transition: transform $swift-ease-out-duration $swift-ease-out-timing-function;
1716
}
1817

1918
> md-sidenav {

src/components/sidenav/sidenav.html

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33

44
<ng-content select="md-sidenav"></ng-content>
55

6-
<md-content [style.margin-left.px]="getMarginLeft()"
7-
[style.margin-right.px]="getMarginRight()"
8-
[style.left.px]="getPositionLeft()"
9-
[style.right.px]="getPositionRight()">
6+
<md-content [ngStyle]="getStyles()">
107
<ng-content></ng-content>
118
</md-content>

src/components/sidenav/sidenav.scss

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ $md-sidenav-push-background-color: md-color($md-background, dialog) !default;
1212

1313

1414
/**
15-
* Mixin to help with defining LTR/RTL 'transform: translateX()' values.
15+
* Mixin to help with defining LTR/RTL 'transform: translate3d()' values.
1616
* @param $open The translation value when the sidenav is opened.
1717
* @param $close The translation value when the sidenav is closed.
1818
*/
1919
@mixin md-sidenav-transition($open, $close) {
20-
transform: translateX($close);
20+
transform: translate3d($close, 0, 0);
2121

2222
&.md-sidenav-closed {
2323
// We use 'visibility: hidden | visible' because 'display: none' will not animate any
@@ -27,18 +27,18 @@ $md-sidenav-push-background-color: md-color($md-background, dialog) !default;
2727
visibility: hidden;
2828
}
2929
&.md-sidenav-closing {
30-
transform: translateX($close);
30+
transform: translate3d($close, 0, 0);
3131
will-change: transform;
3232
}
3333
&.md-sidenav-opening {
3434
@include md-elevation(1);
3535
visibility: visible;
36-
transform: translateX($open);
36+
transform: translate3d($open, 0, 0);
3737
will-change: transform;
3838
}
3939
&.md-sidenav-opened {
4040
@include md-elevation(1);
41-
transform: translateX($open);
41+
transform: translate3d($open, 0, 0);
4242
}
4343
}
4444

@@ -60,7 +60,7 @@ $md-sidenav-push-background-color: md-color($md-background, dialog) !default;
6060
@include md-stacking-context();
6161

6262
box-sizing: border-box;
63-
overflow-y: scroll;
63+
overflow-y: auto;
6464
-webkit-overflow-scrolling: touch;
6565

6666
// TODO(hansl): Update this with a more robust solution.

src/components/sidenav/sidenav.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,29 @@ export class MdSidenavLayout implements AfterContentInit {
371371
getPositionRight() {
372372
return this._getSidenavEffectiveWidth(this._right, 'push');
373373
}
374+
375+
/**
376+
* Returns the horizontal offset for the content area. There should never be a value for both
377+
* left and right, so by subtracting the right value from the left value, we should always get
378+
* the appropriate offset.
379+
* @internal
380+
*/
381+
getPositionOffset() {
382+
return this.getPositionLeft() - this.getPositionRight();
383+
}
384+
385+
/**
386+
* This is using [ngStyle] rather than separate [style...] properties because [style.transform]
387+
* doesn't seem to work right now.
388+
* @internal
389+
*/
390+
getStyles() {
391+
return {
392+
marginLeft: `${this.getMarginLeft()}px`,
393+
marginRight: `${this.getMarginRight()}px`,
394+
transform: `translate3d(${this.getPositionOffset()}px, 0, 0)`
395+
};
396+
}
374397
}
375398

376399

0 commit comments

Comments
 (0)