@@ -7,23 +7,34 @@ import { announce } from '@vaadin/a11y-base/src/announce.js';
7
7
import { ComboBoxDataProviderMixin } from '@vaadin/combo-box/src/vaadin-combo-box-data-provider-mixin.js' ;
8
8
import { ComboBoxItemsMixin } from '@vaadin/combo-box/src/vaadin-combo-box-items-mixin.js' ;
9
9
import { ComboBoxPlaceholder } from '@vaadin/combo-box/src/vaadin-combo-box-placeholder.js' ;
10
+ import { I18nMixin } from '@vaadin/component-base/src/i18n-mixin.js' ;
10
11
import { ResizeMixin } from '@vaadin/component-base/src/resize-mixin.js' ;
11
12
import { SlotController } from '@vaadin/component-base/src/slot-controller.js' ;
12
13
import { TooltipController } from '@vaadin/component-base/src/tooltip-controller.js' ;
13
14
import { InputControlMixin } from '@vaadin/field-base/src/input-control-mixin.js' ;
14
15
import { InputController } from '@vaadin/field-base/src/input-controller.js' ;
15
16
import { LabelledInputController } from '@vaadin/field-base/src/labelled-input-controller.js' ;
16
17
18
+ const DEFAULT_I18N = {
19
+ cleared : 'Selection cleared' ,
20
+ focused : 'focused. Press Backspace to remove' ,
21
+ selected : 'added to selection' ,
22
+ deselected : 'removed from selection' ,
23
+ total : '{count} items selected' ,
24
+ } ;
25
+
17
26
/**
18
27
* @polymerMixin
19
28
* @mixes ComboBoxDataProviderMixin
20
29
* @mixes ComboBoxItemsMixin
30
+ * @mixes I18nMixin
21
31
* @mixes InputControlMixin
22
32
* @mixes ResizeMixin
23
33
*/
24
34
export const MultiSelectComboBoxMixin = ( superClass ) =>
25
- class MultiSelectComboBoxMixinClass extends ComboBoxDataProviderMixin (
26
- ComboBoxItemsMixin ( InputControlMixin ( ResizeMixin ( superClass ) ) ) ,
35
+ class MultiSelectComboBoxMixinClass extends I18nMixin (
36
+ DEFAULT_I18N ,
37
+ ComboBoxDataProviderMixin ( ComboBoxItemsMixin ( InputControlMixin ( ResizeMixin ( superClass ) ) ) ) ,
27
38
) {
28
39
static get properties ( ) {
29
40
return {
@@ -72,43 +83,6 @@ export const MultiSelectComboBoxMixin = (superClass) =>
72
83
sync : true ,
73
84
} ,
74
85
75
- /**
76
- * The object used to localize this component.
77
- * To change the default localization, replace the entire
78
- * _i18n_ object or just the property you want to modify.
79
- *
80
- * The object has the following JSON structure and default values:
81
- * ```js
82
- * {
83
- * // Screen reader announcement on clear button click.
84
- * cleared: 'Selection cleared',
85
- * // Screen reader announcement when a chip is focused.
86
- * focused: ' focused. Press Backspace to remove',
87
- * // Screen reader announcement when item is selected.
88
- * selected: 'added to selection',
89
- * // Screen reader announcement when item is deselected.
90
- * deselected: 'removed from selection',
91
- * // Screen reader announcement of the selected items count.
92
- * // {count} is replaced with the actual count of items.
93
- * total: '{count} items selected',
94
- * }
95
- * ```
96
- * @type {!MultiSelectComboBoxI18n }
97
- * @default {English/US}
98
- */
99
- i18n : {
100
- type : Object ,
101
- value : ( ) => {
102
- return {
103
- cleared : 'Selection cleared' ,
104
- focused : 'focused. Press Backspace to remove' ,
105
- selected : 'added to selection' ,
106
- deselected : 'removed from selection' ,
107
- total : '{count} items selected' ,
108
- } ;
109
- } ,
110
- } ,
111
-
112
86
/**
113
87
* When true, filter string isn't cleared after selecting an item.
114
88
*/
@@ -244,6 +218,37 @@ export const MultiSelectComboBoxMixin = (superClass) =>
244
218
] ;
245
219
}
246
220
221
+ /**
222
+ * The object used to localize this component. To change the default
223
+ * localization, replace this with an object that provides all properties, or
224
+ * just the individual properties you want to change.
225
+ *
226
+ * The object has the following JSON structure and default values:
227
+ * ```js
228
+ * {
229
+ * // Screen reader announcement on clear button click.
230
+ * cleared: 'Selection cleared',
231
+ * // Screen reader announcement when a chip is focused.
232
+ * focused: ' focused. Press Backspace to remove',
233
+ * // Screen reader announcement when item is selected.
234
+ * selected: 'added to selection',
235
+ * // Screen reader announcement when item is deselected.
236
+ * deselected: 'removed from selection',
237
+ * // Screen reader announcement of the selected items count.
238
+ * // {count} is replaced with the actual count of items.
239
+ * total: '{count} items selected',
240
+ * }
241
+ * ```
242
+ * @return {!MultiSelectComboBoxI18n }
243
+ */
244
+ get i18n ( ) {
245
+ return super . i18n ;
246
+ }
247
+
248
+ set i18n ( value ) {
249
+ super . i18n = value ;
250
+ }
251
+
247
252
/** @protected */
248
253
get slotStyles ( ) {
249
254
const tag = this . localName ;
@@ -384,7 +389,7 @@ export const MultiSelectComboBoxMixin = (superClass) =>
384
389
clear ( ) {
385
390
this . __updateSelection ( [ ] ) ;
386
391
387
- announce ( this . i18n . cleared ) ;
392
+ announce ( this . __effectiveI18n . cleared ) ;
388
393
}
389
394
390
395
/**
@@ -750,8 +755,8 @@ export const MultiSelectComboBoxMixin = (superClass) =>
750
755
/** @private */
751
756
__announceItem ( itemLabel , isSelected , itemCount ) {
752
757
const state = isSelected ? 'selected' : 'deselected' ;
753
- const total = this . i18n . total . replace ( '{count}' , itemCount || 0 ) ;
754
- announce ( `${ itemLabel } ${ this . i18n [ state ] } ${ total } ` ) ;
758
+ const total = this . __effectiveI18n . total . replace ( '{count}' , itemCount || 0 ) ;
759
+ announce ( `${ itemLabel } ${ this . __effectiveI18n [ state ] } ${ total } ` ) ;
755
760
}
756
761
757
762
/** @private */
@@ -1218,7 +1223,7 @@ export const MultiSelectComboBoxMixin = (superClass) =>
1218
1223
if ( focusedIndex > - 1 ) {
1219
1224
const item = chips [ focusedIndex ] . item ;
1220
1225
const itemLabel = this . _getItemLabel ( item ) ;
1221
- announce ( `${ itemLabel } ${ this . i18n . focused } ` ) ;
1226
+ announce ( `${ itemLabel } ${ this . __effectiveI18n . focused } ` ) ;
1222
1227
}
1223
1228
}
1224
1229
}
0 commit comments