@progress/kendo-react-dropdowns 6.1.1 → 7.0.0-develop.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/{dist/es/AutoComplete → AutoComplete}/AutoComplete.d.ts +12 -8
  2. package/{dist/npm/AutoComplete → AutoComplete}/AutoCompleteProps.d.ts +4 -1
  3. package/{dist/es/ComboBox → ComboBox}/ComboBox.d.ts +12 -8
  4. package/{dist/es/ComboBox → ComboBox}/ComboBoxProps.d.ts +4 -1
  5. package/{dist/es/DropDownList → DropDownList}/DropDownList.d.ts +9 -5
  6. package/{dist/es/DropDownList → DropDownList}/DropDownListProps.d.ts +4 -1
  7. package/{dist/es/DropDownTree → DropDownTree}/DropDownTree.d.ts +4 -0
  8. package/{dist/npm/DropDownTree → DropDownTree}/DropDownTreeProps.d.ts +4 -1
  9. package/DropDownTree/ListNoData.d.ts +10 -0
  10. package/DropDownTree/useDropdownWidth.d.ts +9 -0
  11. package/LICENSE.md +1 -1
  12. package/{dist/es/MultiColumnComboBox → MultiColumnComboBox}/MultiColumnComboBox.d.ts +4 -0
  13. package/{dist/npm/MultiSelect → MultiSelect}/MultiSelect.d.ts +9 -5
  14. package/{dist/es/MultiSelect → MultiSelect}/MultiSelectProps.d.ts +4 -1
  15. package/{dist/npm/MultiSelect → MultiSelect}/TagList.d.ts +5 -1
  16. package/{dist/es/MultiSelectTree → MultiSelectTree}/MultiSelectTree.d.ts +4 -0
  17. package/{dist/es/MultiSelectTree → MultiSelectTree}/MultiSelectTreeProps.d.ts +5 -1
  18. package/{dist/npm/MultiSelectTree → MultiSelectTree}/utils.d.ts +5 -1
  19. package/{dist/npm/common → common}/AdaptiveMode.d.ts +5 -1
  20. package/common/ClearButton.d.ts +18 -0
  21. package/{dist/npm/common → common}/DropDownBase.d.ts +5 -1
  22. package/{dist/es/common → common}/GroupStickyHeader.d.ts +5 -1
  23. package/{dist/es/common → common}/List.d.ts +8 -3
  24. package/common/ListContainer.d.ts +22 -0
  25. package/common/ListDefaultItem.d.ts +20 -0
  26. package/{dist/npm/common → common}/ListFilter.d.ts +4 -0
  27. package/{dist/npm/common → common}/ListGroupItem.d.ts +5 -1
  28. package/{dist/npm/common → common}/ListItem.d.ts +5 -1
  29. package/common/MultiColumnList.d.ts +9 -0
  30. package/common/Navigation.d.ts +17 -0
  31. package/{dist/es/common → common}/SearchBar.d.ts +5 -1
  32. package/{dist/npm/common → common}/VirtualScroll.d.ts +4 -1
  33. package/common/constants.d.ts +8 -0
  34. package/{dist/es/common → common}/events.d.ts +4 -1
  35. package/{dist/npm/common → common}/filterDescriptor.d.ts +4 -0
  36. package/{dist/es/common → common}/settings.d.ts +5 -2
  37. package/{dist/npm/common → common}/utils.d.ts +4 -0
  38. package/dist/cdn/js/kendo-react-dropdowns.js +5 -1
  39. package/index.d.ts +29 -0
  40. package/index.js +5 -0
  41. package/index.mjs +4397 -0
  42. package/{dist/npm/messages → messages}/index.d.ts +4 -0
  43. package/package-metadata.d.ts +9 -0
  44. package/package.json +34 -62
  45. package/about.md +0 -3
  46. package/dist/es/AutoComplete/AutoComplete.js +0 -652
  47. package/dist/es/AutoComplete/AutoCompleteProps.d.ts +0 -243
  48. package/dist/es/AutoComplete/AutoCompleteProps.js +0 -2
  49. package/dist/es/ComboBox/ComboBox.js +0 -915
  50. package/dist/es/ComboBox/ComboBoxProps.js +0 -2
  51. package/dist/es/DropDownList/DropDownList.js +0 -887
  52. package/dist/es/DropDownList/DropDownListProps.js +0 -2
  53. package/dist/es/DropDownTree/DropDownTree.js +0 -540
  54. package/dist/es/DropDownTree/DropDownTreeProps.d.ts +0 -294
  55. package/dist/es/DropDownTree/DropDownTreeProps.js +0 -2
  56. package/dist/es/DropDownTree/ListNoData.d.ts +0 -6
  57. package/dist/es/DropDownTree/ListNoData.js +0 -8
  58. package/dist/es/DropDownTree/useDropdownWidth.d.ts +0 -5
  59. package/dist/es/DropDownTree/useDropdownWidth.js +0 -13
  60. package/dist/es/MultiColumnComboBox/MultiColumnComboBox.js +0 -213
  61. package/dist/es/MultiSelect/MultiSelect.d.ts +0 -256
  62. package/dist/es/MultiSelect/MultiSelect.js +0 -1110
  63. package/dist/es/MultiSelect/MultiSelectProps.js +0 -2
  64. package/dist/es/MultiSelect/TagList.d.ts +0 -38
  65. package/dist/es/MultiSelect/TagList.js +0 -39
  66. package/dist/es/MultiSelectTree/MultiSelectTree.js +0 -619
  67. package/dist/es/MultiSelectTree/MultiSelectTreeProps.js +0 -2
  68. package/dist/es/MultiSelectTree/utils.d.ts +0 -17
  69. package/dist/es/MultiSelectTree/utils.js +0 -191
  70. package/dist/es/common/AdaptiveMode.d.ts +0 -21
  71. package/dist/es/common/AdaptiveMode.js +0 -45
  72. package/dist/es/common/ClearButton.d.ts +0 -14
  73. package/dist/es/common/ClearButton.js +0 -39
  74. package/dist/es/common/DropDownBase.d.ts +0 -175
  75. package/dist/es/common/DropDownBase.js +0 -297
  76. package/dist/es/common/GroupStickyHeader.js +0 -34
  77. package/dist/es/common/List.js +0 -75
  78. package/dist/es/common/ListContainer.d.ts +0 -18
  79. package/dist/es/common/ListContainer.js +0 -43
  80. package/dist/es/common/ListDefaultItem.d.ts +0 -16
  81. package/dist/es/common/ListDefaultItem.js +0 -36
  82. package/dist/es/common/ListFilter.d.ts +0 -19
  83. package/dist/es/common/ListFilter.js +0 -37
  84. package/dist/es/common/ListGroupItem.d.ts +0 -33
  85. package/dist/es/common/ListGroupItem.js +0 -33
  86. package/dist/es/common/ListItem.d.ts +0 -61
  87. package/dist/es/common/ListItem.js +0 -44
  88. package/dist/es/common/MultiColumnList.d.ts +0 -6
  89. package/dist/es/common/MultiColumnList.js +0 -22
  90. package/dist/es/common/Navigation.d.ts +0 -13
  91. package/dist/es/common/Navigation.js +0 -34
  92. package/dist/es/common/SearchBar.js +0 -62
  93. package/dist/es/common/VirtualScroll.d.ts +0 -42
  94. package/dist/es/common/VirtualScroll.js +0 -161
  95. package/dist/es/common/constants.d.ts +0 -4
  96. package/dist/es/common/constants.js +0 -4
  97. package/dist/es/common/events.js +0 -1
  98. package/dist/es/common/filterDescriptor.d.ts +0 -41
  99. package/dist/es/common/filterDescriptor.js +0 -2
  100. package/dist/es/common/settings.js +0 -8
  101. package/dist/es/common/utils.d.ts +0 -62
  102. package/dist/es/common/utils.js +0 -194
  103. package/dist/es/main.d.ts +0 -25
  104. package/dist/es/main.js +0 -19
  105. package/dist/es/messages/index.d.ts +0 -40
  106. package/dist/es/messages/index.js +0 -41
  107. package/dist/es/package-metadata.d.ts +0 -5
  108. package/dist/es/package-metadata.js +0 -11
  109. package/dist/npm/AutoComplete/AutoComplete.d.ts +0 -230
  110. package/dist/npm/AutoComplete/AutoComplete.js +0 -655
  111. package/dist/npm/AutoComplete/AutoCompleteProps.js +0 -3
  112. package/dist/npm/ComboBox/ComboBox.d.ts +0 -248
  113. package/dist/npm/ComboBox/ComboBox.js +0 -918
  114. package/dist/npm/ComboBox/ComboBoxProps.d.ts +0 -313
  115. package/dist/npm/ComboBox/ComboBoxProps.js +0 -3
  116. package/dist/npm/DropDownList/DropDownList.d.ts +0 -258
  117. package/dist/npm/DropDownList/DropDownList.js +0 -890
  118. package/dist/npm/DropDownList/DropDownListProps.d.ts +0 -326
  119. package/dist/npm/DropDownList/DropDownListProps.js +0 -3
  120. package/dist/npm/DropDownTree/DropDownTree.d.ts +0 -70
  121. package/dist/npm/DropDownTree/DropDownTree.js +0 -543
  122. package/dist/npm/DropDownTree/DropDownTreeProps.js +0 -3
  123. package/dist/npm/DropDownTree/ListNoData.d.ts +0 -6
  124. package/dist/npm/DropDownTree/ListNoData.js +0 -12
  125. package/dist/npm/DropDownTree/useDropdownWidth.d.ts +0 -5
  126. package/dist/npm/DropDownTree/useDropdownWidth.js +0 -17
  127. package/dist/npm/MultiColumnComboBox/MultiColumnComboBox.d.ts +0 -287
  128. package/dist/npm/MultiColumnComboBox/MultiColumnComboBox.js +0 -216
  129. package/dist/npm/MultiSelect/MultiSelect.js +0 -1113
  130. package/dist/npm/MultiSelect/MultiSelectProps.d.ts +0 -314
  131. package/dist/npm/MultiSelect/MultiSelectProps.js +0 -3
  132. package/dist/npm/MultiSelect/TagList.js +0 -41
  133. package/dist/npm/MultiSelectTree/MultiSelectTree.d.ts +0 -81
  134. package/dist/npm/MultiSelectTree/MultiSelectTree.js +0 -622
  135. package/dist/npm/MultiSelectTree/MultiSelectTreeProps.d.ts +0 -320
  136. package/dist/npm/MultiSelectTree/MultiSelectTreeProps.js +0 -3
  137. package/dist/npm/MultiSelectTree/utils.js +0 -196
  138. package/dist/npm/common/AdaptiveMode.js +0 -49
  139. package/dist/npm/common/ClearButton.d.ts +0 -14
  140. package/dist/npm/common/ClearButton.js +0 -41
  141. package/dist/npm/common/DropDownBase.js +0 -299
  142. package/dist/npm/common/GroupStickyHeader.d.ts +0 -24
  143. package/dist/npm/common/GroupStickyHeader.js +0 -36
  144. package/dist/npm/common/List.d.ts +0 -45
  145. package/dist/npm/common/List.js +0 -77
  146. package/dist/npm/common/ListContainer.d.ts +0 -18
  147. package/dist/npm/common/ListContainer.js +0 -45
  148. package/dist/npm/common/ListDefaultItem.d.ts +0 -16
  149. package/dist/npm/common/ListDefaultItem.js +0 -38
  150. package/dist/npm/common/ListFilter.js +0 -39
  151. package/dist/npm/common/ListGroupItem.js +0 -35
  152. package/dist/npm/common/ListItem.js +0 -46
  153. package/dist/npm/common/MultiColumnList.d.ts +0 -6
  154. package/dist/npm/common/MultiColumnList.js +0 -26
  155. package/dist/npm/common/Navigation.d.ts +0 -13
  156. package/dist/npm/common/Navigation.js +0 -37
  157. package/dist/npm/common/SearchBar.d.ts +0 -43
  158. package/dist/npm/common/SearchBar.js +0 -64
  159. package/dist/npm/common/VirtualScroll.js +0 -163
  160. package/dist/npm/common/constants.d.ts +0 -4
  161. package/dist/npm/common/constants.js +0 -7
  162. package/dist/npm/common/events.d.ts +0 -73
  163. package/dist/npm/common/events.js +0 -2
  164. package/dist/npm/common/filterDescriptor.js +0 -3
  165. package/dist/npm/common/settings.d.ts +0 -114
  166. package/dist/npm/common/settings.js +0 -11
  167. package/dist/npm/common/utils.js +0 -211
  168. package/dist/npm/main.d.ts +0 -25
  169. package/dist/npm/main.js +0 -62
  170. package/dist/npm/messages/index.js +0 -44
  171. package/dist/npm/package-metadata.d.ts +0 -5
  172. package/dist/npm/package-metadata.js +0 -14
  173. package/dist/systemjs/kendo-react-dropdowns.js +0 -1
  174. package/e2e-next/combobox.basic.ts +0 -24
  175. package/e2e-next/dropdownlist.basic.tests.ts +0 -24
  176. package/e2e-next/dropdowntree.basic.tests.ts +0 -24
  177. package/e2e-next/multicolumncombobox.basic.tests.ts +0 -24
@@ -1,1110 +0,0 @@
1
- var __extends = (this && this.__extends) || (function () {
2
- var extendStatics = function (d, b) {
3
- extendStatics = Object.setPrototypeOf ||
4
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
- return extendStatics(d, b);
7
- };
8
- return function (d, b) {
9
- if (typeof b !== "function" && b !== null)
10
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
- extendStatics(d, b);
12
- function __() { this.constructor = d; }
13
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
- };
15
- })();
16
- var __assign = (this && this.__assign) || function () {
17
- __assign = Object.assign || function(t) {
18
- for (var s, i = 1, n = arguments.length; i < n; i++) {
19
- s = arguments[i];
20
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
21
- t[p] = s[p];
22
- }
23
- return t;
24
- };
25
- return __assign.apply(this, arguments);
26
- };
27
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
28
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
29
- if (ar || !(i in from)) {
30
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
31
- ar[i] = from[i];
32
- }
33
- }
34
- return to.concat(ar || Array.prototype.slice.call(from));
35
- };
36
- import * as React from 'react';
37
- import * as PropTypes from 'prop-types';
38
- import { classNames, Keys, guid, createPropsContext, kendoThemeMaps, withPropsContext, IconWrap, canUseDOM } from '@progress/kendo-react-common';
39
- import { plusIcon } from '@progress/kendo-svg-icons';
40
- import { FloatingLabel } from '@progress/kendo-react-labels';
41
- import ListContainer from '../common/ListContainer';
42
- import List from '../common/List';
43
- import GroupStickyHeader from '../common/GroupStickyHeader';
44
- import TagList from './TagList';
45
- import SearchBar from '../common/SearchBar';
46
- import DropDownBase from '../common/DropDownBase';
47
- import { ActiveDescendant } from './../common/settings';
48
- import { itemIndexStartsWith, getItemValue, areSame, removeDataItems, isPresent, preventDefaultNonInputs, matchTags } from '../common/utils';
49
- import { validatePackage } from '@progress/kendo-react-common';
50
- import { packageMetadata } from '../package-metadata';
51
- import ClearButton from '../common/ClearButton';
52
- import { AdaptiveMode } from '../common/AdaptiveMode';
53
- import { ActionSheetContent } from '@progress/kendo-react-layout';
54
- import { MOBILE_MEDIUM_DEVISE } from '../common/constants';
55
- import { provideLocalizationService } from '@progress/kendo-react-intl';
56
- import { adaptiveModeFooterApply, adaptiveModeFooterCancel, messages } from '../messages';
57
- import ListFilter from '../common/ListFilter';
58
- var sizeMap = kendoThemeMaps.sizeMap, roundedMap = kendoThemeMaps.roundedMap;
59
- var VALIDATION_MESSAGE = 'Please enter a valid value!';
60
- var preventDefault = function (event) { return event.preventDefault(); };
61
- var isCustom = function (type) { return type === FocusedItemType.CustomItem; };
62
- var FocusedItemType;
63
- (function (FocusedItemType) {
64
- FocusedItemType[FocusedItemType["None"] = 0] = "None";
65
- FocusedItemType[FocusedItemType["ListItem"] = 1] = "ListItem";
66
- FocusedItemType[FocusedItemType["CustomItem"] = 2] = "CustomItem";
67
- })(FocusedItemType || (FocusedItemType = {}));
68
- /** @hidden */
69
- var MultiSelectWithoutContext = /** @class */ (function (_super) {
70
- __extends(MultiSelectWithoutContext, _super);
71
- function MultiSelectWithoutContext(props) {
72
- var _this = _super.call(this, props) || this;
73
- /** @hidden */
74
- _this.state = {
75
- activedescendant: ActiveDescendant.PopupList,
76
- currentValue: []
77
- };
78
- _this._element = null;
79
- _this._valueItemsDuringOnChange = null;
80
- _this._inputId = guid();
81
- _this.base = new DropDownBase(_this);
82
- _this._tags = [];
83
- _this._input = null;
84
- _this._adaptiveInput = null;
85
- _this._skipFocusEvent = false;
86
- _this._lastSelectedOrDeslectedItemIndex = null; // Needed for handling the Shift + Up/Down Keyboard Navigation requirement
87
- _this.itemHeight = 0;
88
- _this.scrollToFocused = false;
89
- _this.localization = null;
90
- /** @hidden */
91
- _this.focus = function () {
92
- if (_this._input) {
93
- _this._input.focus();
94
- }
95
- };
96
- /** @hidden */
97
- _this.handleItemSelect = function (index, state) {
98
- var _a = _this.props, _b = _a.data, data = _b === void 0 ? [] : _b, dataItemKey = _a.dataItemKey, virtual = _a.virtual;
99
- var skip = virtual ? virtual.skip : 0;
100
- var dataItem = data[index - skip];
101
- var indexInValue = _this.value.findIndex(function (i) { return areSame(i, dataItem, dataItemKey); });
102
- _this._lastSelectedOrDeslectedItemIndex = data.findIndex(function (i) { return areSame(i, dataItem, dataItemKey); });
103
- var newItems = [];
104
- if (indexInValue !== -1) { // item is already selected
105
- newItems = _this.value;
106
- newItems.splice(indexInValue, 1);
107
- }
108
- else {
109
- newItems = __spreadArray(__spreadArray([], _this.value, true), [dataItem], false);
110
- }
111
- var text = _this.props.filter !== undefined ? _this.props.filter : _this.state.text;
112
- if (text && !_this.mobileMode) {
113
- if (_this.state.text) {
114
- state.data.text = '';
115
- }
116
- _this.base.filterChanged('', state);
117
- }
118
- if (_this._adaptiveInput) {
119
- _this._adaptiveInput.blur();
120
- }
121
- ;
122
- if (_this.state.focusedIndex !== undefined) {
123
- state.data.focusedIndex = undefined;
124
- }
125
- _this.triggerOnChange(newItems, state);
126
- _this.base.triggerPageChangeCornerItems(dataItem, state);
127
- };
128
- /** @hidden */
129
- _this.onTagDelete = function (itemsToRemove, event) {
130
- var state = _this.base.initState();
131
- state.syntheticEvent = event;
132
- if (_this.opened) {
133
- _this.base.togglePopup(state);
134
- }
135
- if (!_this.state.focused && !_this.mobileMode) {
136
- state.data.focused = true;
137
- _this.focus();
138
- }
139
- var selected = _this.value;
140
- removeDataItems(selected, itemsToRemove, _this.props.dataItemKey);
141
- _this.triggerOnChange(selected, state);
142
- _this.applyState(state);
143
- };
144
- /** @hidden */
145
- _this.itemFocus = function (index, state) {
146
- var _a = _this.props, _b = _a.data, data = _b === void 0 ? [] : _b, allowCustom = _a.allowCustom, virtual = _a.virtual;
147
- var skip = virtual ? virtual.skip : 0;
148
- var text = _this.props.filter !== undefined ? _this.props.filter : _this.state.text;
149
- var focusedIndex = _this.getFocusedState().focusedIndex;
150
- var customItem = allowCustom && text;
151
- var nextFocusedItem = data[index - skip];
152
- if (nextFocusedItem && focusedIndex !== index) {
153
- if (_this.state.focusedIndex !== index) {
154
- state.data.focusedIndex = index;
155
- state.data.activedescendant = ActiveDescendant.PopupList;
156
- }
157
- }
158
- else if (customItem && index === -1) {
159
- if (_this.state.focusedIndex !== undefined) {
160
- state.data.focusedIndex = undefined;
161
- }
162
- }
163
- _this.base.triggerPageChangeCornerItems(nextFocusedItem, state);
164
- };
165
- _this.componentRef = function (element) {
166
- _this._element = element;
167
- _this.base.wrapper = element;
168
- };
169
- _this.searchbarRef = function (searchbar) {
170
- var input = _this._input = searchbar && searchbar.input;
171
- if (input && _this.state.focused) {
172
- window.setTimeout(function () { return input.focus(); }, 0);
173
- }
174
- };
175
- _this.onChangeHandler = function (event) {
176
- var state = _this.base.initState();
177
- var value = event.target.value;
178
- state.syntheticEvent = event;
179
- if (_this.props.filter === undefined) {
180
- state.data.text = value;
181
- }
182
- state.data.focusedIndex = undefined;
183
- if (!_this.opened) {
184
- _this.base.togglePopup(state);
185
- _this.setState({ currentValue: _this.value });
186
- }
187
- _this.base.filterChanged(value, state);
188
- _this.applyState(state);
189
- _this.setState({ group: undefined });
190
- };
191
- _this.clearButtonClick = function (event) {
192
- var state = _this.base.initState();
193
- state.syntheticEvent = event;
194
- event.stopPropagation();
195
- if (_this.value.length > 0) {
196
- _this.triggerOnChange([], state);
197
- }
198
- if (_this.state.focusedIndex !== undefined) {
199
- state.data.focusedIndex = undefined;
200
- }
201
- if (_this.opened) {
202
- _this.base.togglePopup(state);
203
- }
204
- var text = _this.props.filter !== undefined ? _this.props.filter : _this.state.text;
205
- if (isPresent(text) && text !== '') {
206
- _this.base.filterChanged('', state);
207
- }
208
- if (_this.state.text) {
209
- state.data.text = '';
210
- }
211
- _this._lastSelectedOrDeslectedItemIndex = null; // Resets the last selected/deselected item according to the Keyboard navigation requirements
212
- _this.applyState(state);
213
- };
214
- _this.onInputKeyDown = function (event) {
215
- var _a = _this.props, _b = _a.data, data = _b === void 0 ? [] : _b, textField = _a.textField, groupField = _a.groupField;
216
- var keyCode = event.keyCode;
217
- var text = _this.props.filter !== undefined ? _this.props.filter : _this.state.text;
218
- var opened = _this.props.opened !== undefined ? _this.props.opened : _this.state.opened;
219
- var _c = _this.getFocusedState(), focusedItem = _c.focusedItem, focusedIndex = _c.focusedIndex;
220
- var state = _this.base.initState();
221
- state.syntheticEvent = event;
222
- if (!text && _this.value.length > 0 &&
223
- (keyCode === Keys.left || keyCode === Keys.right ||
224
- keyCode === Keys.home || keyCode === Keys.end ||
225
- keyCode === Keys.delete || keyCode === Keys.backspace) && !event.shiftKey) {
226
- return _this.onTagsNavigate(event, state);
227
- }
228
- var togglePopup = function () {
229
- event.preventDefault();
230
- _this.base.togglePopup(state);
231
- _this.applyState(state);
232
- };
233
- if (_this.opened) {
234
- if (keyCode === Keys.pageUp) {
235
- _this.base.scrollPopupByPageSize(-1);
236
- }
237
- else if (keyCode === Keys.pageDown) {
238
- _this.base.scrollPopupByPageSize(1);
239
- }
240
- else if ((event.ctrlKey || event.metaKey) && event.code === 'KeyA') {
241
- // Ctrl or Command + "A" Key selects/deselects all items
242
- var currentValuesLength = _this.state.value && _this.state.value.length;
243
- var dataToSet = currentValuesLength === data.length ? [] : data;
244
- _this.updateStateOnKeyboardNavigation(dataToSet, state);
245
- }
246
- else if ((event.ctrlKey || event.metaKey) && event.shiftKey && event.keyCode === Keys.end) {
247
- // Ctrl or Command + Shift + End from the Keyboard specifications
248
- var dataToSet = data.slice(_this.getFocusedState().focusedIndex);
249
- _this.itemFocus(data.length - 1, state);
250
- _this.updateStateOnKeyboardNavigation(dataToSet, state);
251
- }
252
- else if ((event.ctrlKey || event.metaKey) && event.shiftKey && event.keyCode === Keys.home) {
253
- // Ctrl or Command + Shift + Home from the Keyboard specifications
254
- var dataToSet = data.slice(0, _this.getFocusedState().focusedIndex + 1);
255
- _this.itemFocus(0, state);
256
- _this.updateStateOnKeyboardNavigation(dataToSet, state);
257
- }
258
- else if (event.shiftKey && event.keyCode === Keys.up) {
259
- // Shift + Up from the Keyboard specifications
260
- var dataToSet = void 0;
261
- var lastSelectedOrDeselectedIndex = _this.getLastSelectedOrDeselectedIndex(1, focusedIndex);
262
- if (lastSelectedOrDeselectedIndex === null) {
263
- dataToSet = focusedIndex !== 0 ? data.slice(focusedIndex - 1, focusedIndex) : [data[focusedIndex]];
264
- }
265
- else if (lastSelectedOrDeselectedIndex === focusedIndex) {
266
- dataToSet = [data[lastSelectedOrDeselectedIndex - 1]];
267
- }
268
- else if (focusedIndex >= 0) {
269
- dataToSet = lastSelectedOrDeselectedIndex > focusedIndex
270
- ? data.slice(focusedIndex - 1, lastSelectedOrDeselectedIndex)
271
- : data.slice(lastSelectedOrDeselectedIndex - 1, focusedIndex);
272
- }
273
- if (dataToSet && dataToSet.length > 0) {
274
- if (focusedIndex >= 1) {
275
- _this.itemFocus(focusedIndex - 1, state);
276
- }
277
- _this.updateStateOnKeyboardNavigation(dataToSet, state);
278
- }
279
- }
280
- else if (event.shiftKey && event.keyCode === Keys.down) {
281
- // Shift + Down from the Keyboard specifications
282
- var dataToSet = void 0;
283
- var lastSelectedOrDeselectedIndex = _this.getLastSelectedOrDeselectedIndex(0, focusedIndex);
284
- if (lastSelectedOrDeselectedIndex === null) {
285
- dataToSet = focusedIndex !== data.length - 1 ? data.slice(focusedIndex, focusedIndex + 1) : [data[focusedIndex]];
286
- }
287
- else if (lastSelectedOrDeselectedIndex === focusedIndex) {
288
- dataToSet = data.slice(focusedIndex, focusedIndex + 2);
289
- }
290
- else if (focusedIndex >= 0) {
291
- // dataToSet = data.slice(focusedIndex, lastSelectedOrDeselectedIndex);
292
- dataToSet = lastSelectedOrDeselectedIndex > focusedIndex
293
- ? data.slice(focusedIndex + 1, lastSelectedOrDeselectedIndex + 1)
294
- : data.slice(lastSelectedOrDeselectedIndex, focusedIndex + 2);
295
- }
296
- if (dataToSet && dataToSet.length >= 1) {
297
- _this.itemFocus(focusedIndex + 1, state);
298
- _this.updateStateOnKeyboardNavigation(dataToSet, state);
299
- }
300
- }
301
- else if (event.altKey && keyCode === Keys.up) {
302
- togglePopup();
303
- }
304
- else if (keyCode === Keys.up || keyCode === Keys.down) {
305
- if (groupField !== '' && textField) {
306
- if (!_this.props.skipDisabledItems && opened) {
307
- _this.onNavigate(state, keyCode);
308
- }
309
- else {
310
- var newIndex = 0;
311
- if (keyCode === Keys.down || keyCode === Keys.right) {
312
- var tempnewIndex_1 = data.slice(focusedIndex + 1).find(function (i) { return !i.disabled && i[textField]; });
313
- newIndex = tempnewIndex_1 && data.findIndex(function (el) { return el[textField] === tempnewIndex_1[textField]; });
314
- }
315
- else if (keyCode === Keys.up || keyCode === Keys.left) {
316
- var dataToSearch = void 0;
317
- if (focusedIndex === -1) {
318
- dataToSearch = data;
319
- newIndex = data.findIndex(function (i) { return !i.disabled && i[textField]; });
320
- }
321
- else {
322
- dataToSearch = data.slice(0, focusedIndex);
323
- var tempnewIndex_2 = dataToSearch.pop();
324
- while (tempnewIndex_2 && tempnewIndex_2.disabled) {
325
- tempnewIndex_2 = dataToSearch.pop();
326
- }
327
- newIndex = tempnewIndex_2 && data.findIndex(function (el) { return el[textField] === tempnewIndex_2[textField]; });
328
- }
329
- }
330
- if (newIndex) {
331
- var skipItems = newIndex - focusedIndex;
332
- _this.onNavigate(state, keyCode, skipItems);
333
- }
334
- else if (newIndex !== undefined) {
335
- _this.onNavigate(state, keyCode);
336
- }
337
- }
338
- }
339
- else if (!_this.props.skipDisabledItems && opened) {
340
- _this.onNavigate(state, keyCode);
341
- }
342
- else {
343
- var newIndex = null;
344
- if (keyCode === Keys.down || keyCode === Keys.right) {
345
- newIndex = data.slice(focusedIndex + 1).find(function (i) { return !i.disabled; });
346
- }
347
- else if (keyCode === Keys.up || keyCode === Keys.left) {
348
- var dataTest = data.slice(0, focusedIndex);
349
- newIndex = dataTest.pop();
350
- while (newIndex && newIndex.disabled) {
351
- newIndex = dataTest.pop();
352
- }
353
- }
354
- if (newIndex) {
355
- var skipItems = newIndex.id - focusedIndex - 1;
356
- _this.onNavigate(state, keyCode, skipItems);
357
- }
358
- else {
359
- _this.onNavigate(state, keyCode);
360
- }
361
- }
362
- _this.applyState(state);
363
- event.preventDefault();
364
- }
365
- else if (keyCode === Keys.enter) {
366
- event.preventDefault();
367
- if (_this.props.allowCustom && text && focusedItem === null) {
368
- _this.customItemSelect(event);
369
- }
370
- else if (focusedItem && focusedItem.disabled) {
371
- togglePopup();
372
- }
373
- else {
374
- _this.selectFocusedItem(event);
375
- }
376
- }
377
- else if (keyCode === Keys.esc) {
378
- togglePopup();
379
- }
380
- }
381
- else if (event.altKey && keyCode === Keys.down) {
382
- togglePopup();
383
- }
384
- };
385
- _this.listContainerContent = function () {
386
- var _a, _b;
387
- var _c = _this.props, header = _c.header, footer = _c.footer, allowCustom = _c.allowCustom, size = _c.size, _d = _c.data, data = _d === void 0 ? [] : _d, groupStickyHeaderItemRender = _c.groupStickyHeaderItemRender, groupField = _c.groupField, list = _c.list;
388
- var text = _this.props.filter !== undefined ? _this.props.filter : _this.state.text;
389
- var focusedType = _this.getFocusedState().focusedType;
390
- var customItem = allowCustom && text && (React.createElement("div", { className: classNames('k-list', (_a = {},
391
- _a["k-list-".concat(sizeMap[size] || size)] = size,
392
- _a)), key: "customitem", onClick: _this.customItemSelect, onMouseDown: preventDefault },
393
- React.createElement("div", { className: classNames('k-list-item k-custom-item', { 'k-focus': isCustom(focusedType) }), style: { fontStyle: 'italic' } },
394
- text,
395
- React.createElement(IconWrap, { name: 'plus', icon: plusIcon, style: { position: 'absolute', right: '0.5em' } }))));
396
- var group = _this.state.group;
397
- if (group === undefined && groupField !== undefined) {
398
- group = getItemValue(data[0], groupField);
399
- }
400
- return (React.createElement(React.Fragment, null,
401
- header && React.createElement("div", { className: "k-list-header" }, header),
402
- customItem,
403
- React.createElement("div", { className: classNames('k-list', (_b = {},
404
- _b["k-list-".concat(_this.mobileMode ? 'lg' : sizeMap[size] || size)] = size,
405
- _b['k-virtual-list'] = _this.base.vs.enabled,
406
- _b)) },
407
- !list && group && data.length !== 0 && React.createElement(GroupStickyHeader, { group: group, groupMode: 'modern', render: groupStickyHeaderItemRender }),
408
- _this.renderList()),
409
- footer && React.createElement("div", { className: "k-list-footer" }, footer)));
410
- };
411
- _this.renderListContainer = function () {
412
- var base = _this.base;
413
- var _a = _this.props, dir = _a.dir, _b = _a.data, data = _b === void 0 ? [] : _b;
414
- var popupSettings = _this.base.getPopupSettings();
415
- var popupWidth = popupSettings.width !== undefined ? popupSettings.width : base.popupWidth;
416
- var listContainerProps = {
417
- dir: dir !== undefined ? dir : base.dirCalculated,
418
- width: popupWidth,
419
- popupSettings: {
420
- popupClass: classNames(popupSettings.popupClass, 'k-list-container', 'k-multiselect-popup'),
421
- className: popupSettings.className,
422
- animate: popupSettings.animate,
423
- anchor: _this.element,
424
- show: _this.opened,
425
- onOpen: _this.onPopupOpened,
426
- onClose: _this.onPopupClosed,
427
- appendTo: popupSettings.appendTo
428
- },
429
- itemsCount: [data.length, _this.value.length]
430
- };
431
- return (React.createElement(ListContainer, __assign({}, listContainerProps), _this.listContainerContent()));
432
- };
433
- _this.renderAdaptiveListContainer = function () {
434
- var _a = _this.props, adaptiveTitle = _a.adaptiveTitle, filterable = _a.filterable, filter = _a.filter;
435
- var _b = _this.state.windowWidth, windowWidth = _b === void 0 ? 0 : _b;
436
- var mobileText = filter !== undefined ? filter : _this.state.text;
437
- _this.localization = provideLocalizationService(_this);
438
- var mobileFilter = filterable ? (React.createElement(ListFilter, { value: mobileText, ref: function (adaptiveFilter) { return _this._adaptiveInput = adaptiveFilter && adaptiveFilter.element; }, onChange: _this.onChangeHandler, onKeyDown: _this.onInputKeyDown, size: _this.props.size, rounded: _this.props.rounded, fillMode: _this.props.fillMode })) : null;
439
- var actionSheetProps = {
440
- adaptiveTitle: adaptiveTitle,
441
- expand: _this.opened,
442
- onClose: function (event) { return _this.onCancel(event); },
443
- windowWidth: windowWidth,
444
- mobileFilter: mobileFilter,
445
- footer: {
446
- cancelText: _this.localization.toLanguageString(adaptiveModeFooterCancel, messages[adaptiveModeFooterCancel]),
447
- onCancel: _this.onCancel,
448
- applyText: _this.localization.toLanguageString(adaptiveModeFooterApply, messages[adaptiveModeFooterApply]),
449
- onApply: _this.closePopup
450
- }
451
- };
452
- return (React.createElement(AdaptiveMode, __assign({}, actionSheetProps),
453
- React.createElement(ActionSheetContent, { className: '!k-overflow-hidden' },
454
- React.createElement("div", { className: 'k-list-container' }, _this.listContainerContent()))));
455
- };
456
- _this.closePopup = function (event) {
457
- var state = _this.base.initState();
458
- state.syntheticEvent = event;
459
- event.stopPropagation();
460
- if (_this.state.focusedIndex !== undefined) {
461
- state.data.focusedIndex = undefined;
462
- }
463
- if (_this.opened) {
464
- _this.base.togglePopup(state);
465
- }
466
- state.events.push({ type: 'onClose' });
467
- var text = _this.props.filter !== undefined ? _this.props.filter : _this.state.text;
468
- if (isPresent(text) && text !== '') {
469
- _this.base.filterChanged('', state);
470
- }
471
- if (_this.state.text) {
472
- state.data.text = '';
473
- }
474
- _this.applyState(state);
475
- };
476
- _this.onCancel = function (event) {
477
- var state = _this.base.initState();
478
- state.syntheticEvent = event;
479
- event.stopPropagation();
480
- if (_this.state.focusedIndex !== undefined) {
481
- state.data.focusedIndex = undefined;
482
- }
483
- if (_this.opened) {
484
- _this.base.togglePopup(state);
485
- }
486
- state.events.push({ type: 'onCancel' });
487
- var text = _this.props.filter !== undefined ? _this.props.filter : _this.state.text;
488
- if (isPresent(text) && text !== '') {
489
- _this.base.filterChanged('', state);
490
- }
491
- if (_this.state.text) {
492
- state.data.text = '';
493
- }
494
- _this.applyState(state);
495
- };
496
- _this.renderList = function () {
497
- var _a = _this.props, _b = _a.data, data = _b === void 0 ? [] : _b, textField = _a.textField, listNoDataRender = _a.listNoDataRender, itemRender = _a.itemRender, groupHeaderItemRender = _a.groupHeaderItemRender, dataItemKey = _a.dataItemKey, virtual = _a.virtual;
498
- var vs = _this.base.vs;
499
- var skip = virtual ? virtual.skip : 0;
500
- var focusedIndex = _this.getFocusedState().focusedIndex;
501
- var popupSettings = _this.base.getPopupSettings();
502
- var translate = "translateY(".concat(vs.translate, "px)");
503
- return (React.createElement(List, { id: _this.base.listBoxId, show: _this.opened, data: data.slice(), focusedIndex: focusedIndex - skip, value: _this.value, textField: textField, valueField: dataItemKey, optionsGuid: _this.base.guid, groupField: _this.props.groupField, groupMode: 'modern', listRef: function (list) { vs.list = _this.base.list = list; }, wrapperStyle: _this.mobileMode ? {} : { maxHeight: popupSettings.height }, wrapperCssClass: "k-list-content", listStyle: vs.enabled ? { transform: translate } : undefined, key: "listKey", skip: skip, onClick: _this.handleItemClick, itemRender: itemRender, groupHeaderItemRender: groupHeaderItemRender, noDataRender: listNoDataRender, onMouseDown: preventDefault, onBlur: _this.handleBlur, onScroll: _this.onScroll, wrapperRef: vs.scrollerRef, scroller: _this.base.renderScrollElement() }));
504
- };
505
- _this.onScroll = function (event) {
506
- var _a = _this.base, vs = _a.vs, list = _a.list;
507
- vs.scrollHandler(event);
508
- var groupField = _this.props.groupField;
509
- var _b = _this.props.data, data = _b === void 0 ? [] : _b;
510
- if (!groupField || !data.length) {
511
- return;
512
- }
513
- if (groupField) {
514
- var itemHeight = _this.itemHeight =
515
- _this.itemHeight || (vs.enabled ? vs.itemHeight : (list ? list.children[0].offsetHeight : 0));
516
- var target = event.target;
517
- var scrollTop = target.scrollTop - (vs.skip * itemHeight);
518
- data = _this.base.getGroupedDataModernMode(data, groupField);
519
- var group = data[0][groupField];
520
- for (var i = 1; i < data.length; i++) {
521
- if (itemHeight * i > scrollTop) {
522
- break;
523
- }
524
- if (data[i] && data[i][groupField]) {
525
- group = data[i][groupField];
526
- }
527
- }
528
- if (group !== _this.state.group) {
529
- _this.setState({
530
- group: group
531
- });
532
- }
533
- }
534
- };
535
- _this.customItemSelect = function (event) {
536
- var _a;
537
- var itemText = _this.props.filter !== undefined ? _this.props.filter : _this.state.text;
538
- var textField = _this.props.textField;
539
- if (!itemText) {
540
- return;
541
- }
542
- var state = _this.base.initState();
543
- state.syntheticEvent = event;
544
- var item = textField ? (_a = {}, _a[textField] = itemText, _a) : itemText;
545
- if (_this.state.text !== undefined) {
546
- state.data.text = '';
547
- }
548
- state.data.focusedIndex = undefined;
549
- _this.base.filterChanged('', state);
550
- var newItems = __spreadArray(__spreadArray([], _this.value, true), [item], false);
551
- _this.triggerOnChange(newItems, state);
552
- _this.base.togglePopup(state);
553
- _this.applyState(state);
554
- };
555
- _this.handleWrapperClick = function (event) {
556
- var input = _this._input;
557
- if (!_this.opened && input) {
558
- _this.focusElement(input);
559
- }
560
- var state = _this.base.initState();
561
- state.syntheticEvent = event;
562
- if (!_this.state.focused && !_this.mobileMode) {
563
- state.events.push({ type: 'onFocus' });
564
- state.data.focused = true;
565
- }
566
- if (_this.mobileMode) {
567
- _this.setState({ currentValue: _this.tagsToRender });
568
- if (_this.mobileMode) {
569
- window.setTimeout(function () { return _this._adaptiveInput && _this._adaptiveInput.focus(); }, 300);
570
- }
571
- }
572
- _this.base.togglePopup(state);
573
- _this.applyState(state);
574
- };
575
- _this.handleItemClick = function (index, event) {
576
- var state = _this.base.initState();
577
- state.syntheticEvent = event;
578
- _this.handleItemSelect(index, state);
579
- if (_this.props.autoClose && !_this.mobileMode) {
580
- _this.base.togglePopup(state);
581
- }
582
- event.stopPropagation();
583
- _this.applyState(state);
584
- };
585
- _this.handleBlur = function (event) {
586
- if (!_this.state.focused || _this._skipFocusEvent) {
587
- return;
588
- }
589
- var state = _this.base.initState();
590
- var _a = _this.props, allowCustom = _a.allowCustom, filterable = _a.filterable;
591
- state.syntheticEvent = event;
592
- state.data.focused = false;
593
- state.events.push({ type: 'onBlur' });
594
- if (_this.opened && !_this.mobileMode) {
595
- if (_this.state.opened) {
596
- state.data.opened = false;
597
- }
598
- state.events.push({ type: 'onClose' });
599
- }
600
- if (!allowCustom && !filterable && _this.state.text) {
601
- state.data.text = '';
602
- }
603
- _this.applyState(state);
604
- };
605
- _this.handleFocus = function (event) {
606
- if (_this._skipFocusEvent) {
607
- return;
608
- }
609
- _this.base.handleFocus(event);
610
- };
611
- _this.onPopupOpened = function () {
612
- if (_this._input && _this.state.focused && !_this.mobileMode) {
613
- _this.focusElement(_this._input);
614
- }
615
- };
616
- _this.onPopupClosed = function () {
617
- if (_this.state.focused) {
618
- window.setTimeout(function () { if (_this.state.focused) {
619
- _this.focusElement(_this._input);
620
- } }, 0);
621
- }
622
- };
623
- _this.setValidity = function () {
624
- if (_this._input && _this._input.setCustomValidity) {
625
- _this._input.setCustomValidity(_this.validity.valid
626
- ? ''
627
- : _this.props.validationMessage || VALIDATION_MESSAGE);
628
- }
629
- };
630
- validatePackage(packageMetadata);
631
- return _this;
632
- }
633
- Object.defineProperty(MultiSelectWithoutContext.prototype, "document", {
634
- get: function () {
635
- if (!canUseDOM) {
636
- return;
637
- }
638
- // useful only for user actions
639
- return (this.element && this.element.ownerDocument) || document;
640
- },
641
- enumerable: false,
642
- configurable: true
643
- });
644
- Object.defineProperty(MultiSelectWithoutContext.prototype, "element", {
645
- /** @hidden */
646
- get: function () {
647
- return this._element;
648
- },
649
- enumerable: false,
650
- configurable: true
651
- });
652
- Object.defineProperty(MultiSelectWithoutContext.prototype, "opened", {
653
- /** @hidden */
654
- get: function () {
655
- var opened = this.props.opened !== undefined ? this.props.opened : this.state.opened;
656
- return !!opened;
657
- },
658
- enumerable: false,
659
- configurable: true
660
- });
661
- Object.defineProperty(MultiSelectWithoutContext.prototype, "tagsToRender", {
662
- /** @hidden */
663
- get: function () {
664
- var _a = this.props, tags = _a.tags, textField = _a.textField;
665
- var tagsToRender = [];
666
- if (tags === undefined) {
667
- this.value.forEach(function (item) {
668
- tagsToRender.push({ text: getItemValue(item, textField), data: [item] });
669
- });
670
- }
671
- else {
672
- tagsToRender.push.apply(tagsToRender, tags);
673
- }
674
- return tagsToRender;
675
- },
676
- enumerable: false,
677
- configurable: true
678
- });
679
- Object.defineProperty(MultiSelectWithoutContext.prototype, "mobileMode", {
680
- /**
681
- * The mobile mode of the ComboBox.
682
- */
683
- get: function () {
684
- var isAdaptive = this.state.windowWidth && this.state.windowWidth <= MOBILE_MEDIUM_DEVISE && this.props.adaptive;
685
- return !!isAdaptive;
686
- },
687
- enumerable: false,
688
- configurable: true
689
- });
690
- Object.defineProperty(MultiSelectWithoutContext.prototype, "value", {
691
- /**
692
- * Represents the value of the MultiSelect.
693
- */
694
- get: function () {
695
- var result = [];
696
- if (this._valueItemsDuringOnChange) {
697
- result.push.apply(result, this._valueItemsDuringOnChange);
698
- }
699
- else if (this.props.value) {
700
- result.push.apply(result, this.props.value);
701
- }
702
- else if (this.state.value) {
703
- result.push.apply(result, this.state.value);
704
- }
705
- else if (this.props.defaultValue) {
706
- result.push.apply(result, this.props.defaultValue);
707
- }
708
- return result;
709
- },
710
- enumerable: false,
711
- configurable: true
712
- });
713
- Object.defineProperty(MultiSelectWithoutContext.prototype, "name", {
714
- /**
715
- * Gets the `name` property of the MultiSelect.
716
- */
717
- get: function () {
718
- return this.props.name;
719
- },
720
- enumerable: false,
721
- configurable: true
722
- });
723
- Object.defineProperty(MultiSelectWithoutContext.prototype, "validity", {
724
- /**
725
- * Represents the validity state into which the MultiSelect is set.
726
- */
727
- get: function () {
728
- var customError = this.props.validationMessage !== undefined;
729
- var isValid = (!this.required
730
- || (this.value !== null && this.value.length > 0 && this.value !== undefined));
731
- var valid = this.props.valid !== undefined ? this.props.valid : isValid;
732
- return {
733
- customError: customError,
734
- valid: valid,
735
- valueMissing: this.value === null
736
- };
737
- },
738
- enumerable: false,
739
- configurable: true
740
- });
741
- Object.defineProperty(MultiSelectWithoutContext.prototype, "required", {
742
- /** @hidden */
743
- get: function () {
744
- return this.props.required !== undefined
745
- ? this.props.required
746
- : MultiSelectWithoutContext.defaultProps.required;
747
- },
748
- enumerable: false,
749
- configurable: true
750
- });
751
- Object.defineProperty(MultiSelectWithoutContext.prototype, "validityStyles", {
752
- get: function () {
753
- return this.props.validityStyles !== undefined
754
- ? this.props.validityStyles
755
- : MultiSelectWithoutContext.defaultProps.validityStyles;
756
- },
757
- enumerable: false,
758
- configurable: true
759
- });
760
- /** @hidden */
761
- MultiSelectWithoutContext.prototype.componentDidUpdate = function (prevProps, prevState) {
762
- var _a;
763
- var _b = this.props, virtual = _b.virtual, _c = _b.groupField, groupField = _c === void 0 ? '' : _c, _d = _b.data, data = _d === void 0 ? [] : _d;
764
- var skip = virtual ? virtual.skip : 0;
765
- var prevTotal = prevProps.virtual ? prevProps.virtual.total : 0;
766
- var prevOpened = prevProps.opened !== undefined ? prevProps.opened : prevState.opened;
767
- var opening = !prevOpened && this.opened;
768
- var closing = prevOpened && !this.opened;
769
- var popupSettings = this.base.getPopupSettings();
770
- if (!popupSettings.animate && closing) {
771
- this.onPopupClosed();
772
- }
773
- if (virtual && virtual.total !== prevTotal) {
774
- this.base.vs.calcScrollElementHeight();
775
- this.base.vs.reset();
776
- }
777
- else {
778
- var _e = this.getFocusedState(), focusedItem = _e.focusedItem, focusedIndex = _e.focusedIndex;
779
- if (groupField !== '') {
780
- focusedIndex = (_a = this.base.getGroupedDataModernMode(data, groupField)) === null || _a === void 0 ? void 0 : _a.indexOf(focusedItem);
781
- }
782
- if (opening && virtual) {
783
- this.base.scrollToVirtualItem(virtual, focusedIndex - skip);
784
- }
785
- else if (opening && !virtual) {
786
- // Resets the sticky header group value for scenarios with open/close of component's popup
787
- if (data && data.length !== 0) {
788
- this.base.resetGroupStickyHeader(data[0][groupField], this);
789
- }
790
- this.base.scrollToItem(focusedIndex);
791
- }
792
- else if (this.opened && prevOpened && focusedItem && this.scrollToFocused) {
793
- this.base.scrollToItem(focusedIndex - skip);
794
- }
795
- }
796
- this.scrollToFocused = false;
797
- this.setValidity();
798
- };
799
- /** @hidden */
800
- MultiSelectWithoutContext.prototype.componentDidMount = function () {
801
- var _a;
802
- this.observerResize = canUseDOM && window.ResizeObserver && new window.ResizeObserver(this.calculateMedia.bind(this));
803
- this.base.didMount();
804
- this.setValidity();
805
- if (((_a = this.document) === null || _a === void 0 ? void 0 : _a.body) && this.observerResize) {
806
- this.observerResize.observe(this.document.body);
807
- }
808
- };
809
- /** @hidden */
810
- MultiSelectWithoutContext.prototype.componentWillUnmount = function () {
811
- var _a;
812
- if (((_a = this.document) === null || _a === void 0 ? void 0 : _a.body) && this.observerResize) {
813
- this.observerResize.disconnect();
814
- }
815
- };
816
- /** @hidden */
817
- MultiSelectWithoutContext.prototype.onNavigate = function (state, keyCode, skipItems) {
818
- var _a = this.props, allowCustom = _a.allowCustom, _b = _a.data, data = _b === void 0 ? [] : _b;
819
- var text = this.props.filter !== undefined ? this.props.filter : this.state.text;
820
- var _c = this.getFocusedState(), focusedType = _c.focusedType, focusedIndex = _c.focusedIndex;
821
- var customItem = allowCustom && text;
822
- var customItemFocused = isCustom(focusedType);
823
- var base = this.base;
824
- var vs = base.vs;
825
- if (this.opened && keyCode === Keys.up && customItemFocused) {
826
- if (this.state.focusedIndex !== undefined) {
827
- state.data.focusedIndex = undefined;
828
- }
829
- }
830
- else {
831
- var newFocused = base.navigation.navigate({
832
- keyCode: keyCode,
833
- current: focusedIndex,
834
- max: (vs.enabled ? vs.total : data.length) - 1,
835
- min: customItem ? -1 : 0,
836
- skipItems: skipItems ? skipItems : undefined
837
- });
838
- if (newFocused !== undefined) {
839
- this.itemFocus(newFocused, state);
840
- this.scrollToFocused = true;
841
- }
842
- }
843
- this.applyState(state);
844
- };
845
- /** @hidden */
846
- MultiSelectWithoutContext.prototype.render = function () {
847
- var _a, _b;
848
- var _c = this.props, style = _c.style, className = _c.className, label = _c.label, dir = _c.dir, disabled = _c.disabled, textField = _c.textField, dataItemKey = _c.dataItemKey, virtual = _c.virtual, size = _c.size, rounded = _c.rounded, fillMode = _c.fillMode, loading = _c.loading, filter = _c.filter;
849
- var _d = this.state, text = _d.text, focused = _d.focused, focusedTag = _d.focusedTag, currentValue = _d.currentValue;
850
- var vs = this.base.vs;
851
- var id = this.props.id || this._inputId;
852
- vs.enabled = virtual !== undefined;
853
- if (virtual !== undefined) {
854
- vs.skip = virtual.skip;
855
- vs.total = virtual.total;
856
- vs.pageSize = virtual.pageSize;
857
- }
858
- var currentTagsToRender = (this.mobileMode && this.opened) ? currentValue : this.tagsToRender;
859
- this.setItems(this.tagsToRender, this._tags);
860
- var isValid = !this.validityStyles || this.validity.valid;
861
- var clearButton = Boolean(filter !== undefined ? filter : text)
862
- || (currentTagsToRender && currentTagsToRender.length > 0);
863
- var component = (React.createElement(React.Fragment, null,
864
- React.createElement("div", { ref: this.componentRef, className: classNames('k-multiselect k-input', className, (_a = {},
865
- _a["k-input-".concat(sizeMap[size] || size)] = size,
866
- _a["k-rounded-".concat(roundedMap[rounded] || rounded)] = rounded,
867
- _a["k-input-".concat(fillMode)] = fillMode,
868
- _a['k-focus'] = focused && !disabled,
869
- _a['k-invalid'] = !isValid,
870
- _a['k-disabled'] = disabled,
871
- _a['k-loading'] = loading,
872
- _a['k-required'] = this.required,
873
- _a)), style: !label
874
- ? style
875
- : __assign(__assign({}, style), { width: undefined }), dir: dir, onFocus: this.handleFocus, onBlur: this.handleBlur, onClick: this.handleWrapperClick, onMouseDown: preventDefaultNonInputs },
876
- React.createElement("div", { className: classNames('k-input-values') },
877
- React.createElement("div", { className: classNames('k-chip-list', (_b = {}, _b["k-chip-list-".concat(sizeMap[size] || size)] = size, _b)), role: "listbox", id: 'tagslist-' + this.base.guid }, currentTagsToRender && currentTagsToRender.length > 0 && React.createElement(TagList, { tagRender: this.props.tagRender, onTagDelete: this.onTagDelete, data: currentTagsToRender, guid: this.base.guid, focused: focusedTag ? currentTagsToRender.find(function (t) { return matchTags(t, focusedTag, dataItemKey); }) : undefined, size: size })),
878
- this.renderSearchBar(id)),
879
- loading && React.createElement(IconWrap, { className: "k-input-loading-icon", name: 'loading' }),
880
- clearButton && React.createElement(ClearButton, { onClick: this.clearButtonClick }),
881
- !this.mobileMode && this.renderListContainer()),
882
- this.mobileMode && this.renderAdaptiveListContainer()));
883
- return label ? (React.createElement(FloatingLabel, { label: label, editorId: id, editorValue: text || getItemValue(this.value[0], textField), editorValid: isValid, editorDisabled: disabled, style: { width: style ? style.width : undefined }, children: component })) : component;
884
- };
885
- MultiSelectWithoutContext.prototype.renderSearchBar = function (id) {
886
- var _a = this.state, activedescendant = _a.activedescendant, focusedTag = _a.focusedTag, currentValue = _a.currentValue;
887
- var _b = this.props, disabled = _b.disabled, placeholder = _b.placeholder, ariaDescribedBy = _b.ariaDescribedBy;
888
- var text = !this.mobileMode && (this.props.filter !== undefined ? this.props.filter : this.state.text) || '';
889
- var focusedIndex = this.getFocusedState().focusedIndex;
890
- var placeholderToShow = this.value.length === 0 && !text ? placeholder : undefined;
891
- var adaptivePlaceholder = (currentValue && currentValue.length > 0) ? undefined : placeholder;
892
- var ariaActivedescendant = activedescendant === ActiveDescendant.TagsList && focusedTag !== undefined ?
893
- "tag-".concat(this.base.guid, "-").concat(focusedTag.text.replace(/\s+/g, '-')) :
894
- "option-".concat(this.base.guid, "-").concat(focusedIndex);
895
- return (React.createElement(SearchBar, { id: id, size: Math.max((placeholderToShow || '').length, text.length, 1), tabIndex: this.props.tabIndex, accessKey: this.props.accessKey, placeholder: this.mobileMode && this.opened ? adaptivePlaceholder : placeholderToShow, value: text, onChange: this.onChangeHandler, onKeyDown: this.onInputKeyDown, ref: this.searchbarRef, disabled: disabled, expanded: this.opened, owns: this.base.listBoxId, role: 'combobox', activedescendant: ariaActivedescendant, ariaDescribedBy: "tagslist-".concat(this.base.guid).concat(ariaDescribedBy ? (' ' + ariaDescribedBy) : ''), ariaLabelledBy: this.props.ariaLabelledBy, ariaRequired: this.required }));
896
- };
897
- MultiSelectWithoutContext.prototype.onTagsNavigate = function (event, state) {
898
- var keyCode = event.keyCode;
899
- var focusedTag = this.state.focusedTag;
900
- var tags = this._tags;
901
- var itemsKey = this.props.dataItemKey;
902
- var focusedIndex = focusedTag ?
903
- tags.findIndex(function (t) { return matchTags(t, focusedTag, itemsKey); }) : -1;
904
- var newFocusedTag = undefined;
905
- var hasFocused = focusedIndex !== -1;
906
- if (keyCode === Keys.left) {
907
- if (hasFocused) {
908
- focusedIndex = Math.max(0, focusedIndex - 1);
909
- }
910
- else {
911
- focusedIndex = tags.length - 1;
912
- }
913
- newFocusedTag = tags[focusedIndex];
914
- }
915
- else if (keyCode === Keys.right) {
916
- if (focusedIndex === tags.length - 1) {
917
- newFocusedTag = undefined;
918
- }
919
- else if (hasFocused) {
920
- focusedIndex = Math.min(tags.length - 1, focusedIndex + 1);
921
- newFocusedTag = tags[focusedIndex];
922
- }
923
- }
924
- else if (keyCode === Keys.home && !event.shiftKey) {
925
- newFocusedTag = tags[0];
926
- }
927
- else if (keyCode === Keys.end && !event.shiftKey) {
928
- newFocusedTag = tags[tags.length - 1];
929
- }
930
- else if (keyCode === Keys.delete) {
931
- if (hasFocused) {
932
- var items = this.value;
933
- removeDataItems(items, tags[focusedIndex].data, itemsKey);
934
- this.triggerOnChange(items, state);
935
- }
936
- }
937
- else if (keyCode === Keys.backspace) {
938
- var items = this.value;
939
- if (hasFocused) {
940
- removeDataItems(items, tags[focusedIndex].data, itemsKey);
941
- this.triggerOnChange(items, state);
942
- }
943
- else if (!hasFocused && tags.length) {
944
- var removed = tags.pop();
945
- removeDataItems(items, removed.data, itemsKey);
946
- this.triggerOnChange(items, state);
947
- }
948
- }
949
- if (newFocusedTag !== focusedTag) {
950
- state.data.focusedTag = newFocusedTag;
951
- state.data.activedescendant = ActiveDescendant.TagsList;
952
- }
953
- this.applyState(state);
954
- };
955
- MultiSelectWithoutContext.prototype.triggerOnChange = function (items, state) {
956
- if (this.props.value === undefined) {
957
- state.data.value = __spreadArray([], items, true);
958
- }
959
- this._valueItemsDuringOnChange = [];
960
- this.setItems(items, this._valueItemsDuringOnChange);
961
- state.events.push({ type: 'onChange' });
962
- };
963
- MultiSelectWithoutContext.prototype.selectFocusedItem = function (event, itemtoSelect) {
964
- var _a = this.props, _b = _a.data, data = _b === void 0 ? [] : _b, virtual = _a.virtual;
965
- var focusedIndex = (itemtoSelect || this.getFocusedState()).focusedIndex;
966
- var skip = virtual ? virtual.skip : 0;
967
- if (data[focusedIndex - skip] !== undefined) {
968
- this.handleItemClick(focusedIndex, event);
969
- }
970
- };
971
- MultiSelectWithoutContext.prototype.setItems = function (srcItems, destItems) {
972
- destItems.length = 0;
973
- destItems.push.apply(destItems, srcItems);
974
- };
975
- MultiSelectWithoutContext.prototype.getFocusedState = function () {
976
- var focusedIndex = this.state.focusedIndex;
977
- var text = this.props.filter !== undefined ? this.props.filter : this.state.text;
978
- var _a = this.props, allowCustom = _a.allowCustom, _b = _a.data, data = _b === void 0 ? [] : _b, dataItemKey = _a.dataItemKey, virtual = _a.virtual, textField = _a.textField, _c = _a.focusedItemIndex, focusedItemIndex = _c === void 0 ? itemIndexStartsWith : _c, skipDisabledItems = _a.skipDisabledItems;
979
- var skip = (virtual && virtual.skip) || 0;
980
- var focusedInd;
981
- if (focusedIndex !== undefined) {
982
- return {
983
- focusedIndex: focusedIndex,
984
- focusedItem: data[focusedIndex - skip],
985
- focusedType: FocusedItemType.ListItem
986
- };
987
- }
988
- var selected = this.value;
989
- if (allowCustom && text) {
990
- return { focusedItem: null, focusedIndex: -1, focusedType: FocusedItemType.CustomItem };
991
- }
992
- else if (text) {
993
- focusedInd = focusedItemIndex(data, text, textField);
994
- return {
995
- focusedItem: data[focusedInd],
996
- focusedIndex: focusedInd + skip,
997
- focusedType: FocusedItemType.ListItem
998
- };
999
- }
1000
- else if (selected.length) {
1001
- var last_1 = selected[selected.length - 1];
1002
- focusedInd = data.findIndex(function (i) { return areSame(i, last_1, dataItemKey); });
1003
- if (data[focusedInd] !== undefined) {
1004
- return {
1005
- focusedIndex: focusedInd + skip,
1006
- focusedItem: data[focusedInd],
1007
- focusedType: FocusedItemType.ListItem
1008
- };
1009
- }
1010
- return { focusedType: FocusedItemType.None, focusedIndex: -1 };
1011
- }
1012
- else if (skipDisabledItems && textField && !text && skip === 0) {
1013
- var newIndex = data.findIndex(function (i) { return !i.disabled && i[textField]; });
1014
- return {
1015
- focusedIndex: newIndex,
1016
- focusedItem: data[newIndex - skip],
1017
- focusedType: FocusedItemType.ListItem
1018
- };
1019
- }
1020
- return skip === 0 ?
1021
- { focusedItem: data[0], focusedIndex: 0, focusedType: FocusedItemType.ListItem } :
1022
- { focusedType: FocusedItemType.None, focusedIndex: -1 };
1023
- };
1024
- MultiSelectWithoutContext.prototype.focusElement = function (element) {
1025
- var _this = this;
1026
- this._skipFocusEvent = true;
1027
- element.focus();
1028
- window.setTimeout(function () { return _this._skipFocusEvent = false; }, 0);
1029
- };
1030
- MultiSelectWithoutContext.prototype.applyState = function (state) {
1031
- this.base.applyState(state);
1032
- this._valueItemsDuringOnChange = null;
1033
- };
1034
- MultiSelectWithoutContext.prototype.calculateMedia = function (entries) {
1035
- for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
1036
- var entry = entries_1[_i];
1037
- this.setState({ windowWidth: entry.target.clientWidth });
1038
- }
1039
- ;
1040
- };
1041
- ;
1042
- /**
1043
- * Updates the state of the MultiSelect when the complex keyboard navigation that
1044
- * includes key combinations with the Ctrl/Command, Shift, Home and End keys
1045
- *
1046
- * @param {Array<string | Object>} dataToSet Defines the array of new values that will be applied to the MultiSelect
1047
- * @param {MultiSelectInternalState} state The current state of the MultiSelect
1048
- */
1049
- MultiSelectWithoutContext.prototype.updateStateOnKeyboardNavigation = function (dataToSet, state) {
1050
- this.setState({ value: dataToSet });
1051
- this.triggerOnChange(dataToSet, state);
1052
- this.applyState(state);
1053
- };
1054
- /**
1055
- * Returns the last element that was selected or deselected. Needed for the keyboard navigation specifications
1056
- *
1057
- * @param {number} correction A correction is needed depending on if UP or DOWN key is pressed
1058
- */
1059
- MultiSelectWithoutContext.prototype.getLastSelectedOrDeselectedIndex = function (correction, focusedIndex) {
1060
- if (this._lastSelectedOrDeslectedItemIndex === null) {
1061
- this._lastSelectedOrDeslectedItemIndex = focusedIndex;
1062
- }
1063
- return this._lastSelectedOrDeslectedItemIndex !== null ? this._lastSelectedOrDeslectedItemIndex + correction : null;
1064
- };
1065
- MultiSelectWithoutContext.displayName = 'MultiSelect';
1066
- /** @hidden */
1067
- MultiSelectWithoutContext.propTypes = __assign(__assign({}, DropDownBase.propTypes), { autoClose: PropTypes.bool, value: PropTypes.arrayOf(PropTypes.any), defaultValue: PropTypes.arrayOf(PropTypes.any), dataItemKey: PropTypes.string, placeholder: PropTypes.string, tags: PropTypes.arrayOf(PropTypes.shape({
1068
- text: PropTypes.string,
1069
- data: PropTypes.arrayOf(PropTypes.any)
1070
- })), tagRender: PropTypes.func, id: PropTypes.string, ariaLabelledBy: PropTypes.string, ariaDescribedBy: PropTypes.string, groupField: PropTypes.string, list: PropTypes.any, adaptive: PropTypes.bool, adaptiveTitle: PropTypes.string, onCancel: PropTypes.func, skipDisabledItems: PropTypes.bool });
1071
- /** @hidden */
1072
- MultiSelectWithoutContext.defaultProps = __assign(__assign({}, DropDownBase.defaultProps), { autoClose: true, required: false, size: 'medium', rounded: 'medium', fillMode: 'solid', groupMode: 'modern', skipDisabledItems: true });
1073
- return MultiSelectWithoutContext;
1074
- }(React.Component));
1075
- export { MultiSelectWithoutContext };
1076
- /**
1077
- * Represents the PropsContext of the `MultiSelect` component.
1078
- * Used for global configuration of all `MultiSelect` instances.
1079
- *
1080
- * For more information, refer to the [Dropdowns Props Context]({% slug props-context_dropdowns %}) article.
1081
- */
1082
- export var MultiSelectPropsContext = createPropsContext();
1083
- /* eslint-disable @typescript-eslint/no-redeclare -- intentionally naming the component the same as the type */
1084
- /**
1085
- * Represents the [KendoReact MultiSelect component]({% slug overview_multiselect %}).
1086
- *
1087
- * Accepts properties of type [MultiSelectProps]({% slug api_dropdowns_multiselectprops %}).
1088
- * Obtaining the `ref` returns an object of type [MultiSelectHandle]({% slug api_dropdowns_multiselecthandle %}).
1089
- *
1090
- * @example
1091
- * ```jsx
1092
- * class App extends React.Component {
1093
- * multiselect = null;
1094
- * render() {
1095
- * return (
1096
- * <div>
1097
- * <MultiSelect
1098
- * data={[ "Albania", "Andorra", "Austria", "Belarus" ]}
1099
- * ref={component => this.multiselect = component}
1100
- * />
1101
- * <button onClick={() => alert(this.multiselect.value)}>alert value</button>
1102
- * </div>
1103
- * );
1104
- * }
1105
- * }
1106
- * ReactDOM.render(<App />, document.querySelector('my-app'));
1107
- * ```
1108
- */
1109
- export var MultiSelect = withPropsContext(MultiSelectPropsContext, MultiSelectWithoutContext);
1110
- MultiSelect.displayName = 'KendoReactMultiSelect';