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(dialog): directionality not injected into child components #7111

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 11 additions & 1 deletion src/lib/dialog/dialog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {By} from '@angular/platform-browser';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {Location} from '@angular/common';
import {SpyLocation} from '@angular/common/testing';
import {Directionality} from '@angular/cdk/bidi';
import {MatDialogContainer} from './dialog-container';
import {OverlayContainer} from '@angular/cdk/overlay';
import {ESCAPE} from '@angular/cdk/keycodes';
Expand Down Expand Up @@ -433,6 +434,14 @@ describe('MatDialog', () => {
expect(overlayPane.getAttribute('dir')).toBe('rtl');
});

it('should inject the correct layout direction in the component instance', () => {
const dialogRef = dialog.open(PizzaMsg, { direction: 'rtl' });

viewContainerFixture.detectChanges();

expect(dialogRef.componentInstance.directionality.value).toBe('rtl');
});

it('should close all of the dialogs', async(() => {
dialog.open(PizzaMsg);
dialog.open(PizzaMsg);
Expand Down Expand Up @@ -970,7 +979,8 @@ class ComponentWithTemplateRef {
@Component({template: '<p>Pizza</p> <input> <button>Close</button>'})
class PizzaMsg {
constructor(public dialogRef: MatDialogRef<PizzaMsg>,
public dialogInjector: Injector) {}
public dialogInjector: Injector,
public directionality: Directionality) {}
}

@Component({
Expand Down
6 changes: 6 additions & 0 deletions src/lib/dialog/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ import {
TemplateRef,
} from '@angular/core';
import {extendObject} from '@angular/material/core';
import {Directionality} from '@angular/cdk/bidi';
import {Observable} from 'rxjs/Observable';
import {defer} from 'rxjs/observable/defer';
import {Subject} from 'rxjs/Subject';
import {MatDialogConfig} from './dialog-config';
import {MatDialogContainer} from './dialog-container';
import {MatDialogRef} from './dialog-ref';
import {of as observableOf} from 'rxjs/observable/of';


export const MAT_DIALOG_DATA = new InjectionToken<any>('MatDialogData');
Expand Down Expand Up @@ -277,6 +279,10 @@ export class MatDialog {
injectionTokens.set(MatDialogRef, dialogRef);
injectionTokens.set(MatDialogContainer, dialogContainer);
injectionTokens.set(MAT_DIALOG_DATA, config.data);
injectionTokens.set(Directionality, {
value: config.direction,
change: observableOf()
});

return new PortalInjector(userInjector || this._injector, injectionTokens);
}
Expand Down