Skip to content

Commit

Permalink
fix(connected-overlay): direction not being updated (#3293)
Browse files Browse the repository at this point in the history
Fixes #3241.
  • Loading branch information
crisbeto authored and kara committed Feb 27, 2017
1 parent c21ff40 commit 817dcfd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
22 changes: 22 additions & 0 deletions src/lib/core/overlay/overlay-directives.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import {ConnectedOverlayDirective, OverlayModule} from './overlay-directives';
import {OverlayContainer} from './overlay-container';
import {ConnectedPositionStrategy} from './position/connected-position-strategy';
import {ConnectedOverlayPositionChange} from './position/connected-position';
import {Dir} from '../rtl/dir';


describe('Overlay directives', () => {
let overlayContainerElement: HTMLElement;
let fixture: ComponentFixture<ConnectedOverlayDirectiveTest>;
let dir: {value: string};

beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -19,6 +21,9 @@ describe('Overlay directives', () => {
{provide: OverlayContainer, useFactory: () => {
overlayContainerElement = document.createElement('div');
return {getContainerElement: () => overlayContainerElement};
}},
{provide: Dir, useFactory: () => {
return dir = { value: 'ltr' };
}}
],
});
Expand Down Expand Up @@ -76,6 +81,23 @@ describe('Overlay directives', () => {
expect(positions.length).toBeGreaterThan(0);
});

it('should set and update the `dir` attribute', () => {
dir.value = 'rtl';
fixture.componentInstance.isOpen = true;
fixture.detectChanges();

expect(getPaneElement().getAttribute('dir')).toBe('rtl');

fixture.componentInstance.isOpen = false;
fixture.detectChanges();

dir.value = 'ltr';
fixture.componentInstance.isOpen = true;
fixture.detectChanges();

expect(getPaneElement().getAttribute('dir')).toBe('ltr');
});

describe('inputs', () => {

it('should set the width', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/core/overlay/overlay-directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,6 @@ export class ConnectedOverlayDirective implements OnDestroy {
this._position = this._createPositionStrategy() as ConnectedPositionStrategy;
overlayConfig.positionStrategy = this._position;

overlayConfig.direction = this.dir;

return overlayConfig;
}

Expand All @@ -223,7 +221,6 @@ export class ConnectedOverlayDirective implements OnDestroy {

const strategy = this._overlay.position()
.connectedTo(this.origin.elementRef, originPoint, overlayPoint)
.withDirection(this.dir)
.withOffsetX(this.offsetX)
.withOffsetY(this.offsetY);

Expand All @@ -250,6 +247,9 @@ export class ConnectedOverlayDirective implements OnDestroy {
this._createOverlay();
}

this._position.withDirection(this.dir);
this._overlayRef.getState().direction = this.dir;

if (!this._overlayRef.hasAttached()) {
this._overlayRef.attach(this._templatePortal);
this.attach.emit();
Expand Down

0 comments on commit 817dcfd

Please sign in to comment.