Skip to content

Commit f18f6fb

Browse files
committed
fix snackbar RTL
1 parent 012581f commit f18f6fb

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import {Direction, Directionality} from '@angular/cdk/bidi';
2+
import {EventEmitter, Injectable, OnDestroy} from '@angular/core';
3+
4+
@Injectable()
5+
export class DevAppDirectionality implements Directionality, OnDestroy {
6+
readonly change = new EventEmitter<Direction>();
7+
8+
get value(): Direction {
9+
return this._value;
10+
}
11+
set value(value: Direction) {
12+
this._value = value;
13+
this.change.next(value);
14+
}
15+
private _value: Direction = 'ltr';
16+
17+
ngOnDestroy() {
18+
this.change.complete();
19+
}
20+
}

src/dev-app/dev-app/dev-app-layout.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ <h1>Angular Material Demos</h1>
3737
<button mat-button (click)="rippleOptions.disabled = !rippleOptions.disabled">
3838
{{rippleOptions.disabled ? 'Enable' : 'Disable'}} ripples
3939
</button>
40-
<button mat-button (click)="root.dir = (root.dir === 'rtl' ? 'ltr' : 'rtl')"
40+
<button mat-button (click)="dir.value = (dir.value === 'rtl' ? 'ltr' : 'rtl')"
4141
title="Toggle between RTL and LTR">
42-
{{root.dir.toUpperCase()}}
42+
{{dir.value.toUpperCase()}}
4343
</button>
4444
</div>
4545
</div>
4646
</mat-toolbar>
4747

48-
<div #root="dir" dir="ltr" class="demo-content mat-app-background">
48+
<div [attr.dir]="dir.value" class="demo-content mat-app-background">
4949
<ng-content></ng-content>
5050
</div>
5151
</main>

src/dev-app/dev-app/dev-app-layout.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {Directionality} from '@angular/cdk/bidi';
910
import {OverlayContainer} from '@angular/cdk/overlay';
10-
import {Component, ElementRef, ViewEncapsulation} from '@angular/core';
11+
import {ChangeDetectorRef, Component, ElementRef, Inject, ViewEncapsulation} from '@angular/core';
1112
import {DevAppRippleOptions} from '../ripple/ripple-options';
13+
import {DevAppDirectionality} from './dev-app-directionality';
1214

1315
/** Root component for the dev-app demos. */
1416
@Component({
@@ -70,7 +72,10 @@ export class DevAppLayout {
7072

7173
constructor(
7274
private _element: ElementRef<HTMLElement>, private _overlayContainer: OverlayContainer,
73-
public rippleOptions: DevAppRippleOptions) {}
75+
public rippleOptions: DevAppRippleOptions,
76+
@Inject(Directionality) public dir: DevAppDirectionality, cdr: ChangeDetectorRef) {
77+
dir.change.subscribe(() => cdr.markForCheck());
78+
}
7479

7580
toggleFullscreen() {
7681
// Cast to `any`, because the typings don't include the browser-prefixed methods.

src/dev-app/main-module.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {Directionality} from '@angular/cdk/bidi';
910
import {FullscreenOverlayContainer, OverlayContainer} from '@angular/cdk/overlay';
1011
import {HttpClientModule} from '@angular/common/http';
1112
import {NgModule} from '@angular/core';
@@ -14,6 +15,7 @@ import {BrowserModule} from '@angular/platform-browser';
1415
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
1516
import {RouterModule} from '@angular/router';
1617
import {DevAppComponent} from './dev-app';
18+
import {DevAppDirectionality} from './dev-app/dev-app-directionality';
1719
import {DevAppModule} from './dev-app/dev-app-module';
1820
import {DEV_APP_ROUTES} from './dev-app/routes';
1921
import {DevAppRippleOptions} from './ripple/ripple-options';
@@ -32,6 +34,7 @@ import {DevAppRippleOptions} from './ripple/ripple-options';
3234
providers: [
3335
{provide: OverlayContainer, useClass: FullscreenOverlayContainer},
3436
{provide: MAT_RIPPLE_GLOBAL_OPTIONS, useExisting: DevAppRippleOptions},
37+
{provide: Directionality, useClass: DevAppDirectionality},
3538
],
3639
bootstrap: [DevAppComponent],
3740
})

src/dev-app/snack-bar/snack-bar-demo.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Dir} from '@angular/cdk/bidi';
9+
import {Directionality} from '@angular/cdk/bidi';
1010
import {Component, TemplateRef, ViewChild} from '@angular/core';
1111
import {
1212
MatSnackBar,
@@ -33,8 +33,7 @@ export class SnackBarDemo {
3333
horizontalPosition: MatSnackBarHorizontalPosition = 'center';
3434
verticalPosition: MatSnackBarVerticalPosition = 'bottom';
3535

36-
constructor(public snackBar: MatSnackBar, private dir: Dir) {
37-
}
36+
constructor(public snackBar: MatSnackBar, private dir: Directionality) {}
3837

3938
open() {
4039
const config = this._createConfig();

0 commit comments

Comments
 (0)