Skip to content

Commit

Permalink
fix(directionality): change event now emit the new value
Browse files Browse the repository at this point in the history
  • Loading branch information
EladBezalel committed Nov 18, 2017
1 parent 0f954a0 commit b76cc96
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/cdk/bidi/dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class Dir implements Directionality {
private _isInitialized: boolean = false;

/** Event emitted when the direction changes. */
@Output('dirChange') change = new EventEmitter<void>();
@Output('dirChange') change = new EventEmitter<Direction>();

/** @docs-private */
@Input('dir')
Expand All @@ -43,7 +43,7 @@ export class Dir implements Directionality {
let old = this._dir;
this._dir = v;
if (old !== this._dir && this._isInitialized) {
this.change.emit();
this.change.emit(this._dir);
}
}

Expand Down
12 changes: 8 additions & 4 deletions src/cdk/bidi/directionality.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {async, fakeAsync, TestBed, tick} from '@angular/core/testing';
import {async, fakeAsync, TestBed} from '@angular/core/testing';
import {Component} from '@angular/core';
import {By} from '@angular/platform-browser';
import {BidiModule, Directionality, DIR_DOCUMENT} from './index';
import {BidiModule, Directionality, Direction, DIR_DOCUMENT} from './index';

describe('Directionality', () => {
let fakeDocument: FakeDocument;
Expand Down Expand Up @@ -62,14 +62,18 @@ describe('Directionality', () => {

fixture.detectChanges();

let direction = injectedDirectionality.value;
injectedDirectionality.change.subscribe((dir: Direction) => { direction = dir; });

expect(direction).toBe('rtl');
expect(injectedDirectionality.value).toBe('rtl');
expect(fixture.componentInstance.changeCount).toBe(0);

fixture.componentInstance.direction = 'ltr';

fixture.detectChanges();
tick();

expect(direction).toBe('ltr');
expect(injectedDirectionality.value).toBe('ltr');
expect(fixture.componentInstance.changeCount).toBe(1);
}));
Expand All @@ -79,7 +83,7 @@ describe('Directionality', () => {

@Component({
template: `
<div [dir]="direction" (dirChange)="changeCount= changeCount + 1">
<div [dir]="direction" (dirChange)="changeCount = changeCount + 1">
<injects-directionality></injects-directionality>
</div>
`
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/bidi/directionality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class Directionality {
readonly value: Direction = 'ltr';

/** Stream that emits whenever the 'ltr' / 'rtl' state changes. */
readonly change = new EventEmitter<void>();
readonly change = new EventEmitter<Direction>();

constructor(@Optional() @Inject(DIR_DOCUMENT) _document?: any) {
if (_document) {
Expand Down

0 comments on commit b76cc96

Please sign in to comment.