5
5
*/
6
6
import { DisabledMixin } from '@vaadin/a11y-base/src/disabled-mixin.js' ;
7
7
import { FocusMixin } from '@vaadin/a11y-base/src/focus-mixin.js' ;
8
+ import { I18nMixin } from '@vaadin/component-base/src/i18n-mixin.js' ;
8
9
import { SlotController } from '@vaadin/component-base/src/slot-controller.js' ;
9
10
import { TooltipController } from '@vaadin/component-base/src/tooltip-controller.js' ;
10
11
import {
@@ -21,6 +22,8 @@ import { timePickerI18nDefaults } from '@vaadin/time-picker/src/vaadin-time-pick
21
22
const datePickerI18nProps = Object . keys ( datePickerI18nDefaults ) ;
22
23
const timePickerI18nProps = Object . keys ( timePickerI18nDefaults ) ;
23
24
25
+ const DEFAULT_I18N = { ...datePickerI18nDefaults , ...timePickerI18nDefaults } ;
26
+
24
27
/**
25
28
* A controller to initialize slotted picker.
26
29
*
@@ -46,7 +49,7 @@ class PickerSlotController extends SlotController {
46
49
* @mixes FocusMixin
47
50
*/
48
51
export const DateTimePickerMixin = ( superClass ) =>
49
- class DateTimePickerMixinClass extends FieldMixin ( FocusMixin ( DisabledMixin ( superClass ) ) ) {
52
+ class DateTimePickerMixinClass extends I18nMixin ( DEFAULT_I18N , FieldMixin ( FocusMixin ( DisabledMixin ( superClass ) ) ) ) {
50
53
static get properties ( ) {
51
54
return {
52
55
/**
@@ -224,22 +227,6 @@ export const DateTimePickerMixin = (superClass) =>
224
227
sync : true ,
225
228
} ,
226
229
227
- /**
228
- * The object used to localize this component.
229
- * To change the default localization, replace the entire
230
- * `i18n` object or just the properties you want to modify.
231
- *
232
- * The object is a combination of the i18n properties supported by
233
- * [`<vaadin-date-picker>`](#/elements/vaadin-date-picker) and
234
- * [`<vaadin-time-picker>`](#/elements/vaadin-time-picker).
235
- * @type {!DateTimePickerI18n }
236
- */
237
- i18n : {
238
- type : Object ,
239
- sync : true ,
240
- value : ( ) => ( { ...datePickerI18nDefaults , ...timePickerI18nDefaults } ) ,
241
- } ,
242
-
243
230
/**
244
231
* The current slotted date picker.
245
232
* @private
@@ -274,11 +261,11 @@ export const DateTimePickerMixin = (superClass) =>
274
261
'__invalidChanged(invalid, __datePicker, __timePicker)' ,
275
262
'__disabledChanged(disabled, __datePicker, __timePicker)' ,
276
263
'__readonlyChanged(readonly, __datePicker, __timePicker)' ,
277
- '__i18nChanged(i18n , __datePicker, __timePicker)' ,
264
+ '__i18nChanged(__effectiveI18n , __datePicker, __timePicker)' ,
278
265
'__autoOpenDisabledChanged(autoOpenDisabled, __datePicker, __timePicker)' ,
279
266
'__themeChanged(_theme, __datePicker, __timePicker)' ,
280
267
'__pickersChanged(__datePicker, __timePicker)' ,
281
- '__labelOrAccessibleNameChanged(label, accessibleName, i18n , __datePicker, __timePicker)' ,
268
+ '__labelOrAccessibleNameChanged(label, accessibleName, __effectiveI18n , __datePicker, __timePicker)' ,
282
269
] ;
283
270
}
284
271
@@ -297,6 +284,43 @@ export const DateTimePickerMixin = (superClass) =>
297
284
this . __openedChangedEventHandler = this . __openedChangedEventHandler . bind ( this ) ;
298
285
}
299
286
287
+ /**
288
+ * The object used to localize this component. To change the default
289
+ * localization, replace this with an object that provides all properties, or
290
+ * just the individual properties you want to change.
291
+ *
292
+ * The object has the following structure and default values:
293
+ *
294
+ * ```
295
+ * {
296
+ * // Accessible label to the date picker.
297
+ * // The property works in conjunction with label and accessibleName defined on the field.
298
+ * // If both properties are defined, then accessibleName takes precedence.
299
+ * // Then, the dateLabel value is concatenated with it.
300
+ * dateLabel: undefined;
301
+ *
302
+ * // Accessible label to the time picker.
303
+ * // The property works in conjunction with label and accessibleName defined on the field.
304
+ * // If both properties are defined, then accessibleName takes precedence.
305
+ * // Then, the dateLabel value is concatenated with it.
306
+ * timeLabel: undefined;
307
+ * }
308
+ * ```
309
+ *
310
+ * Additionally, all i18n properties from
311
+ * [`<vaadin-date-picker>`](#/elements/vaadin-date-picker) and
312
+ * [`<vaadin-time-picker>`](#/elements/vaadin-time-picker) are supported.
313
+ *
314
+ * @type {!DateTimePickerI18n }
315
+ */
316
+ get i18n ( ) {
317
+ return super . i18n ;
318
+ }
319
+
320
+ set i18n ( value ) {
321
+ super . i18n = value ;
322
+ }
323
+
300
324
/** @private */
301
325
get __pickers ( ) {
302
326
return [ this . __datePicker , this . __timePicker ] ;
@@ -448,15 +472,15 @@ export const DateTimePickerMixin = (superClass) =>
448
472
}
449
473
450
474
/** @private */
451
- __syncI18n ( target , source , props = Object . keys ( source . i18n ) ) {
452
- const i18n = { ... target . i18n } ;
475
+ __syncI18n ( target , i18n , props ) {
476
+ const targetI18n = { } ;
453
477
props . forEach ( ( prop ) => {
454
478
// eslint-disable-next-line no-prototype-builtins
455
- if ( source . i18n && source . i18n . hasOwnProperty ( prop ) ) {
456
- i18n [ prop ] = source . i18n [ prop ] ;
479
+ if ( i18n && i18n . hasOwnProperty ( prop ) ) {
480
+ targetI18n [ prop ] = i18n [ prop ] ;
457
481
}
458
482
} ) ;
459
- target . i18n = i18n ;
483
+ target . i18n = targetI18n ;
460
484
}
461
485
462
486
/** @private */
@@ -528,7 +552,6 @@ export const DateTimePickerMixin = (superClass) =>
528
552
this . datePlaceholder = newDatePicker . placeholder ;
529
553
this . initialPosition = newDatePicker . initialPosition ;
530
554
this . showWeekNumbers = newDatePicker . showWeekNumbers ;
531
- this . __syncI18n ( this , newDatePicker , datePickerI18nProps ) ;
532
555
}
533
556
534
557
// Min and max are always synchronized from date time picker (host) to inner fields because time picker
@@ -557,7 +580,6 @@ export const DateTimePickerMixin = (superClass) =>
557
580
// Synchronize properties from slotted time picker
558
581
this . timePlaceholder = newTimePicker . placeholder ;
559
582
this . step = newTimePicker . step ;
560
- this . __syncI18n ( this , newTimePicker , timePickerI18nProps ) ;
561
583
}
562
584
563
585
// Min and max are always synchronized from parent to slotted because time picker min and max
@@ -589,26 +611,27 @@ export const DateTimePickerMixin = (superClass) =>
589
611
}
590
612
591
613
/** @private */
592
- __i18nChanged ( _i18n , datePicker , timePicker ) {
593
- if ( datePicker ) {
594
- this . __syncI18n ( datePicker , this , datePickerI18nProps ) ;
614
+ __i18nChanged ( effectiveI18n , datePicker , timePicker ) {
615
+ // Only propagate i18n to default pickers
616
+ if ( datePicker && this . __isDefaultPicker ( datePicker , 'date' ) ) {
617
+ this . __syncI18n ( datePicker , effectiveI18n , datePickerI18nProps ) ;
595
618
}
596
619
597
- if ( timePicker ) {
598
- this . __syncI18n ( timePicker , this , timePickerI18nProps ) ;
620
+ if ( timePicker && this . __isDefaultPicker ( timePicker , 'time' ) ) {
621
+ this . __syncI18n ( timePicker , effectiveI18n , timePickerI18nProps ) ;
599
622
}
600
623
}
601
624
602
625
/** @private */
603
- __labelOrAccessibleNameChanged ( label , accessibleName , i18n , datePicker , timePicker ) {
626
+ __labelOrAccessibleNameChanged ( label , accessibleName , effectiveI18n , datePicker , timePicker ) {
604
627
const name = accessibleName || label || '' ;
605
628
606
629
if ( datePicker ) {
607
- datePicker . accessibleName = `${ name } ${ i18n . dateLabel || '' } ` . trim ( ) ;
630
+ datePicker . accessibleName = `${ name } ${ effectiveI18n . dateLabel || '' } ` . trim ( ) ;
608
631
}
609
632
610
633
if ( timePicker ) {
611
- timePicker . accessibleName = `${ name } ${ i18n . timeLabel || '' } ` . trim ( ) ;
634
+ timePicker . accessibleName = `${ name } ${ effectiveI18n . timeLabel || '' } ` . trim ( ) ;
612
635
}
613
636
}
614
637
0 commit comments