@@ -675,13 +675,13 @@ function SelectProvider($$interimElementProvider) {
675
675
} ) ;
676
676
677
677
/* @ngInject */
678
- function selectDefaultOptions ( $mdSelect , $mdConstant , $$rAF , $mdUtil , $mdTheming , $timeout , $window ) {
678
+ function selectDefaultOptions ( $mdSelect , $mdConstant , $$rAF , $mdUtil , $mdTheming , $timeout , $window , $document ) {
679
679
return {
680
680
parent : 'body' ,
681
681
onShow : onShow ,
682
682
onRemove : onRemove ,
683
683
hasBackdrop : true ,
684
- disableParentScroll : $mdUtil . floatingScrollbars ( ) ,
684
+ disableParentScroll : true ,
685
685
themable : true
686
686
} ;
687
687
@@ -733,11 +733,21 @@ function SelectProvider($$interimElementProvider) {
733
733
if ( opts . disableParentScroll ) {
734
734
opts . disableTarget = opts . parent . find ( 'md-content' ) ;
735
735
if ( ! opts . disableTarget . length ) opts . disableTarget = opts . parent ;
736
- if ( $mdUtil . floatingScrollbars ( ) ) {
737
- opts . disableTarget . css ( 'margin-right' , '16px' ) ;
736
+ opts . lastDisableCss = opts . disableTarget . attr ( 'style' ) ;
737
+ var heightOffset = opts . disableTarget [ 0 ] . scrollTop ;
738
+ if ( heightOffset == 0 && ( heightOffset = $document [ 0 ] . documentElement . scrollTop ) ) {
739
+ opts . restoreScrollOnDocElement = true ;
740
+ }
741
+ opts . disableTargetOffset = heightOffset ;
742
+ opts . disableTarget . css ( {
743
+ overflow : 'hidden' ,
744
+ position : 'fixed' ,
745
+ width : '100%' ,
746
+ top : ( - 1 * heightOffset ) + 'px'
747
+ } ) ;
748
+ if ( ! $mdUtil . floatingScrollbars ( ) ) {
749
+ opts . disableTarget . parent ( ) . css ( 'overflow-y' , 'scroll' ) ;
738
750
}
739
- opts . lastOverflow = opts . disableTarget . css ( 'overflow' ) ;
740
- opts . disableTarget . css ( 'overflow' , 'hidden' ) ;
741
751
}
742
752
// Only activate click listeners after a short time to stop accidental double taps/clicks
743
753
// from clicking the wrong item
@@ -860,12 +870,6 @@ function SelectProvider($$interimElementProvider) {
860
870
. removeClass ( 'md-clickable' ) ;
861
871
opts . target . attr ( 'aria-expanded' , 'false' ) ;
862
872
863
- if ( opts . disableParentScroll && $mdUtil . floatingScrollbars ( ) ) {
864
- opts . disableTarget . css ( 'overflow' , opts . lastOverflow ) ;
865
- opts . disableTarget . css ( 'margin-right' , '0px' ) ;
866
- delete opts . lastOverflow ;
867
- delete opts . disableTarget ;
868
- }
869
873
870
874
angular . element ( $window ) . off ( 'resize' , opts . resizefn ) ;
871
875
angular . element ( $window ) . off ( 'orientationchange' , opts . resizefn ) ;
@@ -881,6 +885,21 @@ function SelectProvider($$interimElementProvider) {
881
885
opts . parent [ 0 ] . removeChild ( element [ 0 ] ) ; // use browser to avoid $destroy event
882
886
opts . backdrop && opts . backdrop . remove ( ) ;
883
887
if ( opts . restoreFocus ) opts . target . focus ( ) ;
888
+ if ( opts . disableParentScroll ) {
889
+ opts . disableTarget . attr ( 'style' , opts . lastDisableCss || '' ) ;
890
+ if ( opts . restoreScrollOnDocElement ) {
891
+ $document [ 0 ] . documentElement . scrollTop = opts . disableTargetOffset ;
892
+ } else {
893
+ opts . disableTarget [ 0 ] . scrollTop = opts . disableTargetOffset ;
894
+ }
895
+ if ( ! $mdUtil . floatingScrollbars ( ) ) {
896
+ opts . disableTarget . parent ( ) . css ( 'overflow-y' , 'auto' ) ;
897
+ }
898
+ delete opts . lastDisableCss ;
899
+ delete opts . disableTarget ;
900
+ delete opts . disableTargetOffset ;
901
+ delete opts . restoreScrollOnDocElement ;
902
+ }
884
903
} ) ;
885
904
}
886
905
0 commit comments