@via-profit/ui-kit 0.1.0-rc.71 → 0.1.0-rc.73
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.
|
@@ -31,11 +31,13 @@ export interface AutocompleteProps<T, Multiple extends boolean | undefined = und
|
|
|
31
31
|
*/
|
|
32
32
|
readonly isLoading?: boolean;
|
|
33
33
|
/**
|
|
34
|
-
* Should the autocomplete element be cleared when blur and if no element is selected
|
|
34
|
+
* Should the autocomplete element be cleared when blur and if no element is selected\
|
|
35
|
+
* **Default:** `true`
|
|
35
36
|
*/
|
|
36
37
|
readonly clearIfNotSelected?: boolean;
|
|
37
38
|
/**
|
|
38
|
-
* Show clear button if clearable is true
|
|
39
|
+
* Show clear button if clearable is true\
|
|
40
|
+
* **Default:** `true`
|
|
39
41
|
*/
|
|
40
42
|
readonly clearable?: boolean;
|
|
41
43
|
/**
|
|
@@ -84,8 +84,10 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
|
84
84
|
switch (event.code) {
|
|
85
85
|
case 'Enter':
|
|
86
86
|
case 'NumpadEnter':
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
if (currentOpen) {
|
|
88
|
+
event.preventDefault();
|
|
89
|
+
(_a = menuRef.current) === null || _a === void 0 ? void 0 : _a.selectHightlightedItem();
|
|
90
|
+
}
|
|
89
91
|
break;
|
|
90
92
|
case 'ArrowUp':
|
|
91
93
|
{
|
|
@@ -166,13 +168,11 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
|
166
168
|
}, [filteredItems]);
|
|
167
169
|
react_1.default.useEffect(() => {
|
|
168
170
|
if (currentOpen !== isOpen || currentLoading !== isLoading) {
|
|
169
|
-
// console.debug('Use effect 1', { currentOpen: isOpen, currentLoading: isLoading });
|
|
170
171
|
dispatch((0, context_1.actionSetPartial)({ currentOpen: isOpen, currentLoading: isLoading }));
|
|
171
172
|
}
|
|
172
173
|
}, [isOpen, isLoading, dispatch, currentOpen, currentLoading]);
|
|
173
174
|
react_1.default.useEffect(() => {
|
|
174
175
|
if (JSON.stringify(items) !== JSON.stringify(itemsRef.current)) {
|
|
175
|
-
// console.debug('Use effect 2', { filteredItems: applyFilterForItems(inputValue, items) });
|
|
176
176
|
itemsRef.current = items;
|
|
177
177
|
dispatch((0, context_1.actionSetPartial)({ filteredItems: applyFilterForItems(inputValue, items) }));
|
|
178
178
|
}
|
|
@@ -189,15 +189,34 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
|
189
189
|
}
|
|
190
190
|
parentElem = parentElem.parentNode;
|
|
191
191
|
}
|
|
192
|
+
// Click outside
|
|
192
193
|
if (needToClose) {
|
|
193
|
-
|
|
194
|
+
if (clearIfNotSelected) {
|
|
195
|
+
dispatch((0, context_1.actionSetPartial)({
|
|
196
|
+
inputValue: currentValue === null
|
|
197
|
+
? ''
|
|
198
|
+
: selectedItemToString(currentValue),
|
|
199
|
+
}));
|
|
200
|
+
}
|
|
201
|
+
if (isOpen) {
|
|
202
|
+
onRequestClose(event);
|
|
203
|
+
}
|
|
194
204
|
}
|
|
195
205
|
};
|
|
196
206
|
window.document.addEventListener(ClickOutside_1.mouseEventMap.onMouseDown, mouseDownEvent);
|
|
197
207
|
return () => {
|
|
198
208
|
window.document.removeEventListener(ClickOutside_1.mouseEventMap.onMouseDown, mouseDownEvent);
|
|
199
209
|
};
|
|
200
|
-
}, [
|
|
210
|
+
}, [
|
|
211
|
+
onRequestClose,
|
|
212
|
+
anchorElement,
|
|
213
|
+
isOpen,
|
|
214
|
+
clearIfNotSelected,
|
|
215
|
+
dispatch,
|
|
216
|
+
value,
|
|
217
|
+
selectedItemToString,
|
|
218
|
+
currentValue,
|
|
219
|
+
]);
|
|
201
220
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
202
221
|
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 => {
|
|
203
222
|
inputKeydownEvent(event);
|
|
@@ -282,18 +301,7 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
|
282
301
|
if (typeof onChange === 'function') {
|
|
283
302
|
onChange(item);
|
|
284
303
|
}
|
|
285
|
-
}, closeOnSelect: multiple ? false : true,
|
|
286
|
-
if (clearIfNotSelected) {
|
|
287
|
-
dispatch((0, context_1.actionSetPartial)({
|
|
288
|
-
inputValue: value !== null
|
|
289
|
-
? selectedItemToString(value)
|
|
290
|
-
: '',
|
|
291
|
-
}));
|
|
292
|
-
}
|
|
293
|
-
if ((evt === null || evt === void 0 ? void 0 : evt.target) !== anchorElement) {
|
|
294
|
-
onRequestClose(evt);
|
|
295
|
-
}
|
|
296
|
-
} }, ({ index, item }, itemProps) => children({ index, item: item, inputValue }, itemProps))), [
|
|
304
|
+
}, onRequestClose: onRequestClose, closeOnSelect: multiple ? false : true }, ({ index, item }, itemProps) => children({ index, item: item, inputValue }, itemProps))), [
|
|
297
305
|
anchorPos,
|
|
298
306
|
multiple,
|
|
299
307
|
filteredItems,
|
|
@@ -302,10 +310,6 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
|
302
310
|
anchorElement,
|
|
303
311
|
getOptionSelected,
|
|
304
312
|
onChange,
|
|
305
|
-
clearIfNotSelected,
|
|
306
|
-
dispatch,
|
|
307
|
-
value,
|
|
308
|
-
selectedItemToString,
|
|
309
313
|
onRequestClose,
|
|
310
314
|
children,
|
|
311
315
|
inputValue,
|
package/Menu/MenuContainer.js
CHANGED
|
@@ -61,10 +61,8 @@ const MenuContainer = react_1.default.forwardRef((props, ref) => {
|
|
|
61
61
|
}
|
|
62
62
|
return [...idx];
|
|
63
63
|
}, [getOptionSelected, items, multiple, value]);
|
|
64
|
-
// const [currentAnchorPos, setCurrentAnchorPos] = React.useState(anchorPos);
|
|
65
|
-
const [menuIsOpen, setMenuOpen] = react_1.default.useState(Boolean(isOpen));
|
|
66
64
|
const [currentAnchorElement, setAnchorElement] = react_1.default.useState(anchorElement);
|
|
67
|
-
const isOpenRef = react_1.default.useRef(
|
|
65
|
+
const isOpenRef = react_1.default.useRef(isOpen);
|
|
68
66
|
const menuListRef = react_1.default.useRef(null);
|
|
69
67
|
const menuPopperRef = react_1.default.useRef(null);
|
|
70
68
|
const { dispatch, state: { selectedIndexes, markedIndex, hoveredIndex }, } = (0, context_1.default)();
|
|
@@ -291,14 +289,17 @@ const MenuContainer = react_1.default.forwardRef((props, ref) => {
|
|
|
291
289
|
return () => {
|
|
292
290
|
window.document.removeEventListener('resize', windowResizeEvent);
|
|
293
291
|
};
|
|
294
|
-
}, [
|
|
292
|
+
}, [isOpen, onRequestClose, anchorElement, closeOutsideClick]);
|
|
295
293
|
/**
|
|
296
294
|
* Toggle menu open
|
|
297
295
|
*/
|
|
298
296
|
react_1.default.useEffect(() => {
|
|
299
297
|
if (isOpenRef.current !== isOpen) {
|
|
300
298
|
isOpenRef.current = Boolean(isOpen);
|
|
301
|
-
setMenuOpen(Boolean(isOpen));
|
|
299
|
+
// setMenuOpen(Boolean(isOpen));
|
|
300
|
+
if (!isOpen) {
|
|
301
|
+
onRequestClose();
|
|
302
|
+
}
|
|
302
303
|
if (isOpen) {
|
|
303
304
|
scrollToFirstSelected();
|
|
304
305
|
if (autofocus) {
|
|
@@ -314,7 +315,7 @@ const MenuContainer = react_1.default.forwardRef((props, ref) => {
|
|
|
314
315
|
dispatch((0, context_1.actionSetmenuState)({ markedIndex: -1, hoveredIndex: -1 }));
|
|
315
316
|
}
|
|
316
317
|
}
|
|
317
|
-
}, [getSelectedIndexes, scrollToFirstSelected, isOpen, autofocus, dispatch]);
|
|
318
|
+
}, [getSelectedIndexes, scrollToFirstSelected, isOpen, autofocus, dispatch, onRequestClose]);
|
|
318
319
|
/**
|
|
319
320
|
* Mark selected items by values
|
|
320
321
|
*/
|
package/Menu/MenuItem.js
CHANGED
|
@@ -20,6 +20,8 @@ const react_2 = require("@emotion/react");
|
|
|
20
20
|
const InnerContainer = styled_1.default.div `
|
|
21
21
|
cursor: pointer;
|
|
22
22
|
user-select: none;
|
|
23
|
+
display: flex;
|
|
24
|
+
align-items: center;
|
|
23
25
|
padding: 0.4em 0.8em;
|
|
24
26
|
transition: all 240ms ease-out;
|
|
25
27
|
border-radius: ${({ theme }) => theme.shape.radiusFactor}em;
|