@laerdal/life-react-components 1.7.0-dev.9 → 1.8.0

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 (176) hide show
  1. package/dist/Button/BackButton.cjs +3 -0
  2. package/dist/Button/BackButton.cjs.map +1 -1
  3. package/dist/Button/BackButton.js +2 -0
  4. package/dist/Button/BackButton.js.map +1 -1
  5. package/dist/Button/Button.cjs +3 -4
  6. package/dist/Button/Button.cjs.map +1 -1
  7. package/dist/Button/Button.d.ts +1 -1
  8. package/dist/Button/Button.js +3 -4
  9. package/dist/Button/Button.js.map +1 -1
  10. package/dist/Button/DualFunctionButton.cjs +29 -7
  11. package/dist/Button/DualFunctionButton.cjs.map +1 -1
  12. package/dist/Button/DualFunctionButton.js +27 -6
  13. package/dist/Button/DualFunctionButton.js.map +1 -1
  14. package/dist/Button/Iconbutton.cjs +14 -10
  15. package/dist/Button/Iconbutton.cjs.map +1 -1
  16. package/dist/Button/Iconbutton.d.ts +1 -0
  17. package/dist/Button/Iconbutton.js +10 -9
  18. package/dist/Button/Iconbutton.js.map +1 -1
  19. package/dist/Card/CardBottomSection.cjs +32 -16
  20. package/dist/Card/CardBottomSection.cjs.map +1 -1
  21. package/dist/Card/CardBottomSection.d.ts +10 -0
  22. package/dist/Card/CardBottomSection.js +15 -15
  23. package/dist/Card/CardBottomSection.js.map +1 -1
  24. package/dist/Card/CardMiddleSection.cjs +37 -11
  25. package/dist/Card/CardMiddleSection.cjs.map +1 -1
  26. package/dist/Card/CardMiddleSection.d.ts +16 -1
  27. package/dist/Card/CardMiddleSection.js +28 -10
  28. package/dist/Card/CardMiddleSection.js.map +1 -1
  29. package/dist/Card/CardTopSection.cjs +21 -11
  30. package/dist/Card/CardTopSection.cjs.map +1 -1
  31. package/dist/Card/CardTopSection.d.ts +10 -0
  32. package/dist/Card/CardTopSection.js +10 -10
  33. package/dist/Card/CardTopSection.js.map +1 -1
  34. package/dist/Card/index.cjs +51 -3
  35. package/dist/Card/index.cjs.map +1 -1
  36. package/dist/Card/index.d.ts +3 -0
  37. package/dist/Card/index.js +3 -0
  38. package/dist/Card/index.js.map +1 -1
  39. package/dist/Chips/ChipStyles.cjs +3 -3
  40. package/dist/Chips/ChipStyles.cjs.map +1 -1
  41. package/dist/Chips/ChipStyles.js +3 -3
  42. package/dist/Chips/ChipStyles.js.map +1 -1
  43. package/dist/Chips/ChipTypes.d.ts +2 -2
  44. package/dist/Chips/InputChip.cjs +18 -9
  45. package/dist/Chips/InputChip.cjs.map +1 -1
  46. package/dist/Chips/InputChip.js +17 -9
  47. package/dist/Chips/InputChip.js.map +1 -1
  48. package/dist/ChipsInput/ChipDropdownInput.cjs +16 -13
  49. package/dist/ChipsInput/ChipDropdownInput.cjs.map +1 -1
  50. package/dist/ChipsInput/ChipDropdownInput.js +15 -14
  51. package/dist/ChipsInput/ChipDropdownInput.js.map +1 -1
  52. package/dist/ChipsInput/ChipInput.cjs +1 -1
  53. package/dist/ChipsInput/ChipInput.cjs.map +1 -1
  54. package/dist/ChipsInput/ChipInput.js +1 -1
  55. package/dist/ChipsInput/ChipInput.js.map +1 -1
  56. package/dist/ChipsInput/ChipInputField.cjs +98 -53
  57. package/dist/ChipsInput/ChipInputField.cjs.map +1 -1
  58. package/dist/ChipsInput/ChipInputField.d.ts +3 -2
  59. package/dist/ChipsInput/ChipInputField.js +91 -51
  60. package/dist/ChipsInput/ChipInputField.js.map +1 -1
  61. package/dist/Dropdown/BasicDropdown.cjs +30 -11
  62. package/dist/Dropdown/BasicDropdown.cjs.map +1 -1
  63. package/dist/Dropdown/BasicDropdown.js +32 -12
  64. package/dist/Dropdown/BasicDropdown.js.map +1 -1
  65. package/dist/Dropdown/CommonStyling.cjs +7 -7
  66. package/dist/Dropdown/CommonStyling.cjs.map +1 -1
  67. package/dist/Dropdown/CommonStyling.js +7 -7
  68. package/dist/Dropdown/CommonStyling.js.map +1 -1
  69. package/dist/Dropdown/DropdownButton.cjs +22 -15
  70. package/dist/Dropdown/DropdownButton.cjs.map +1 -1
  71. package/dist/Dropdown/DropdownButton.js +21 -15
  72. package/dist/Dropdown/DropdownButton.js.map +1 -1
  73. package/dist/Dropdown/DropdownContent.cjs +164 -124
  74. package/dist/Dropdown/DropdownContent.cjs.map +1 -1
  75. package/dist/Dropdown/DropdownContent.d.ts +2 -2
  76. package/dist/Dropdown/DropdownContent.js +161 -125
  77. package/dist/Dropdown/DropdownContent.js.map +1 -1
  78. package/dist/Dropdown/DropdownFilter.cjs +66 -24
  79. package/dist/Dropdown/DropdownFilter.cjs.map +1 -1
  80. package/dist/Dropdown/DropdownFilter.js +65 -25
  81. package/dist/Dropdown/DropdownFilter.js.map +1 -1
  82. package/dist/GlobalNavigationBar/MainMenu.cjs +0 -1
  83. package/dist/GlobalNavigationBar/MainMenu.cjs.map +1 -1
  84. package/dist/GlobalNavigationBar/MainMenu.js +0 -1
  85. package/dist/GlobalNavigationBar/MainMenu.js.map +1 -1
  86. package/dist/GlobalNavigationBar/UserMenu/MenuLink.cjs +4 -0
  87. package/dist/GlobalNavigationBar/UserMenu/MenuLink.cjs.map +1 -1
  88. package/dist/GlobalNavigationBar/UserMenu/MenuLink.js +3 -0
  89. package/dist/GlobalNavigationBar/UserMenu/MenuLink.js.map +1 -1
  90. package/dist/Image/ImageWithFallbacks.cjs +3 -1
  91. package/dist/Image/ImageWithFallbacks.cjs.map +1 -1
  92. package/dist/Image/ImageWithFallbacks.js +3 -1
  93. package/dist/Image/ImageWithFallbacks.js.map +1 -1
  94. package/dist/InputFields/Checkbox.cjs +11 -8
  95. package/dist/InputFields/Checkbox.cjs.map +1 -1
  96. package/dist/InputFields/Checkbox.d.ts +1 -0
  97. package/dist/InputFields/Checkbox.js +11 -8
  98. package/dist/InputFields/Checkbox.js.map +1 -1
  99. package/dist/InputFields/RadioButton.cjs +10 -7
  100. package/dist/InputFields/RadioButton.cjs.map +1 -1
  101. package/dist/InputFields/RadioButton.d.ts +1 -0
  102. package/dist/InputFields/RadioButton.js +10 -7
  103. package/dist/InputFields/RadioButton.js.map +1 -1
  104. package/dist/LoadingIndicator/LoadingIndicator.cjs +6 -1
  105. package/dist/LoadingIndicator/LoadingIndicator.cjs.map +1 -1
  106. package/dist/LoadingIndicator/LoadingIndicator.d.ts +2 -1
  107. package/dist/LoadingIndicator/LoadingIndicator.js +6 -1
  108. package/dist/LoadingIndicator/LoadingIndicator.js.map +1 -1
  109. package/dist/MenuItem/MenuItem.cjs +5 -2
  110. package/dist/MenuItem/MenuItem.cjs.map +1 -1
  111. package/dist/MenuItem/MenuItem.d.ts +1 -0
  112. package/dist/MenuItem/MenuItem.js +5 -2
  113. package/dist/MenuItem/MenuItem.js.map +1 -1
  114. package/dist/Modals/ModalDialog.cjs +16 -9
  115. package/dist/Modals/ModalDialog.cjs.map +1 -1
  116. package/dist/Modals/ModalDialog.d.ts +1 -0
  117. package/dist/Modals/ModalDialog.js +17 -10
  118. package/dist/Modals/ModalDialog.js.map +1 -1
  119. package/dist/Modals/ModalStyles.cjs +32 -18
  120. package/dist/Modals/ModalStyles.cjs.map +1 -1
  121. package/dist/Modals/ModalStyles.d.ts +7 -1
  122. package/dist/Modals/ModalStyles.js +25 -17
  123. package/dist/Modals/ModalStyles.js.map +1 -1
  124. package/dist/Toggles/ToggleButton.cjs +81 -0
  125. package/dist/Toggles/ToggleButton.cjs.map +1 -0
  126. package/dist/Toggles/ToggleButton.d.ts +14 -0
  127. package/dist/Toggles/ToggleButton.js +59 -0
  128. package/dist/Toggles/ToggleButton.js.map +1 -0
  129. package/dist/Toggles/ToggleSwitch.cjs +4 -0
  130. package/dist/Toggles/ToggleSwitch.cjs.map +1 -1
  131. package/dist/Toggles/ToggleSwitch.js +3 -0
  132. package/dist/Toggles/ToggleSwitch.js.map +1 -1
  133. package/dist/Toggles/TogglerStyles.cjs +1 -1
  134. package/dist/Toggles/TogglerStyles.cjs.map +1 -1
  135. package/dist/Toggles/TogglerStyles.js +1 -1
  136. package/dist/Toggles/TogglerStyles.js.map +1 -1
  137. package/dist/Toggles/index.cjs +8 -0
  138. package/dist/Toggles/index.cjs.map +1 -1
  139. package/dist/Toggles/index.d.ts +2 -1
  140. package/dist/Toggles/index.js +2 -1
  141. package/dist/Toggles/index.js.map +1 -1
  142. package/dist/common/{HoverWithin.cjs → ActionWithin.cjs} +9 -5
  143. package/dist/common/ActionWithin.cjs.map +1 -0
  144. package/dist/common/{HoverWithin.d.ts → ActionWithin.d.ts} +0 -0
  145. package/dist/common/{HoverWithin.js → ActionWithin.js} +9 -5
  146. package/dist/common/ActionWithin.js.map +1 -0
  147. package/dist/common/ClickOutside.cjs +39 -0
  148. package/dist/common/ClickOutside.cjs.map +1 -0
  149. package/dist/common/ClickOutside.d.ts +1 -0
  150. package/dist/common/ClickOutside.js +25 -0
  151. package/dist/common/ClickOutside.js.map +1 -0
  152. package/dist/common/FocusOutside.cjs +39 -0
  153. package/dist/common/FocusOutside.cjs.map +1 -0
  154. package/dist/common/FocusOutside.d.ts +1 -0
  155. package/dist/common/FocusOutside.js +25 -0
  156. package/dist/common/FocusOutside.js.map +1 -0
  157. package/dist/common/FocusVisible.cjs +43 -18
  158. package/dist/common/FocusVisible.cjs.map +1 -1
  159. package/dist/common/FocusVisible.js +42 -18
  160. package/dist/common/FocusVisible.js.map +1 -1
  161. package/dist/common/InputStyling.cjs +1 -1
  162. package/dist/common/InputStyling.cjs.map +1 -1
  163. package/dist/common/InputStyling.js +1 -1
  164. package/dist/common/InputStyling.js.map +1 -1
  165. package/dist/common/index.cjs +18 -2
  166. package/dist/common/index.cjs.map +1 -1
  167. package/dist/common/index.d.ts +3 -1
  168. package/dist/common/index.js +3 -1
  169. package/dist/common/index.js.map +1 -1
  170. package/dist/icons/index.cjs +1 -1
  171. package/dist/icons/index.cjs.map +1 -1
  172. package/dist/icons/index.js +1 -1
  173. package/dist/icons/index.js.map +1 -1
  174. package/package.json +1 -1
  175. package/dist/common/HoverWithin.cjs.map +0 -1
  176. package/dist/common/HoverWithin.js.map +0 -1
@@ -39,11 +39,21 @@ var _jsxRuntime = require("react/jsx-runtime");
39
39
 
40
40
  var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7;
41
41
 
42
- var DDContainer = _styledComponents.default.div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n display: none;\n position: absolute;\n background-color: ", ";\n\n width: ", ";\n z-index: ", ";\n margin: ", ";\n\n &.show {\n display: flex;\n flex-direction: column;\n justify-content: center;\n }\n\n &.up {\n top: auto;\n bottom: 100%;\n }\n\n ", "\n\n ", ";\n\n border: 1px solid ", ";\n box-sizing: border-box;\n box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.15);\n padding-top: 4px;\n padding-right: 0px;\n padding-bottom: 4px;\n padding-left: 0px;\n\n min-width: ", ";\n border-radius: ", ";\n\n max-height: ", ";\n \n ", ";\n"])), _styles.COLORS.white, function (props) {
42
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
43
+
44
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
45
+
46
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
47
+
48
+ var MAX_MENU_HEIGHT = 240;
49
+ var AVG_OPTION_HEIGHT = 48;
50
+ var OFFSET_BEFORE_SHOW = 1000000;
51
+
52
+ var DDContainer = _styledComponents.default.div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n display: none;\n position: absolute;\n background-color: ", ";\n\n width: ", ";\n z-index: ", ";\n margin: ", ";\n\n &.show {\n display: flex;\n flex-direction: column;\n justify-content: center;\n }\n\n &.up {\n top: auto;\n bottom: 100%;\n }\n\n transform: translate(-", "px, -", "px);\n\n &.up,\n &.down {\n transform: translate(0, 0);\n }\n\n &.outline:focus:after {\n content: '';\n pointer-events: none;\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n outline: 4px solid black;\n outline-offset: 2px;\n border-radius: 2px;\n }\n\n &:focus {\n outline: none;\n }\n\n ", "\n\n ", ";\n\n border: 1px solid ", ";\n box-sizing: border-box;\n box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.15);\n padding: 4px 0px;\n\n min-width: ", ";\n border-radius: ", ";\n\n max-height: ", ";\n\n"])), _styles.COLORS.white, function (props) {
43
53
  return props.width ? props.width : '100%';
44
54
  }, _zIndexes.Z_INDEXES.dropdown, function (props) {
45
55
  return props.isButton ? '-4px' : '4px 0px';
46
- }, function (props) {
56
+ }, OFFSET_BEFORE_SHOW, OFFSET_BEFORE_SHOW, function (props) {
47
57
  return props.alignLeft ? 'left: 0px;' : '';
48
58
  }, function (props) {
49
59
  return props.isButton ? _CommonStyling.ButtonDropdownContentStyling : '';
@@ -53,15 +63,13 @@ var DDContainer = _styledComponents.default.div(_templateObject || (_templateObj
53
63
  return props.size == _types.Size.Large ? '10px' : props.size == _types.Size.Medium ? '8px' : '6px';
54
64
  }, function (props) {
55
65
  return !props.scrollable ? 'auto' : props.maxHeight ? props.maxHeight : props.size == _types.Size.Large ? '320px' : props.size == _types.Size.Medium ? '280px' : '240px';
56
- }, function (props) {
57
- return !!props.scrollable ? '* { outline-offset: -4px !important;}' : '';
58
66
  });
59
67
 
60
68
  exports.DDContainer = DDContainer;
61
69
 
62
70
  var ItemsContainer = _styledComponents.default.div(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2.default)(["\n > *:hover {\n z-index: ", ";\n }\n\n > *:active,\n > *.active {\n z-index: ", ";\n }\n\n > *:focus {\n z-index: ", ";\n }\n"])), _zIndexes.Z_INDEXES.hover, _zIndexes.Z_INDEXES.active, _zIndexes.Z_INDEXES.focus);
63
71
 
64
- var ListContainer = _styledComponents.default.div(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2.default)(["\n ", "\n ", "\n ", "\n ", "\n div.divider {\n display: block;\n width: calc(100% - 40px);\n margin-left: 16px;\n border-top: 1px solid #e5e5e5;\n position: absolute;\n top: 0px;\n }\n\n ", " {\n padding-top: ", ";\n padding-bottom: ", ";\n\n word-break: break-word;\n }\n\n ", "\n"])), function (props) {
72
+ var ListContainer = _styledComponents.default.div(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2.default)(["\n ", "\n ", "\n ", "\n ", "\n div.divider {\n display: block;\n width: calc(100% - 40px);\n margin-left: 16px;\n border-top: 1px solid #e5e5e5;\n position: absolute;\n top: 0px;\n }\n\n ", " {\n padding-top: ", ";\n padding-bottom: ", ";\n\n word-break: break-word;\n }\n\n *:focus {\n outline: none !important;\n }\n\n ", "\n"])), function (props) {
65
73
  return props.scrollable ? 'overflow-y: scroll;' : '';
66
74
  }, function (props) {
67
75
  return props.scrollable ? 'margin-right: 6px;' : '';
@@ -107,11 +115,8 @@ var ActionButtonContainer = _styledComponents.default.div(_templateObject7 || (_
107
115
  return props.size === _types.Size.Small || !props.size ? '4px 16px 0px' : props.size === _types.Size.Medium ? '12px 16px 8px' : '16px 16px 12px';
108
116
  });
109
117
 
110
- var MAX_MENU_HEIGHT = 240;
111
- var AVG_OPTION_HEIGHT = 48;
112
-
113
- var DropdownContent = function DropdownContent(_ref) {
114
- var _customizationProps$a;
118
+ var DropdownContent = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
119
+ var _ref2, _customizationProps$a;
115
120
 
116
121
  var id = _ref.id,
117
122
  customizationProps = _ref.customizationProps,
@@ -119,7 +124,6 @@ var DropdownContent = function DropdownContent(_ref) {
119
124
  isButton = _ref.isButton,
120
125
  size = _ref.size,
121
126
  isOpen = _ref.isOpen,
122
- hideOnClickOutside = _ref.hideOnClickOutside,
123
127
  width = _ref.width,
124
128
  setIsOpen = _ref.setIsOpen,
125
129
  filter = _ref.filter,
@@ -127,38 +131,55 @@ var DropdownContent = function DropdownContent(_ref) {
127
131
  setFocused = _ref.setFocused,
128
132
  selectedValues = _ref.selectedValues,
129
133
  setSelectedValues = _ref.setSelectedValues,
130
- messageOnNoResults = _ref.messageOnNoResults;
134
+ messageOnNoResults = _ref.messageOnNoResults,
135
+ outline = _ref.outline;
131
136
 
132
137
  var _React$useState = _react.default.useState(false),
133
138
  _React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
134
139
  isUp = _React$useState2[0],
135
140
  setIsUp = _React$useState2[1];
136
141
 
137
- var dropdownContentRef = _react.default.useRef(null);
142
+ var _React$useState3 = _react.default.useState(false),
143
+ _React$useState4 = (0, _slicedToArray2.default)(_React$useState3, 2),
144
+ locationDefined = _React$useState4[0],
145
+ setLocationDefined = _React$useState4[1];
138
146
 
147
+ var dropdownContentRef = (_ref2 = ref) !== null && _ref2 !== void 0 ? _ref2 : _react.default.useRef(null);
139
148
  if (!customizationProps.itemsType) customizationProps.itemsType = 'normal';
140
149
  if (!size) size = _types.Size.Small;
141
150
 
142
151
  var itemsListRef = _react.default.useRef(null);
143
152
 
153
+ var actionButtonRef = _react.default.useRef(null);
154
+
144
155
  var determineDropUp = function determineDropUp() {
145
156
  var options = customizationProps.items;
146
157
  var node = dropdownContentRef.current;
147
158
  if (!node) return;
148
159
  var windowHeight = window.innerHeight;
149
160
  var menuHeight = Math.min(MAX_MENU_HEIGHT, options.length * AVG_OPTION_HEIGHT);
150
- var instOffsetWithMenu = node.getBoundingClientRect().top + menuHeight;
161
+ var instOffsetWithMenu = node.getBoundingClientRect().top + menuHeight + OFFSET_BEFORE_SHOW;
151
162
  setIsUp(instOffsetWithMenu >= windowHeight);
163
+ setLocationDefined(true);
152
164
  };
153
165
 
154
166
  var setNewFocusedElement = function setNewFocusedElement(index) {
167
+ var _dropdownContentRef$c;
168
+
169
+ if (outline) (_dropdownContentRef$c = dropdownContentRef.current) === null || _dropdownContentRef$c === void 0 ? void 0 : _dropdownContentRef$c.focus();
155
170
  var newFocusedElement = elRefs[index];
171
+ var oldFocusedElement = focused || focused === 0 ? elRefs[focused] : null;
156
172
 
157
- if (newFocusedElement) {
158
- var _newFocusedElement$cu;
173
+ if (newFocusedElement && newFocusedElement !== oldFocusedElement) {
174
+ var _oldFocusedElement$cu, _newFocusedElement$cu, _newFocusedElement$cu2;
159
175
 
160
176
  setFocused(index);
161
- newFocusedElement === null || newFocusedElement === void 0 ? void 0 : (_newFocusedElement$cu = newFocusedElement.current) === null || _newFocusedElement$cu === void 0 ? void 0 : _newFocusedElement$cu.focus();
177
+ oldFocusedElement === null || oldFocusedElement === void 0 ? void 0 : (_oldFocusedElement$cu = oldFocusedElement.current) === null || _oldFocusedElement$cu === void 0 ? void 0 : _oldFocusedElement$cu.classList.remove('dropdown-hover');
178
+ (_newFocusedElement$cu = newFocusedElement.current) === null || _newFocusedElement$cu === void 0 ? void 0 : _newFocusedElement$cu.classList.add('dropdown-hover');
179
+ (_newFocusedElement$cu2 = newFocusedElement.current) === null || _newFocusedElement$cu2 === void 0 ? void 0 : _newFocusedElement$cu2.scrollIntoView({
180
+ block: 'nearest',
181
+ inline: 'nearest'
182
+ });
162
183
  }
163
184
  };
164
185
 
@@ -171,88 +192,53 @@ var DropdownContent = function DropdownContent(_ref) {
171
192
  });
172
193
  };
173
194
 
195
+ var findNextActiveIndex = function findNextActiveIndex(index, direction, items) {
196
+ for (var i = index + direction; i > 0 && i <= items.length; i += direction) {
197
+ var _items;
198
+
199
+ if (!((_items = items[i - 1]) !== null && _items !== void 0 && _items.disabled)) {
200
+ return i;
201
+ }
202
+ }
203
+
204
+ return index;
205
+ };
206
+
174
207
  var handleKeyDown = function handleKeyDown(e) {
175
208
  if (isOpen) {
176
209
  if (e.key === 'ArrowUp' || e.key === 'Up') {
177
210
  e.preventDefault();
178
- var focusedNow = focused;
179
-
180
- if (focusedNow !== undefined && focusedNow !== null && focusedNow > 0) {
181
- var filtered = getFilteredItems();
182
- if (focusedNow === 1 && haveTopItem()) focusedNow = 0;else {
183
- for (var i = focusedNow - 1; i > 0; i--) {
184
- var _filtered;
185
-
186
- if (!((_filtered = filtered[i - 1]) !== null && _filtered !== void 0 && _filtered.disabled)) {
187
- focusedNow = i;
188
- break;
189
- }
190
- }
191
- }
211
+ var focusedNow = focused || focused === 0 ? focused : arrLength + 1;
212
+
213
+ if (!!focusedNow) {
214
+ focusedNow = focusedNow === 1 && haveTopItem() ? 0 : findNextActiveIndex(focusedNow, -1, getFilteredItems());
192
215
  setNewFocusedElement(focusedNow);
193
216
  }
194
217
  } else if (e.key === 'ArrowDown' || e.key === 'Down') {
195
218
  e.preventDefault();
196
219
  var _focusedNow = focused;
197
-
198
- if (_focusedNow !== undefined && _focusedNow !== null) {
199
- var _filtered2 = getFilteredItems();
200
-
201
- for (var _i = _focusedNow + 1; _i <= _filtered2.length; _i++) {
202
- var _filtered3;
203
-
204
- if (!((_filtered3 = _filtered2[_i - 1]) !== null && _filtered3 !== void 0 && _filtered3.disabled)) {
205
- _focusedNow = _i;
206
- break;
207
- }
208
- }
209
- } else {
210
- _focusedNow = haveTopItem() ? 0 : 1;
211
- }
212
-
220
+ _focusedNow = !!_focusedNow || _focusedNow === 0 ? findNextActiveIndex(_focusedNow, 1, getFilteredItems()) : haveTopItem() ? 0 : 1;
213
221
  setNewFocusedElement(_focusedNow);
214
- } else if (e.key === 'Tab') {
215
- var _focusedNow2 = focused;
216
-
217
- if (_focusedNow2 !== undefined && _focusedNow2 !== null) {
218
- e.preventDefault();
219
- e.shiftKey ? _focusedNow2-- : _focusedNow2++;
220
- var newFocusedElement = document.getElementById("".concat(id, "_").concat(_focusedNow2));
221
-
222
- if (!newFocusedElement) {
223
- setNewFocusedElement(0);
224
- } else {
225
- setNewFocusedElement(_focusedNow2);
226
- }
227
- } else {
228
- setFocused(null);
229
- }
230
222
  } else if (e.key === 'Escape' || e.key === 'Esc') {
231
223
  setIsOpen(false);
232
224
  setFocused(null);
233
- }
234
- }
235
- };
225
+ } else if ((e.key === 'Enter' || e.key === ' ') && focused !== null && e.target !== (actionButtonRef === null || actionButtonRef === void 0 ? void 0 : actionButtonRef.current)) {
226
+ e.preventDefault();
227
+ var focusedElement = elRefs[focused];
236
228
 
237
- var handleClickOutside = function handleClickOutside(e) {
238
- if (hideOnClickOutside && dropdownContentRef !== null && dropdownContentRef !== void 0 && dropdownContentRef.current && !dropdownContentRef.current.contains(e.target) && !elRefs.some(function (x) {
239
- var _x$current;
229
+ if (focusedElement) {
230
+ var _focusedElement$curre;
240
231
 
241
- return x === null || x === void 0 ? void 0 : (_x$current = x.current) === null || _x$current === void 0 ? void 0 : _x$current.contains(e.target);
242
- })) {
243
- if (isOpen) {
244
- setIsOpen(false);
245
- setFocused(null);
232
+ (_focusedElement$curre = focusedElement.current) === null || _focusedElement$curre === void 0 ? void 0 : _focusedElement$curre.click();
233
+ }
246
234
  }
247
235
  }
248
236
  };
249
237
 
250
238
  _react.default.useEffect(function () {
251
239
  document.addEventListener('keydown', handleKeyDown);
252
- document.addEventListener('click', handleClickOutside);
253
240
  return function () {
254
241
  document.removeEventListener('keydown', handleKeyDown);
255
- document.removeEventListener('click', handleClickOutside);
256
242
  };
257
243
  });
258
244
 
@@ -282,26 +268,31 @@ var DropdownContent = function DropdownContent(_ref) {
282
268
 
283
269
  var arrLength = getFilteredItems().length;
284
270
 
285
- var _React$useState3 = _react.default.useState([]),
286
- _React$useState4 = (0, _slicedToArray2.default)(_React$useState3, 2),
287
- elRefs = _React$useState4[0],
288
- setElRefs = _React$useState4[1];
271
+ var _React$useState5 = _react.default.useState([]),
272
+ _React$useState6 = (0, _slicedToArray2.default)(_React$useState5, 2),
273
+ elRefs = _React$useState6[0],
274
+ setElRefs = _React$useState6[1];
289
275
 
290
276
  _react.default.useEffect(function () {
277
+ if ((elRefs === null || elRefs === void 0 ? void 0 : elRefs.length) !== arrLength) {
278
+ setFocused(null);
279
+ }
280
+
291
281
  setElRefs(function (elRefs) {
292
282
  return Array(arrLength + 1).fill(null).map(function (_, i) {
293
283
  return getCorrectRef(elRefs[i]);
294
284
  });
295
285
  });
296
- }, [isOpen, arrLength, selectedValues]);
286
+ }, [isOpen, arrLength]);
297
287
 
298
- _react.default.useEffect(function () {
299
- determineDropUp();
300
- }, [isOpen]);
288
+ _react.default.useLayoutEffect(function () {
289
+ isOpen && !locationDefined && determineDropUp();
290
+ }, [isOpen, locationDefined]);
301
291
 
302
292
  var haveTopItem = function haveTopItem() {
303
293
  var _getSuggestions;
304
294
 
295
+ if (!customizationProps.pinTopItem) return false;
305
296
  if (customizationProps.itemsType === 'radio' && selectedValues && (selectedValues === null || selectedValues === void 0 ? void 0 : selectedValues.length) > 0) return true;else if (customizationProps.itemsType === 'checkbox' && (customizationProps.multiSelect || (selectedValues === null || selectedValues === void 0 ? void 0 : selectedValues.length) > 0)) return true;else if (customizationProps.itemsType === 'normal' && ((_getSuggestions = getSuggestions()) === null || _getSuggestions === void 0 ? void 0 : _getSuggestions.length) > 0) return true;
306
297
  return false;
307
298
  };
@@ -311,18 +302,65 @@ var DropdownContent = function DropdownContent(_ref) {
311
302
  return x.suggestion;
312
303
  });
313
304
  };
305
+ /**
306
+ * when dropdown opens set correct position of focused item
307
+ * */
308
+
314
309
 
315
310
  _react.default.useLayoutEffect(function () {
316
311
  if (isOpen && (focused || focused === 0)) {
317
- var _newFocusedElement$cu2;
312
+ setNewFocusedElement(focused === 0 && !haveTopItem() ? 1 : focused);
313
+ }
314
+ }, [isOpen, focused]);
315
+ /**
316
+ * Reset dropdown content state on close
317
+ * */
318
318
 
319
- var focusThis = focused === 0 && !haveTopItem() ? 1 : focused;
320
- if (focusThis !== focused) setFocused(focusThis);
321
- var newFocusedElement = elRefs[focusThis];
322
- newFocusedElement === null || newFocusedElement === void 0 ? void 0 : (_newFocusedElement$cu2 = newFocusedElement.current) === null || _newFocusedElement$cu2 === void 0 ? void 0 : _newFocusedElement$cu2.focus();
323
- } else setFocused(null); //if the dropdown is closed, we don't to keep saved the focused item
324
319
 
325
- }, [isOpen, focused]);
320
+ _react.default.useEffect(function () {
321
+ if (!isOpen) {
322
+ var _dropdownContentRef$c2, _dropdownContentRef$c3;
323
+
324
+ setLocationDefined(false);
325
+
326
+ var _iterator = _createForOfIteratorHelper(elRefs),
327
+ _step;
328
+
329
+ try {
330
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
331
+ var _elRef$current;
332
+
333
+ var elRef = _step.value;
334
+ (_elRef$current = elRef.current) === null || _elRef$current === void 0 ? void 0 : _elRef$current.classList.remove('dropdown-hover');
335
+ }
336
+ } catch (err) {
337
+ _iterator.e(err);
338
+ } finally {
339
+ _iterator.f();
340
+ }
341
+
342
+ setFocused(null);
343
+ (_dropdownContentRef$c2 = dropdownContentRef.current) === null || _dropdownContentRef$c2 === void 0 ? void 0 : _dropdownContentRef$c2.classList.remove('outline');
344
+ (_dropdownContentRef$c3 = dropdownContentRef.current) === null || _dropdownContentRef$c3 === void 0 ? void 0 : _dropdownContentRef$c3.blur();
345
+ } else {
346
+ if (outline) {
347
+ var _dropdownContentRef$c4, _dropdownContentRef$c5;
348
+
349
+ (_dropdownContentRef$c4 = dropdownContentRef.current) === null || _dropdownContentRef$c4 === void 0 ? void 0 : _dropdownContentRef$c4.classList.add('outline');
350
+ (_dropdownContentRef$c5 = dropdownContentRef.current) === null || _dropdownContentRef$c5 === void 0 ? void 0 : _dropdownContentRef$c5.focus();
351
+ }
352
+ }
353
+ }, [isOpen, dropdownContentRef, focused, outline]);
354
+ /**
355
+ * Scroll item container to top when dropdown opens
356
+ * */
357
+
358
+
359
+ _react.default.useEffect(function () {
360
+ if (isOpen && itemsListRef.current) {
361
+ itemsListRef.current.scrollTop = 0;
362
+ }
363
+ }, [isOpen]);
326
364
 
327
365
  var handleItemClick = function handleItemClick(selected, item) {
328
366
  var newValue = [];
@@ -362,16 +400,20 @@ var DropdownContent = function DropdownContent(_ref) {
362
400
  }) : null;
363
401
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(TopItemContainer, {
364
402
  size: size,
365
- children: [customizationProps.itemsType == 'radio' && /*#__PURE__*/(0, _jsxRuntime.jsx)(_InputFields.RadioButton, {
403
+ children: [customizationProps.itemsType === 'radio' && /*#__PURE__*/(0, _jsxRuntime.jsx)(_InputFields.RadioButton, {
366
404
  ref: elRefs[0],
367
405
  iconPointerEventsTransparent: true,
406
+ tabIndexVal: -1,
407
+ className: "".concat(focused === 0 ? 'dropdown-hover' : ''),
368
408
  select: function select() {},
369
409
  label: (_selectedFirst$displa = selectedFirst === null || selectedFirst === void 0 ? void 0 : selectedFirst.displayLabel) !== null && _selectedFirst$displa !== void 0 ? _selectedFirst$displa : selectedFirst === null || selectedFirst === void 0 ? void 0 : selectedFirst.value,
370
410
  size: size,
371
411
  id: "".concat(id, "_topitem"),
372
412
  selected: true
373
- }), customizationProps.itemsType == 'checkbox' && /*#__PURE__*/(0, _jsxRuntime.jsx)(_InputFields.Checkbox, {
413
+ }), customizationProps.itemsType === 'checkbox' && /*#__PURE__*/(0, _jsxRuntime.jsx)(_InputFields.Checkbox, {
374
414
  ref: elRefs[0],
415
+ tabIndexVal: -1,
416
+ className: "".concat(focused === 0 ? 'dropdown-hover' : ''),
375
417
  select: function select(selected) {
376
418
  if (!customizationProps.multiSelect) return;
377
419
  var newValues = selected ? visibleItems.map(function (x) {
@@ -386,12 +428,14 @@ var DropdownContent = function DropdownContent(_ref) {
386
428
  id: "".concat(id, "_checkbox_selectall"),
387
429
  label: customizationProps.multiSelect ? 'Select all' : (_selectedFirst$displa2 = selectedFirst === null || selectedFirst === void 0 ? void 0 : selectedFirst.displayLabel) !== null && _selectedFirst$displa2 !== void 0 ? _selectedFirst$displa2 : selectedFirst === null || selectedFirst === void 0 ? void 0 : selectedFirst.value,
388
430
  selected: !customizationProps.multiSelect || allSelected
389
- }), customizationProps.itemsType == 'normal' && /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
431
+ }), customizationProps.itemsType === 'normal' && /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
390
432
  children: suggestions.map(function (x) {
391
433
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_MenuItem.default, {
392
434
  item: x,
393
435
  size: size,
394
436
  active: false,
437
+ tabIndex: -1,
438
+ className: "".concat(focused === 0 ? 'dropdown-hover' : ''),
395
439
  ref: elRefs[0],
396
440
  id: "".concat(id, "_topitem"),
397
441
  onClickHandler: function onClickHandler(e) {
@@ -414,6 +458,7 @@ var DropdownContent = function DropdownContent(_ref) {
414
458
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
415
459
  className: "dropdownButton",
416
460
  disabled: true,
461
+ tabIndex: -1,
417
462
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
418
463
  children: messageOnNoResults
419
464
  })
@@ -421,12 +466,11 @@ var DropdownContent = function DropdownContent(_ref) {
421
466
  });
422
467
  }
423
468
 
424
- var number = 0;
425
469
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(ItemsContainer, {
426
470
  size: size,
427
471
  children: getFilteredItems().filter(function (x) {
428
472
  return x && (customizationProps.itemsType != 'normal' || !x.suggestion);
429
- }).map(function (item) {
473
+ }).map(function (item, index) {
430
474
  var _item$displayLabel, _item$displayLabel2;
431
475
 
432
476
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.default.Fragment, {
@@ -434,30 +478,36 @@ var DropdownContent = function DropdownContent(_ref) {
434
478
  select: function select(selected) {
435
479
  return handleItemClick(selected, item);
436
480
  },
437
- ref: elRefs[number + 1],
481
+ ref: elRefs[index + 1],
438
482
  size: size,
483
+ tabIndexVal: -1,
484
+ className: "".concat(index + 1 === focused ? 'dropdown-hover' : ''),
439
485
  iconPointerEventsTransparent: true,
440
486
  disabled: item === null || item === void 0 ? void 0 : item.disabled,
441
- id: "".concat(id, "_").concat(number + 1),
487
+ id: "".concat(id, "_").concat(index + 1),
442
488
  label: (_item$displayLabel = item.displayLabel) !== null && _item$displayLabel !== void 0 ? _item$displayLabel : item.value,
443
489
  selected: selectedValues === null || selectedValues === void 0 ? void 0 : selectedValues.includes(item.value)
444
- }, "key_".concat(id, "_").concat(number++)), !item.customContent && customizationProps.itemsType == 'checkbox' && /*#__PURE__*/(0, _jsxRuntime.jsx)(_InputFields.Checkbox, {
490
+ }, "key_".concat(id, "_").concat(index + 1)), !item.customContent && customizationProps.itemsType == 'checkbox' && /*#__PURE__*/(0, _jsxRuntime.jsx)(_InputFields.Checkbox, {
445
491
  select: function select(selected) {
446
492
  return handleItemClick(selected, item);
447
493
  },
448
494
  iconPointerEventsTransparent: true,
449
495
  disabled: item === null || item === void 0 ? void 0 : item.disabled,
450
- ref: elRefs[number + 1],
496
+ className: "".concat(index + 1 === focused ? 'dropdown-hover' : ''),
497
+ ref: elRefs[index + 1],
451
498
  size: size,
452
- id: "".concat(id, "_").concat(number + 1),
499
+ tabIndexVal: -1,
500
+ id: "".concat(id, "_").concat(index + 1),
453
501
  label: (_item$displayLabel2 = item.displayLabel) !== null && _item$displayLabel2 !== void 0 ? _item$displayLabel2 : item.value,
454
502
  selected: selectedValues === null || selectedValues === void 0 ? void 0 : selectedValues.includes(item.value)
455
- }, "key_".concat(id, "_").concat(number++)), !item.customContent && (customizationProps.itemsType == 'normal' || !customizationProps.itemsType) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_MenuItem.default, {
456
- id: "".concat(id, "_").concat(number + 1),
503
+ }, "key_".concat(id, "_").concat(index + 1)), !item.customContent && (customizationProps.itemsType == 'normal' || !customizationProps.itemsType) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_MenuItem.default, {
504
+ id: "".concat(id, "_").concat(index + 1),
457
505
  item: item,
506
+ tabIndex: -1,
507
+ className: "".concat(index + 1 === focused ? 'dropdown-hover' : ''),
458
508
  size: size,
459
509
  active: selectedValues === null || selectedValues === void 0 ? void 0 : selectedValues.includes(item.value),
460
- ref: elRefs[number + 1],
510
+ ref: elRefs[index + 1],
461
511
  onClickHandler: function onClickHandler(e) {
462
512
  e.stopPropagation();
463
513
  customizationProps.onValueUpdate([item.value]);
@@ -465,28 +515,29 @@ var DropdownContent = function DropdownContent(_ref) {
465
515
  setIsOpen(false);
466
516
  setFocused(null);
467
517
  }
468
- }, "key_".concat(id, "_").concat(number++))]
518
+ }, "key_".concat(id, "_").concat(index + 1))]
469
519
  }, "key_".concat(id, "_").concat(item.value));
470
520
  })
471
521
  });
472
522
  };
473
523
 
524
+ var cls = "".concat(isOpen ? 'show' : '', " ").concat(isOpen && outline ? 'outline' : '', " ").concat(locationDefined ? isUp ? 'up' : 'down' : '');
474
525
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(DDContainer, {
475
526
  ref: dropdownContentRef,
476
527
  size: size,
477
528
  width: width,
529
+ tabIndex: -1,
478
530
  isButton: isButton,
479
531
  alignLeft: alignLeft,
480
532
  scrollable: customizationProps.scrollable,
481
533
  maxHeight: customizationProps.maxHeight,
482
- className: [isOpen && 'show', isUp && 'up'].filter(function (e) {
483
- return !!e;
484
- }).join(' '),
534
+ className: cls,
485
535
  children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(ListContainer, {
486
536
  size: size,
487
537
  itemsType: customizationProps.itemsType,
488
538
  onScroll: handleScroll,
489
539
  ref: itemsListRef,
540
+ outline: outline,
490
541
  scrollable: customizationProps.scrollable,
491
542
  children: [customizationProps.menuContent && /*#__PURE__*/(0, _jsxRuntime.jsxs)(MenuContentContainer, {
492
543
  size: size,
@@ -503,30 +554,19 @@ var DropdownContent = function DropdownContent(_ref) {
503
554
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {
504
555
  width: "100%",
505
556
  icon: customizationProps.actionIcon,
557
+ ref: actionButtonRef,
506
558
  loading: customizationProps.actionLoading,
507
559
  disabled: customizationProps.actionDisabled,
508
560
  variant: (_customizationProps$a = customizationProps.actionVariant) !== null && _customizationProps$a !== void 0 ? _customizationProps$a : 'primary',
509
561
  size: size,
510
562
  onClick: function onClick() {
511
- if (customizationProps.action()) //closing the dropdown if action returns 'true'
512
- setIsOpen(false);
563
+ return customizationProps.action() && setIsOpen(false);
513
564
  },
514
565
  children: customizationProps.actionLabel
515
566
  })
516
567
  })]
517
568
  });
518
- /* ),
519
- {
520
- handleClickOutside: () => () => {
521
- if (isOpen) {
522
- setIsOpen(false);
523
- setFocused(null);
524
- }
525
- },
526
- },
527
- );
528
- return <Wrapped />; */
529
- };
569
+ });
530
570
 
531
571
  DropdownContent.propTypes = {
532
572
  isButton: _propTypes.default.bool.isRequired,
@@ -561,12 +601,12 @@ DropdownContent.propTypes = {
561
601
  id: _propTypes.default.string.isRequired,
562
602
  filter: _propTypes.default.string.isRequired,
563
603
  width: _propTypes.default.string,
564
- hideOnClickOutside: _propTypes.default.bool.isRequired,
565
604
  selectedValues: _propTypes.default.arrayOf(_propTypes.default.string).isRequired,
566
605
  setSelectedValues: _propTypes.default.func.isRequired,
567
606
  messageOnNoResults: _propTypes.default.string.isRequired,
568
607
  focused: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.oneOf([null])]),
569
- setFocused: _propTypes.default.func.isRequired
608
+ setFocused: _propTypes.default.func.isRequired,
609
+ outline: _propTypes.default.bool
570
610
  };
571
611
  var _default = DropdownContent;
572
612
  exports.default = _default;