Skip to content

Commit

Permalink
fix(select): scroll strategy token cannot inject overlay (#10535)
Browse files Browse the repository at this point in the history
  • Loading branch information
jelbourn authored and andrewseguin committed Mar 23, 2018
1 parent c05005a commit 3eb71c2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
8 changes: 5 additions & 3 deletions src/lib/select/select-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {NgModule} from '@angular/core';

import {OverlayModule} from '@angular/cdk/overlay';
import {CommonModule} from '@angular/common';
import {MatSelect, MatSelectTrigger} from './select';
import {NgModule} from '@angular/core';
import {MatCommonModule, MatOptionModule} from '@angular/material/core';
import {OverlayModule} from '@angular/cdk/overlay';
import {MatFormFieldModule} from '@angular/material/form-field';
import {MAT_SELECT_SCROLL_STRATEGY_PROVIDER, MatSelect, MatSelectTrigger} from './select';


@NgModule({
Expand All @@ -22,5 +23,6 @@ import {MatFormFieldModule} from '@angular/material/form-field';
],
exports: [MatFormFieldModule, MatSelect, MatSelectTrigger, MatOptionModule, MatCommonModule],
declarations: [MatSelect, MatSelectTrigger],
providers: [MAT_SELECT_SCROLL_STRATEGY_PROVIDER]
})
export class MatSelectModule {}
27 changes: 17 additions & 10 deletions src/lib/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import {
import {
CdkConnectedOverlay,
Overlay,
RepositionScrollStrategy,
ScrollStrategy,
ViewportRuler,
} from '@angular/cdk/overlay';
import {filter, take, map, switchMap, takeUntil, startWith} from 'rxjs/operators';
import {
AfterContentInit,
Attribute,
Expand All @@ -40,7 +40,6 @@ import {
ElementRef,
EventEmitter,
Inject,
inject,
InjectionToken,
Input,
isDevMode,
Expand Down Expand Up @@ -75,7 +74,8 @@ import {
mixinTabIndex,
} from '@angular/material/core';
import {MatFormField, MatFormFieldControl} from '@angular/material/form-field';
import {defer, Subject, merge, Observable} from 'rxjs';
import {defer, merge, Observable, Subject} from 'rxjs';
import {filter, map, startWith, switchMap, take, takeUntil} from 'rxjs/operators';
import {matSelectAnimations} from './select-animations';
import {
getMatSelectDynamicMultipleError,
Expand Down Expand Up @@ -122,13 +122,20 @@ export const SELECT_PANEL_VIEWPORT_PADDING = 8;

/** Injection token that determines the scroll handling while a select is open. */
export const MAT_SELECT_SCROLL_STRATEGY =
new InjectionToken<() => ScrollStrategy>('mat-select-scroll-strategy', {
providedIn: 'root',
factory: () => {
const overlay = inject(Overlay);
return () => overlay.scrollStrategies.reposition();
}
});
new InjectionToken<() => ScrollStrategy>('mat-select-scroll-strategy');

/** @docs-private */
export function MAT_SELECT_SCROLL_STRATEGY_PROVIDER_FACTORY(overlay: Overlay):
() => RepositionScrollStrategy {
return () => overlay.scrollStrategies.reposition();
}

/** @docs-private */
export const MAT_SELECT_SCROLL_STRATEGY_PROVIDER = {
provide: MAT_SELECT_SCROLL_STRATEGY,
deps: [Overlay],
useFactory: MAT_SELECT_SCROLL_STRATEGY_PROVIDER_FACTORY,
};

/** Change event object that is emitted when the select value has changed. */
export class MatSelectChange {
Expand Down

0 comments on commit 3eb71c2

Please sign in to comment.