@@ -29,6 +29,7 @@ import {MatDatepickerInput} from './datepicker-input';
29
29
import { MatDatepickerToggle } from './datepicker-toggle' ;
30
30
import { MAT_DATEPICKER_SCROLL_STRATEGY , MatDatepickerIntl , MatDatepickerModule } from './index' ;
31
31
import { Subject } from 'rxjs' ;
32
+ import { Directionality } from '@angular/cdk/bidi' ;
32
33
33
34
describe ( 'MatDatepicker' , ( ) => {
34
35
const SUPPORTS_INTL = typeof Intl != 'undefined' ;
@@ -1268,6 +1269,68 @@ describe('MatDatepicker', () => {
1268
1269
} ) ) ;
1269
1270
} ) ;
1270
1271
1272
+ describe ( 'datepicker directionality' , ( ) => {
1273
+ it ( 'should pass along the directionality to the popup' , ( ) => {
1274
+ const fixture = createComponent ( StandardDatepicker , [ MatNativeDateModule ] , [ {
1275
+ provide : Directionality ,
1276
+ useValue : ( { value : 'rtl' } )
1277
+ } ] ) ;
1278
+
1279
+ fixture . detectChanges ( ) ;
1280
+ fixture . componentInstance . datepicker . open ( ) ;
1281
+ fixture . detectChanges ( ) ;
1282
+
1283
+ const overlay = document . querySelector ( '.cdk-overlay-pane' ) ! ;
1284
+
1285
+ expect ( overlay . getAttribute ( 'dir' ) ) . toBe ( 'rtl' ) ;
1286
+ } ) ;
1287
+
1288
+ it ( 'should update the popup direction if the directionality value changes' , fakeAsync ( ( ) => {
1289
+ const dirProvider = { value : 'ltr' } ;
1290
+ const fixture = createComponent ( StandardDatepicker , [ MatNativeDateModule ] , [ {
1291
+ provide : Directionality ,
1292
+ useFactory : ( ) => dirProvider
1293
+ } ] ) ;
1294
+
1295
+ fixture . detectChanges ( ) ;
1296
+ fixture . componentInstance . datepicker . open ( ) ;
1297
+ fixture . detectChanges ( ) ;
1298
+
1299
+ let overlay = document . querySelector ( '.cdk-overlay-pane' ) ! ;
1300
+
1301
+ expect ( overlay . getAttribute ( 'dir' ) ) . toBe ( 'ltr' ) ;
1302
+
1303
+ fixture . componentInstance . datepicker . close ( ) ;
1304
+ fixture . detectChanges ( ) ;
1305
+ flush ( ) ;
1306
+
1307
+ dirProvider . value = 'rtl' ;
1308
+ fixture . componentInstance . datepicker . open ( ) ;
1309
+ fixture . detectChanges ( ) ;
1310
+
1311
+ overlay = document . querySelector ( '.cdk-overlay-pane' ) ! ;
1312
+
1313
+ expect ( overlay . getAttribute ( 'dir' ) ) . toBe ( 'rtl' ) ;
1314
+ } ) ) ;
1315
+
1316
+ it ( 'should pass along the directionality to the dialog in touch mode' , ( ) => {
1317
+ const fixture = createComponent ( StandardDatepicker , [ MatNativeDateModule ] , [ {
1318
+ provide : Directionality ,
1319
+ useValue : ( { value : 'rtl' } )
1320
+ } ] ) ;
1321
+
1322
+ fixture . componentInstance . touch = true ;
1323
+ fixture . detectChanges ( ) ;
1324
+ fixture . componentInstance . datepicker . open ( ) ;
1325
+ fixture . detectChanges ( ) ;
1326
+
1327
+ const overlay = document . querySelector ( '.cdk-overlay-pane' ) ! ;
1328
+
1329
+ expect ( overlay . getAttribute ( 'dir' ) ) . toBe ( 'rtl' ) ;
1330
+ } ) ;
1331
+
1332
+ } ) ;
1333
+
1271
1334
} ) ;
1272
1335
1273
1336
describe ( 'with missing DateAdapter and MAT_DATE_FORMATS' , ( ) => {
0 commit comments