@via-profit/ui-kit 0.1.0-rc.80 → 0.1.0-rc.82
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.
|
@@ -98,7 +98,7 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
|
98
98
|
case 'ArrowDown':
|
|
99
99
|
{
|
|
100
100
|
event.preventDefault();
|
|
101
|
-
if (!currentOpen) {
|
|
101
|
+
if (!currentOpen && filteredItems.length > 0) {
|
|
102
102
|
onRequestOpen(event);
|
|
103
103
|
}
|
|
104
104
|
if (currentOpen) {
|
|
@@ -132,7 +132,7 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
|
132
132
|
// do nothing
|
|
133
133
|
break;
|
|
134
134
|
}
|
|
135
|
-
}, [currentOpen, onRequestClose, onRequestOpen]);
|
|
135
|
+
}, [currentOpen, onRequestClose, onRequestOpen, filteredItems.length]);
|
|
136
136
|
const applyFilterForItems = react_1.default.useCallback((inputValue, itemList) => {
|
|
137
137
|
const query = inputValue.toLowerCase().trim();
|
|
138
138
|
// Apply filter
|
|
@@ -190,12 +190,14 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
|
190
190
|
parentElem = parentElem.parentNode;
|
|
191
191
|
}
|
|
192
192
|
// Click outside
|
|
193
|
-
if (needToClose) {
|
|
193
|
+
if (needToClose && currentOpen) {
|
|
194
194
|
if (clearOnBlur) {
|
|
195
|
+
const newInputValue = currentValue === null
|
|
196
|
+
? ''
|
|
197
|
+
: selectedItemToString(currentValue);
|
|
195
198
|
dispatch((0, context_1.actionSetPartial)({
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
: selectedItemToString(currentValue),
|
|
199
|
+
filteredItems: multiple ? filteredItems : applyFilterForItems(newInputValue, items),
|
|
200
|
+
inputValue: newInputValue,
|
|
199
201
|
}));
|
|
200
202
|
}
|
|
201
203
|
if (isOpen) {
|
|
@@ -210,12 +212,18 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
|
210
212
|
}, [
|
|
211
213
|
onRequestClose,
|
|
212
214
|
anchorElement,
|
|
215
|
+
filteredItems,
|
|
216
|
+
items,
|
|
213
217
|
isOpen,
|
|
214
218
|
clearOnBlur,
|
|
219
|
+
currentOpen,
|
|
215
220
|
dispatch,
|
|
216
221
|
value,
|
|
217
222
|
selectedItemToString,
|
|
218
223
|
currentValue,
|
|
224
|
+
applyFilterForItems,
|
|
225
|
+
inputValue,
|
|
226
|
+
multiple,
|
|
219
227
|
]);
|
|
220
228
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
221
229
|
react_1.default.useMemo(() => (react_1.default.createElement(overridesMap.TextField, Object.assign({ placeholder: placeholder, label: label, error: error, requiredAsterisk: requiredAsterisk, errorText: errorText, fullWidth: fullWidth, startIcon: startIcon, isLoading: currentLoading, endIcon: clearable ? (react_1.default.createElement(Button_1.default, { iconOnly: true, type: "button", onClick: () => (currentLoading ? 'undefined' : clear()) }, currentLoading ? react_1.default.createElement(Spinner_1.default, null) : react_1.default.createElement(IconClear_1.default, null))) : undefined }, nativeInputProps, { onKeyDown: event => {
|
|
@@ -242,29 +250,32 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
|
242
250
|
}
|
|
243
251
|
}, onFocus: event => {
|
|
244
252
|
isFocusedRef.current = true;
|
|
245
|
-
if (openOnFocus) {
|
|
253
|
+
if (openOnFocus && !currentOpen && filteredItems.length > 0) {
|
|
246
254
|
onRequestOpen(event);
|
|
247
255
|
}
|
|
248
|
-
if (!openOnFocus && !currentOpen && inputValue !== '') {
|
|
256
|
+
if (!openOnFocus && !currentOpen && inputValue !== '' && filteredItems.length > 0) {
|
|
249
257
|
onRequestOpen(event);
|
|
250
258
|
}
|
|
251
259
|
if (typeof nativeInputProps.onFocus === 'function') {
|
|
252
260
|
nativeInputProps.onFocus(event);
|
|
253
261
|
}
|
|
254
262
|
}, onClick: event => {
|
|
255
|
-
// if (isFocusedRef.current) {
|
|
256
|
-
// onRequestOpen(event);
|
|
257
|
-
// }
|
|
258
263
|
if (typeof nativeInputProps.onClick === 'function') {
|
|
259
264
|
nativeInputProps.onClick(event);
|
|
260
265
|
}
|
|
266
|
+
if (isFocusedRef.current && !currentOpen && filteredItems.length > 0) {
|
|
267
|
+
onRequestOpen(event);
|
|
268
|
+
}
|
|
261
269
|
}, onChange: event => {
|
|
262
270
|
if (typeof onInputChange === 'function') {
|
|
263
271
|
onInputChange(event);
|
|
264
272
|
}
|
|
265
273
|
// If openOnFocus is false, but value is not empty
|
|
266
274
|
// we should open menu list if is not opened
|
|
267
|
-
if (!openOnFocus &&
|
|
275
|
+
if (!openOnFocus &&
|
|
276
|
+
isFocusedRef.current &&
|
|
277
|
+
!currentOpen &&
|
|
278
|
+
filteredItems.length > 0) {
|
|
268
279
|
onRequestOpen(event);
|
|
269
280
|
}
|
|
270
281
|
// console.debug('set filteredItems');
|
|
@@ -292,16 +303,25 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
|
292
303
|
inputRef,
|
|
293
304
|
openOnFocus,
|
|
294
305
|
currentOpen,
|
|
306
|
+
filteredItems.length,
|
|
295
307
|
onRequestOpen,
|
|
296
308
|
onInputChange,
|
|
297
|
-
applyFilterForItems,
|
|
298
309
|
items,
|
|
310
|
+
applyFilterForItems,
|
|
299
311
|
]),
|
|
300
|
-
react_1.default.useMemo(() => (react_1.default.createElement(Menu_1.default, { ref: menuRef, anchorPos: anchorPos, multiple: multiple, items: filteredItems, value: currentValue, isOpen: currentOpen
|
|
312
|
+
react_1.default.useMemo(() => (react_1.default.createElement(Menu_1.default, { ref: menuRef, anchorPos: anchorPos, multiple: multiple, items: filteredItems, value: currentValue, isOpen: currentOpen, autofocus: false, anchorElement: anchorElement, closeOutsideClick: false, getOptionSelected: getOptionSelected, onRequestClose: onRequestClose, closeOnSelect: multiple ? false : true, onSelectItem: item => {
|
|
313
|
+
if (!multiple) {
|
|
314
|
+
dispatch({
|
|
315
|
+
type: 'setPartial',
|
|
316
|
+
payload: {
|
|
317
|
+
filteredItems: applyFilterForItems(selectedItemToString(item), items),
|
|
318
|
+
},
|
|
319
|
+
});
|
|
320
|
+
}
|
|
301
321
|
if (typeof onChange === 'function') {
|
|
302
322
|
onChange(item);
|
|
303
323
|
}
|
|
304
|
-
}
|
|
324
|
+
} }, ({ index, item }, itemProps) => children({ index, item: item, inputValue }, itemProps))), [
|
|
305
325
|
anchorPos,
|
|
306
326
|
multiple,
|
|
307
327
|
filteredItems,
|
|
@@ -309,8 +329,12 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
|
309
329
|
currentOpen,
|
|
310
330
|
anchorElement,
|
|
311
331
|
getOptionSelected,
|
|
312
|
-
onChange,
|
|
313
332
|
onRequestClose,
|
|
333
|
+
dispatch,
|
|
334
|
+
applyFilterForItems,
|
|
335
|
+
selectedItemToString,
|
|
336
|
+
items,
|
|
337
|
+
onChange,
|
|
314
338
|
children,
|
|
315
339
|
inputValue,
|
|
316
340
|
])));
|
|
@@ -67,7 +67,10 @@ const ModalWrapper = props => {
|
|
|
67
67
|
const keyDown = (event) => {
|
|
68
68
|
var _a, _b, _c, _d;
|
|
69
69
|
const key = ((_a = event === null || event === void 0 ? void 0 : event.key) === null || _a === void 0 ? void 0 : _a.toLowerCase()) || '';
|
|
70
|
-
if (key === 'escape' &&
|
|
70
|
+
if (key === 'escape' &&
|
|
71
|
+
closeOnEscape &&
|
|
72
|
+
isOpenProp &&
|
|
73
|
+
TabManager_1.default.isCurrentContainer(containerRef.current)) {
|
|
71
74
|
const portal = window.document.querySelector(`#${context_1.PORTAL_ID}`);
|
|
72
75
|
const lastID = (_d = (_b = portal === null || portal === void 0 ? void 0 : portal.children) === null || _b === void 0 ? void 0 : _b[((_c = portal === null || portal === void 0 ? void 0 : portal.childNodes) === null || _c === void 0 ? void 0 : _c.length) - 1]) === null || _d === void 0 ? void 0 : _d.id;
|
|
73
76
|
if (lastID === id) {
|
|
@@ -8,7 +8,7 @@ const react_1 = __importDefault(require("react"));
|
|
|
8
8
|
const UnknownFlag_1 = __importDefault(require("./UnknownFlag"));
|
|
9
9
|
const usePhoneUtils = (params) => {
|
|
10
10
|
const { templates } = params;
|
|
11
|
-
const templatesList = templates.concat([
|
|
11
|
+
const templatesList = react_1.default.useMemo(() => templates.concat([
|
|
12
12
|
[
|
|
13
13
|
null,
|
|
14
14
|
react_1.default.createElement(UnknownFlag_1.default, { key: "unknnown" }),
|
|
@@ -17,7 +17,7 @@ const usePhoneUtils = (params) => {
|
|
|
17
17
|
'+7 987 654-32-10',
|
|
18
18
|
/^\+{0,1}.*/,
|
|
19
19
|
],
|
|
20
|
-
]);
|
|
20
|
+
]), [templates]);
|
|
21
21
|
/**
|
|
22
22
|
* Get template info by parset value
|
|
23
23
|
*/
|