Skip to content

Commit 841f753

Browse files
EladBezaleltinayuangao
authored andcommitted
fix(directionality): change event now emit the new value (#8424)
1 parent 0f7fbda commit 841f753

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/cdk/bidi/dir.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class Dir implements Directionality {
3434
private _isInitialized: boolean = false;
3535

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

3939
/** @docs-private */
4040
@Input('dir')
@@ -43,7 +43,7 @@ export class Dir implements Directionality {
4343
let old = this._dir;
4444
this._dir = v;
4545
if (old !== this._dir && this._isInitialized) {
46-
this.change.emit();
46+
this.change.emit(this._dir);
4747
}
4848
}
4949

src/cdk/bidi/directionality.spec.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {async, fakeAsync, TestBed, tick} from '@angular/core/testing';
1+
import {async, fakeAsync, TestBed} from '@angular/core/testing';
22
import {Component} from '@angular/core';
33
import {By} from '@angular/platform-browser';
4-
import {BidiModule, Directionality, DIR_DOCUMENT} from './index';
4+
import {BidiModule, Directionality, Direction, DIR_DOCUMENT} from './index';
55

66
describe('Directionality', () => {
77
let fakeDocument: FakeDocument;
@@ -62,14 +62,18 @@ describe('Directionality', () => {
6262

6363
fixture.detectChanges();
6464

65+
let direction = injectedDirectionality.value;
66+
injectedDirectionality.change.subscribe((dir: Direction) => { direction = dir; });
67+
68+
expect(direction).toBe('rtl');
6569
expect(injectedDirectionality.value).toBe('rtl');
6670
expect(fixture.componentInstance.changeCount).toBe(0);
6771

6872
fixture.componentInstance.direction = 'ltr';
6973

7074
fixture.detectChanges();
71-
tick();
7275

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

8084
@Component({
8185
template: `
82-
<div [dir]="direction" (dirChange)="changeCount= changeCount + 1">
86+
<div [dir]="direction" (dirChange)="changeCount = changeCount + 1">
8387
<injects-directionality></injects-directionality>
8488
</div>
8589
`

src/cdk/bidi/directionality.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class Directionality {
3939
readonly value: Direction = 'ltr';
4040

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

4444
constructor(@Optional() @Inject(DIR_DOCUMENT) _document?: any) {
4545
if (_document) {

0 commit comments

Comments
 (0)