@@ -7,23 +7,34 @@ import { announce } from '@vaadin/a11y-base/src/announce.js';
77import { ComboBoxDataProviderMixin } from '@vaadin/combo-box/src/vaadin-combo-box-data-provider-mixin.js' ;
88import { ComboBoxItemsMixin } from '@vaadin/combo-box/src/vaadin-combo-box-items-mixin.js' ;
99import { ComboBoxPlaceholder } from '@vaadin/combo-box/src/vaadin-combo-box-placeholder.js' ;
10+ import { I18nMixin } from '@vaadin/component-base/src/i18n-mixin.js' ;
1011import { ResizeMixin } from '@vaadin/component-base/src/resize-mixin.js' ;
1112import { SlotController } from '@vaadin/component-base/src/slot-controller.js' ;
1213import { TooltipController } from '@vaadin/component-base/src/tooltip-controller.js' ;
1314import { InputControlMixin } from '@vaadin/field-base/src/input-control-mixin.js' ;
1415import { InputController } from '@vaadin/field-base/src/input-controller.js' ;
1516import { LabelledInputController } from '@vaadin/field-base/src/labelled-input-controller.js' ;
1617
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+
1726/**
1827 * @polymerMixin
1928 * @mixes ComboBoxDataProviderMixin
2029 * @mixes ComboBoxItemsMixin
30+ * @mixes I18nMixin
2131 * @mixes InputControlMixin
2232 * @mixes ResizeMixin
2333 */
2434export 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 ) ) ) ) ,
2738 ) {
2839 static get properties ( ) {
2940 return {
@@ -72,43 +83,6 @@ export const MultiSelectComboBoxMixin = (superClass) =>
7283 sync : true ,
7384 } ,
7485
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-
11286 /**
11387 * When true, filter string isn't cleared after selecting an item.
11488 */
@@ -244,6 +218,37 @@ export const MultiSelectComboBoxMixin = (superClass) =>
244218 ] ;
245219 }
246220
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+
247252 /** @protected */
248253 get slotStyles ( ) {
249254 const tag = this . localName ;
@@ -384,7 +389,7 @@ export const MultiSelectComboBoxMixin = (superClass) =>
384389 clear ( ) {
385390 this . __updateSelection ( [ ] ) ;
386391
387- announce ( this . i18n . cleared ) ;
392+ announce ( this . __effectiveI18n . cleared ) ;
388393 }
389394
390395 /**
@@ -750,8 +755,8 @@ export const MultiSelectComboBoxMixin = (superClass) =>
750755 /** @private */
751756 __announceItem ( itemLabel , isSelected , itemCount ) {
752757 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 } ` ) ;
755760 }
756761
757762 /** @private */
@@ -1218,7 +1223,7 @@ export const MultiSelectComboBoxMixin = (superClass) =>
12181223 if ( focusedIndex > - 1 ) {
12191224 const item = chips [ focusedIndex ] . item ;
12201225 const itemLabel = this . _getItemLabel ( item ) ;
1221- announce ( `${ itemLabel } ${ this . i18n . focused } ` ) ;
1226+ announce ( `${ itemLabel } ${ this . __effectiveI18n . focused } ` ) ;
12221227 }
12231228 }
12241229 }
0 commit comments