@via-profit/ui-kit 0.1.0-rc.72 → 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
  /**
@@ -168,13 +168,11 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
168
168
  }, [filteredItems]);
169
169
  react_1.default.useEffect(() => {
170
170
  if (currentOpen !== isOpen || currentLoading !== isLoading) {
171
- // console.debug('Use effect 1', { currentOpen: isOpen, currentLoading: isLoading });
172
171
  dispatch((0, context_1.actionSetPartial)({ currentOpen: isOpen, currentLoading: isLoading }));
173
172
  }
174
173
  }, [isOpen, isLoading, dispatch, currentOpen, currentLoading]);
175
174
  react_1.default.useEffect(() => {
176
175
  if (JSON.stringify(items) !== JSON.stringify(itemsRef.current)) {
177
- // console.debug('Use effect 2', { filteredItems: applyFilterForItems(inputValue, items) });
178
176
  itemsRef.current = items;
179
177
  dispatch((0, context_1.actionSetPartial)({ filteredItems: applyFilterForItems(inputValue, items) }));
180
178
  }
@@ -191,15 +189,34 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
191
189
  }
192
190
  parentElem = parentElem.parentNode;
193
191
  }
192
+ // Click outside
194
193
  if (needToClose) {
195
- onRequestClose(event);
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
+ }
196
204
  }
197
205
  };
198
206
  window.document.addEventListener(ClickOutside_1.mouseEventMap.onMouseDown, mouseDownEvent);
199
207
  return () => {
200
208
  window.document.removeEventListener(ClickOutside_1.mouseEventMap.onMouseDown, mouseDownEvent);
201
209
  };
202
- }, [onRequestClose, anchorElement]);
210
+ }, [
211
+ onRequestClose,
212
+ anchorElement,
213
+ isOpen,
214
+ clearIfNotSelected,
215
+ dispatch,
216
+ value,
217
+ selectedItemToString,
218
+ currentValue,
219
+ ]);
203
220
  return (react_1.default.createElement(react_1.default.Fragment, null,
204
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 => {
205
222
  inputKeydownEvent(event);
@@ -284,18 +301,7 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
284
301
  if (typeof onChange === 'function') {
285
302
  onChange(item);
286
303
  }
287
- }, closeOnSelect: multiple ? false : true, onRequestClose: evt => {
288
- if (clearIfNotSelected) {
289
- dispatch((0, context_1.actionSetPartial)({
290
- inputValue: value !== null
291
- ? selectedItemToString(value)
292
- : '',
293
- }));
294
- }
295
- if ((evt === null || evt === void 0 ? void 0 : evt.target) !== anchorElement) {
296
- onRequestClose(evt);
297
- }
298
- } }, ({ 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))), [
299
305
  anchorPos,
300
306
  multiple,
301
307
  filteredItems,
@@ -304,10 +310,6 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
304
310
  anchorElement,
305
311
  getOptionSelected,
306
312
  onChange,
307
- clearIfNotSelected,
308
- dispatch,
309
- value,
310
- selectedItemToString,
311
313
  onRequestClose,
312
314
  children,
313
315
  inputValue,
@@ -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(menuIsOpen);
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
- }, [menuIsOpen, onRequestClose, anchorElement, closeOutsideClick]);
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@via-profit/ui-kit",
3
- "version": "0.1.0-rc.72",
3
+ "version": "0.1.0-rc.73",
4
4
  "description": "UI Kit",
5
5
  "repository": {
6
6
  "type": "git",