Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(window): create new window container when overlay container change #1867

Merged
merged 4 commits into from
Aug 26, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(window): create new container when old removed
  • Loading branch information
yggg committed Jul 29, 2019
commit e2b58fc5ac0e626b635fbcd46a97be8392693899
23 changes: 20 additions & 3 deletions src/framework/theme/components/window/window.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
import { NbWindowRef } from './window-ref';
import { NbWindowsContainerComponent } from './windows-container.component';
import { NbWindowComponent } from './window.component';
import { NB_DOCUMENT } from '../../theme.options';

/**
* The `NbWindowService` can be used to open windows.
Expand All @@ -38,7 +39,7 @@ import { NbWindowComponent } from './window.component';
* ```ts
* @NgModule({
* imports: [
* // ...
* // ...
* NbWindowModule.forRoot(config),
* ],
* })
Expand All @@ -49,7 +50,7 @@ import { NbWindowComponent } from './window.component';
* ```ts
* @NgModule({
* imports: [
* // ...
* // ...
* NbWindowModule.forChild(config),
* ],
* })
Expand Down Expand Up @@ -101,6 +102,7 @@ import { NbWindowComponent } from './window.component';
@Injectable()
export class NbWindowService {

protected document: Document;
protected overlayRef: NbOverlayRef;
protected windowsContainerViewRef: ViewContainerRef;
protected openWindows: NbWindowRef[] = [];
Expand All @@ -112,7 +114,9 @@ export class NbWindowService {
protected blockScrollStrategy: NbBlockScrollStrategyAdapter,
@Inject(NB_WINDOW_CONFIG) protected readonly defaultWindowsConfig: NbWindowConfig,
protected cfr: ComponentFactoryResolver,
@Inject(NB_DOCUMENT) document,
) {
this.document = document;
}

/**
Expand All @@ -124,7 +128,7 @@ export class NbWindowService {
windowContent: TemplateRef<any> | NbComponentType,
windowConfig: Partial<NbWindowConfig> = {},
): NbWindowRef {
if (this.windowsContainerViewRef == null) {
if (this.shouldCreateWindowsContainer()) {
this.createWindowsContainer();
}

Expand All @@ -138,7 +142,20 @@ export class NbWindowService {
return windowRef;
}

protected shouldCreateWindowsContainer(): boolean {
if (this.windowsContainerViewRef) {
const containerEl = this.windowsContainerViewRef.element.nativeElement;
return !this.document.body.contains(containerEl);
}

return true;
}

protected createWindowsContainer() {
if (this.overlayRef) {
this.overlayRef.dispose();
}

this.overlayRef = this.overlayService.create({
scrollStrategy: this.overlayService.scrollStrategies.noop(),
positionStrategy: this.overlayPositionBuilder.global().bottom().right(),
Expand Down