@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
@@ -5,6 +5,12 @@ import _pt from "prop-types";
5
5
 
6
6
  var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7;
7
7
 
8
+ 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; } } }; }
9
+
10
+ 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); }
11
+
12
+ 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; }
13
+
8
14
  import React from 'react';
9
15
  import styled from 'styled-components';
10
16
  import Button from '../Button/Button';
@@ -18,11 +24,14 @@ import MenuItem from '../MenuItem/MenuItem';
18
24
  import { jsx as _jsx } from "react/jsx-runtime";
19
25
  import { Fragment as _Fragment } from "react/jsx-runtime";
20
26
  import { jsxs as _jsxs } from "react/jsx-runtime";
21
- export var DDContainer = styled.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\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"])), COLORS.white, function (props) {
27
+ var MAX_MENU_HEIGHT = 240;
28
+ var AVG_OPTION_HEIGHT = 48;
29
+ var OFFSET_BEFORE_SHOW = 1000000;
30
+ export var DDContainer = styled.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\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"])), COLORS.white, function (props) {
22
31
  return props.width ? props.width : '100%';
23
32
  }, Z_INDEXES.dropdown, function (props) {
24
33
  return props.isButton ? '-4px' : '4px 0px';
25
- }, function (props) {
34
+ }, OFFSET_BEFORE_SHOW, OFFSET_BEFORE_SHOW, function (props) {
26
35
  return props.alignLeft ? 'left: 0px;' : '';
27
36
  }, function (props) {
28
37
  return props.isButton ? ButtonDropdownContentStyling : '';
@@ -32,11 +41,9 @@ export var DDContainer = styled.div(_templateObject || (_templateObject = _tagge
32
41
  return props.size == Size.Large ? '10px' : props.size == Size.Medium ? '8px' : '6px';
33
42
  }, function (props) {
34
43
  return !props.scrollable ? 'auto' : props.maxHeight ? props.maxHeight : props.size == Size.Large ? '320px' : props.size == Size.Medium ? '280px' : '240px';
35
- }, function (props) {
36
- return !!props.scrollable ? '* { outline-offset: -4px !important;}' : '';
37
44
  });
38
45
  var ItemsContainer = styled.div(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n > *:hover {\n z-index: ", ";\n }\n\n > *:active,\n > *.active {\n z-index: ", ";\n }\n\n > *:focus {\n z-index: ", ";\n }\n"])), Z_INDEXES.hover, Z_INDEXES.active, Z_INDEXES.focus);
39
- var ListContainer = styled.div(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\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) {
46
+ var ListContainer = styled.div(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\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) {
40
47
  return props.scrollable ? 'overflow-y: scroll;' : '';
41
48
  }, function (props) {
42
49
  return props.scrollable ? 'margin-right: 6px;' : '';
@@ -77,11 +84,8 @@ var ActionButtonContainer = styled.div(_templateObject7 || (_templateObject7 = _
77
84
  }, function (props) {
78
85
  return props.size === Size.Small || !props.size ? '4px 16px 0px' : props.size === Size.Medium ? '12px 16px 8px' : '16px 16px 12px';
79
86
  });
80
- var MAX_MENU_HEIGHT = 240;
81
- var AVG_OPTION_HEIGHT = 48;
82
-
83
- var DropdownContent = function DropdownContent(_ref) {
84
- var _customizationProps$a;
87
+ var DropdownContent = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
88
+ var _ref2, _customizationProps$a;
85
89
 
86
90
  var id = _ref.id,
87
91
  customizationProps = _ref.customizationProps,
@@ -89,7 +93,6 @@ var DropdownContent = function DropdownContent(_ref) {
89
93
  isButton = _ref.isButton,
90
94
  size = _ref.size,
91
95
  isOpen = _ref.isOpen,
92
- hideOnClickOutside = _ref.hideOnClickOutside,
93
96
  width = _ref.width,
94
97
  setIsOpen = _ref.setIsOpen,
95
98
  filter = _ref.filter,
@@ -97,17 +100,24 @@ var DropdownContent = function DropdownContent(_ref) {
97
100
  setFocused = _ref.setFocused,
98
101
  selectedValues = _ref.selectedValues,
99
102
  setSelectedValues = _ref.setSelectedValues,
100
- messageOnNoResults = _ref.messageOnNoResults;
103
+ messageOnNoResults = _ref.messageOnNoResults,
104
+ outline = _ref.outline;
101
105
 
102
106
  var _React$useState = React.useState(false),
103
107
  _React$useState2 = _slicedToArray(_React$useState, 2),
104
108
  isUp = _React$useState2[0],
105
109
  setIsUp = _React$useState2[1];
106
110
 
107
- var dropdownContentRef = React.useRef(null);
111
+ var _React$useState3 = React.useState(false),
112
+ _React$useState4 = _slicedToArray(_React$useState3, 2),
113
+ locationDefined = _React$useState4[0],
114
+ setLocationDefined = _React$useState4[1];
115
+
116
+ var dropdownContentRef = (_ref2 = ref) !== null && _ref2 !== void 0 ? _ref2 : React.useRef(null);
108
117
  if (!customizationProps.itemsType) customizationProps.itemsType = 'normal';
109
118
  if (!size) size = Size.Small;
110
119
  var itemsListRef = React.useRef(null);
120
+ var actionButtonRef = React.useRef(null);
111
121
 
112
122
  var determineDropUp = function determineDropUp() {
113
123
  var options = customizationProps.items;
@@ -115,18 +125,28 @@ var DropdownContent = function DropdownContent(_ref) {
115
125
  if (!node) return;
116
126
  var windowHeight = window.innerHeight;
117
127
  var menuHeight = Math.min(MAX_MENU_HEIGHT, options.length * AVG_OPTION_HEIGHT);
118
- var instOffsetWithMenu = node.getBoundingClientRect().top + menuHeight;
128
+ var instOffsetWithMenu = node.getBoundingClientRect().top + menuHeight + OFFSET_BEFORE_SHOW;
119
129
  setIsUp(instOffsetWithMenu >= windowHeight);
130
+ setLocationDefined(true);
120
131
  };
121
132
 
122
133
  var setNewFocusedElement = function setNewFocusedElement(index) {
134
+ var _dropdownContentRef$c;
135
+
136
+ if (outline) (_dropdownContentRef$c = dropdownContentRef.current) === null || _dropdownContentRef$c === void 0 ? void 0 : _dropdownContentRef$c.focus();
123
137
  var newFocusedElement = elRefs[index];
138
+ var oldFocusedElement = focused || focused === 0 ? elRefs[focused] : null;
124
139
 
125
- if (newFocusedElement) {
126
- var _newFocusedElement$cu;
140
+ if (newFocusedElement && newFocusedElement !== oldFocusedElement) {
141
+ var _oldFocusedElement$cu, _newFocusedElement$cu, _newFocusedElement$cu2;
127
142
 
128
143
  setFocused(index);
129
- newFocusedElement === null || newFocusedElement === void 0 ? void 0 : (_newFocusedElement$cu = newFocusedElement.current) === null || _newFocusedElement$cu === void 0 ? void 0 : _newFocusedElement$cu.focus();
144
+ oldFocusedElement === null || oldFocusedElement === void 0 ? void 0 : (_oldFocusedElement$cu = oldFocusedElement.current) === null || _oldFocusedElement$cu === void 0 ? void 0 : _oldFocusedElement$cu.classList.remove('dropdown-hover');
145
+ (_newFocusedElement$cu = newFocusedElement.current) === null || _newFocusedElement$cu === void 0 ? void 0 : _newFocusedElement$cu.classList.add('dropdown-hover');
146
+ (_newFocusedElement$cu2 = newFocusedElement.current) === null || _newFocusedElement$cu2 === void 0 ? void 0 : _newFocusedElement$cu2.scrollIntoView({
147
+ block: 'nearest',
148
+ inline: 'nearest'
149
+ });
130
150
  }
131
151
  };
132
152
 
@@ -139,88 +159,53 @@ var DropdownContent = function DropdownContent(_ref) {
139
159
  });
140
160
  };
141
161
 
162
+ var findNextActiveIndex = function findNextActiveIndex(index, direction, items) {
163
+ for (var i = index + direction; i > 0 && i <= items.length; i += direction) {
164
+ var _items;
165
+
166
+ if (!((_items = items[i - 1]) !== null && _items !== void 0 && _items.disabled)) {
167
+ return i;
168
+ }
169
+ }
170
+
171
+ return index;
172
+ };
173
+
142
174
  var handleKeyDown = function handleKeyDown(e) {
143
175
  if (isOpen) {
144
176
  if (e.key === 'ArrowUp' || e.key === 'Up') {
145
177
  e.preventDefault();
146
- var focusedNow = focused;
147
-
148
- if (focusedNow !== undefined && focusedNow !== null && focusedNow > 0) {
149
- var filtered = getFilteredItems();
150
- if (focusedNow === 1 && haveTopItem()) focusedNow = 0;else {
151
- for (var i = focusedNow - 1; i > 0; i--) {
152
- var _filtered;
153
-
154
- if (!((_filtered = filtered[i - 1]) !== null && _filtered !== void 0 && _filtered.disabled)) {
155
- focusedNow = i;
156
- break;
157
- }
158
- }
159
- }
178
+ var focusedNow = focused || focused === 0 ? focused : arrLength + 1;
179
+
180
+ if (!!focusedNow) {
181
+ focusedNow = focusedNow === 1 && haveTopItem() ? 0 : findNextActiveIndex(focusedNow, -1, getFilteredItems());
160
182
  setNewFocusedElement(focusedNow);
161
183
  }
162
184
  } else if (e.key === 'ArrowDown' || e.key === 'Down') {
163
185
  e.preventDefault();
164
186
  var _focusedNow = focused;
165
-
166
- if (_focusedNow !== undefined && _focusedNow !== null) {
167
- var _filtered2 = getFilteredItems();
168
-
169
- for (var _i = _focusedNow + 1; _i <= _filtered2.length; _i++) {
170
- var _filtered3;
171
-
172
- if (!((_filtered3 = _filtered2[_i - 1]) !== null && _filtered3 !== void 0 && _filtered3.disabled)) {
173
- _focusedNow = _i;
174
- break;
175
- }
176
- }
177
- } else {
178
- _focusedNow = haveTopItem() ? 0 : 1;
179
- }
180
-
187
+ _focusedNow = !!_focusedNow || _focusedNow === 0 ? findNextActiveIndex(_focusedNow, 1, getFilteredItems()) : haveTopItem() ? 0 : 1;
181
188
  setNewFocusedElement(_focusedNow);
182
- } else if (e.key === 'Tab') {
183
- var _focusedNow2 = focused;
184
-
185
- if (_focusedNow2 !== undefined && _focusedNow2 !== null) {
186
- e.preventDefault();
187
- e.shiftKey ? _focusedNow2-- : _focusedNow2++;
188
- var newFocusedElement = document.getElementById("".concat(id, "_").concat(_focusedNow2));
189
-
190
- if (!newFocusedElement) {
191
- setNewFocusedElement(0);
192
- } else {
193
- setNewFocusedElement(_focusedNow2);
194
- }
195
- } else {
196
- setFocused(null);
197
- }
198
189
  } else if (e.key === 'Escape' || e.key === 'Esc') {
199
190
  setIsOpen(false);
200
191
  setFocused(null);
201
- }
202
- }
203
- };
192
+ } else if ((e.key === 'Enter' || e.key === ' ') && focused !== null && e.target !== (actionButtonRef === null || actionButtonRef === void 0 ? void 0 : actionButtonRef.current)) {
193
+ e.preventDefault();
194
+ var focusedElement = elRefs[focused];
204
195
 
205
- var handleClickOutside = function handleClickOutside(e) {
206
- if (hideOnClickOutside && dropdownContentRef !== null && dropdownContentRef !== void 0 && dropdownContentRef.current && !dropdownContentRef.current.contains(e.target) && !elRefs.some(function (x) {
207
- var _x$current;
196
+ if (focusedElement) {
197
+ var _focusedElement$curre;
208
198
 
209
- return x === null || x === void 0 ? void 0 : (_x$current = x.current) === null || _x$current === void 0 ? void 0 : _x$current.contains(e.target);
210
- })) {
211
- if (isOpen) {
212
- setIsOpen(false);
213
- setFocused(null);
199
+ (_focusedElement$curre = focusedElement.current) === null || _focusedElement$curre === void 0 ? void 0 : _focusedElement$curre.click();
200
+ }
214
201
  }
215
202
  }
216
203
  };
217
204
 
218
205
  React.useEffect(function () {
219
206
  document.addEventListener('keydown', handleKeyDown);
220
- document.addEventListener('click', handleClickOutside);
221
207
  return function () {
222
208
  document.removeEventListener('keydown', handleKeyDown);
223
- document.removeEventListener('click', handleClickOutside);
224
209
  };
225
210
  });
226
211
  var scrollPosition = React.useRef(0);
@@ -249,25 +234,30 @@ var DropdownContent = function DropdownContent(_ref) {
249
234
 
250
235
  var arrLength = getFilteredItems().length;
251
236
 
252
- var _React$useState3 = React.useState([]),
253
- _React$useState4 = _slicedToArray(_React$useState3, 2),
254
- elRefs = _React$useState4[0],
255
- setElRefs = _React$useState4[1];
237
+ var _React$useState5 = React.useState([]),
238
+ _React$useState6 = _slicedToArray(_React$useState5, 2),
239
+ elRefs = _React$useState6[0],
240
+ setElRefs = _React$useState6[1];
256
241
 
257
242
  React.useEffect(function () {
243
+ if ((elRefs === null || elRefs === void 0 ? void 0 : elRefs.length) !== arrLength) {
244
+ setFocused(null);
245
+ }
246
+
258
247
  setElRefs(function (elRefs) {
259
248
  return Array(arrLength + 1).fill(null).map(function (_, i) {
260
249
  return getCorrectRef(elRefs[i]);
261
250
  });
262
251
  });
263
- }, [isOpen, arrLength, selectedValues]);
264
- React.useEffect(function () {
265
- determineDropUp();
266
- }, [isOpen]);
252
+ }, [isOpen, arrLength]);
253
+ React.useLayoutEffect(function () {
254
+ isOpen && !locationDefined && determineDropUp();
255
+ }, [isOpen, locationDefined]);
267
256
 
268
257
  var haveTopItem = function haveTopItem() {
269
258
  var _getSuggestions;
270
259
 
260
+ if (!customizationProps.pinTopItem) return false;
271
261
  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;
272
262
  return false;
273
263
  };
@@ -277,18 +267,63 @@ var DropdownContent = function DropdownContent(_ref) {
277
267
  return x.suggestion;
278
268
  });
279
269
  };
270
+ /**
271
+ * when dropdown opens set correct position of focused item
272
+ * */
273
+
280
274
 
281
275
  React.useLayoutEffect(function () {
282
276
  if (isOpen && (focused || focused === 0)) {
283
- var _newFocusedElement$cu2;
277
+ setNewFocusedElement(focused === 0 && !haveTopItem() ? 1 : focused);
278
+ }
279
+ }, [isOpen, focused]);
280
+ /**
281
+ * Reset dropdown content state on close
282
+ * */
283
+
284
+ React.useEffect(function () {
285
+ if (!isOpen) {
286
+ var _dropdownContentRef$c2, _dropdownContentRef$c3;
284
287
 
285
- var focusThis = focused === 0 && !haveTopItem() ? 1 : focused;
286
- if (focusThis !== focused) setFocused(focusThis);
287
- var newFocusedElement = elRefs[focusThis];
288
- newFocusedElement === null || newFocusedElement === void 0 ? void 0 : (_newFocusedElement$cu2 = newFocusedElement.current) === null || _newFocusedElement$cu2 === void 0 ? void 0 : _newFocusedElement$cu2.focus();
289
- } else setFocused(null); //if the dropdown is closed, we don't to keep saved the focused item
288
+ setLocationDefined(false);
290
289
 
291
- }, [isOpen, focused]);
290
+ var _iterator = _createForOfIteratorHelper(elRefs),
291
+ _step;
292
+
293
+ try {
294
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
295
+ var _elRef$current;
296
+
297
+ var elRef = _step.value;
298
+ (_elRef$current = elRef.current) === null || _elRef$current === void 0 ? void 0 : _elRef$current.classList.remove('dropdown-hover');
299
+ }
300
+ } catch (err) {
301
+ _iterator.e(err);
302
+ } finally {
303
+ _iterator.f();
304
+ }
305
+
306
+ setFocused(null);
307
+ (_dropdownContentRef$c2 = dropdownContentRef.current) === null || _dropdownContentRef$c2 === void 0 ? void 0 : _dropdownContentRef$c2.classList.remove('outline');
308
+ (_dropdownContentRef$c3 = dropdownContentRef.current) === null || _dropdownContentRef$c3 === void 0 ? void 0 : _dropdownContentRef$c3.blur();
309
+ } else {
310
+ if (outline) {
311
+ var _dropdownContentRef$c4, _dropdownContentRef$c5;
312
+
313
+ (_dropdownContentRef$c4 = dropdownContentRef.current) === null || _dropdownContentRef$c4 === void 0 ? void 0 : _dropdownContentRef$c4.classList.add('outline');
314
+ (_dropdownContentRef$c5 = dropdownContentRef.current) === null || _dropdownContentRef$c5 === void 0 ? void 0 : _dropdownContentRef$c5.focus();
315
+ }
316
+ }
317
+ }, [isOpen, dropdownContentRef, focused, outline]);
318
+ /**
319
+ * Scroll item container to top when dropdown opens
320
+ * */
321
+
322
+ React.useEffect(function () {
323
+ if (isOpen && itemsListRef.current) {
324
+ itemsListRef.current.scrollTop = 0;
325
+ }
326
+ }, [isOpen]);
292
327
 
293
328
  var handleItemClick = function handleItemClick(selected, item) {
294
329
  var newValue = [];
@@ -328,16 +363,20 @@ var DropdownContent = function DropdownContent(_ref) {
328
363
  }) : null;
329
364
  return /*#__PURE__*/_jsxs(TopItemContainer, {
330
365
  size: size,
331
- children: [customizationProps.itemsType == 'radio' && /*#__PURE__*/_jsx(RadioButton, {
366
+ children: [customizationProps.itemsType === 'radio' && /*#__PURE__*/_jsx(RadioButton, {
332
367
  ref: elRefs[0],
333
368
  iconPointerEventsTransparent: true,
369
+ tabIndexVal: -1,
370
+ className: "".concat(focused === 0 ? 'dropdown-hover' : ''),
334
371
  select: function select() {},
335
372
  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,
336
373
  size: size,
337
374
  id: "".concat(id, "_topitem"),
338
375
  selected: true
339
- }), customizationProps.itemsType == 'checkbox' && /*#__PURE__*/_jsx(Checkbox, {
376
+ }), customizationProps.itemsType === 'checkbox' && /*#__PURE__*/_jsx(Checkbox, {
340
377
  ref: elRefs[0],
378
+ tabIndexVal: -1,
379
+ className: "".concat(focused === 0 ? 'dropdown-hover' : ''),
341
380
  select: function select(selected) {
342
381
  if (!customizationProps.multiSelect) return;
343
382
  var newValues = selected ? visibleItems.map(function (x) {
@@ -352,12 +391,14 @@ var DropdownContent = function DropdownContent(_ref) {
352
391
  id: "".concat(id, "_checkbox_selectall"),
353
392
  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,
354
393
  selected: !customizationProps.multiSelect || allSelected
355
- }), customizationProps.itemsType == 'normal' && /*#__PURE__*/_jsx(_Fragment, {
394
+ }), customizationProps.itemsType === 'normal' && /*#__PURE__*/_jsx(_Fragment, {
356
395
  children: suggestions.map(function (x) {
357
396
  return /*#__PURE__*/_jsx(MenuItem, {
358
397
  item: x,
359
398
  size: size,
360
399
  active: false,
400
+ tabIndex: -1,
401
+ className: "".concat(focused === 0 ? 'dropdown-hover' : ''),
361
402
  ref: elRefs[0],
362
403
  id: "".concat(id, "_topitem"),
363
404
  onClickHandler: function onClickHandler(e) {
@@ -380,6 +421,7 @@ var DropdownContent = function DropdownContent(_ref) {
380
421
  children: /*#__PURE__*/_jsx("button", {
381
422
  className: "dropdownButton",
382
423
  disabled: true,
424
+ tabIndex: -1,
383
425
  children: /*#__PURE__*/_jsx("span", {
384
426
  children: messageOnNoResults
385
427
  })
@@ -387,12 +429,11 @@ var DropdownContent = function DropdownContent(_ref) {
387
429
  });
388
430
  }
389
431
 
390
- var number = 0;
391
432
  return /*#__PURE__*/_jsx(ItemsContainer, {
392
433
  size: size,
393
434
  children: getFilteredItems().filter(function (x) {
394
435
  return x && (customizationProps.itemsType != 'normal' || !x.suggestion);
395
- }).map(function (item) {
436
+ }).map(function (item, index) {
396
437
  var _item$displayLabel, _item$displayLabel2;
397
438
 
398
439
  return /*#__PURE__*/_jsxs(React.Fragment, {
@@ -400,30 +441,36 @@ var DropdownContent = function DropdownContent(_ref) {
400
441
  select: function select(selected) {
401
442
  return handleItemClick(selected, item);
402
443
  },
403
- ref: elRefs[number + 1],
444
+ ref: elRefs[index + 1],
404
445
  size: size,
446
+ tabIndexVal: -1,
447
+ className: "".concat(index + 1 === focused ? 'dropdown-hover' : ''),
405
448
  iconPointerEventsTransparent: true,
406
449
  disabled: item === null || item === void 0 ? void 0 : item.disabled,
407
- id: "".concat(id, "_").concat(number + 1),
450
+ id: "".concat(id, "_").concat(index + 1),
408
451
  label: (_item$displayLabel = item.displayLabel) !== null && _item$displayLabel !== void 0 ? _item$displayLabel : item.value,
409
452
  selected: selectedValues === null || selectedValues === void 0 ? void 0 : selectedValues.includes(item.value)
410
- }, "key_".concat(id, "_").concat(number++)), !item.customContent && customizationProps.itemsType == 'checkbox' && /*#__PURE__*/_jsx(Checkbox, {
453
+ }, "key_".concat(id, "_").concat(index + 1)), !item.customContent && customizationProps.itemsType == 'checkbox' && /*#__PURE__*/_jsx(Checkbox, {
411
454
  select: function select(selected) {
412
455
  return handleItemClick(selected, item);
413
456
  },
414
457
  iconPointerEventsTransparent: true,
415
458
  disabled: item === null || item === void 0 ? void 0 : item.disabled,
416
- ref: elRefs[number + 1],
459
+ className: "".concat(index + 1 === focused ? 'dropdown-hover' : ''),
460
+ ref: elRefs[index + 1],
417
461
  size: size,
418
- id: "".concat(id, "_").concat(number + 1),
462
+ tabIndexVal: -1,
463
+ id: "".concat(id, "_").concat(index + 1),
419
464
  label: (_item$displayLabel2 = item.displayLabel) !== null && _item$displayLabel2 !== void 0 ? _item$displayLabel2 : item.value,
420
465
  selected: selectedValues === null || selectedValues === void 0 ? void 0 : selectedValues.includes(item.value)
421
- }, "key_".concat(id, "_").concat(number++)), !item.customContent && (customizationProps.itemsType == 'normal' || !customizationProps.itemsType) && /*#__PURE__*/_jsx(MenuItem, {
422
- id: "".concat(id, "_").concat(number + 1),
466
+ }, "key_".concat(id, "_").concat(index + 1)), !item.customContent && (customizationProps.itemsType == 'normal' || !customizationProps.itemsType) && /*#__PURE__*/_jsx(MenuItem, {
467
+ id: "".concat(id, "_").concat(index + 1),
423
468
  item: item,
469
+ tabIndex: -1,
470
+ className: "".concat(index + 1 === focused ? 'dropdown-hover' : ''),
424
471
  size: size,
425
472
  active: selectedValues === null || selectedValues === void 0 ? void 0 : selectedValues.includes(item.value),
426
- ref: elRefs[number + 1],
473
+ ref: elRefs[index + 1],
427
474
  onClickHandler: function onClickHandler(e) {
428
475
  e.stopPropagation();
429
476
  customizationProps.onValueUpdate([item.value]);
@@ -431,28 +478,29 @@ var DropdownContent = function DropdownContent(_ref) {
431
478
  setIsOpen(false);
432
479
  setFocused(null);
433
480
  }
434
- }, "key_".concat(id, "_").concat(number++))]
481
+ }, "key_".concat(id, "_").concat(index + 1))]
435
482
  }, "key_".concat(id, "_").concat(item.value));
436
483
  })
437
484
  });
438
485
  };
439
486
 
487
+ var cls = "".concat(isOpen ? 'show' : '', " ").concat(isOpen && outline ? 'outline' : '', " ").concat(locationDefined ? isUp ? 'up' : 'down' : '');
440
488
  return /*#__PURE__*/_jsxs(DDContainer, {
441
489
  ref: dropdownContentRef,
442
490
  size: size,
443
491
  width: width,
492
+ tabIndex: -1,
444
493
  isButton: isButton,
445
494
  alignLeft: alignLeft,
446
495
  scrollable: customizationProps.scrollable,
447
496
  maxHeight: customizationProps.maxHeight,
448
- className: [isOpen && 'show', isUp && 'up'].filter(function (e) {
449
- return !!e;
450
- }).join(' '),
497
+ className: cls,
451
498
  children: [/*#__PURE__*/_jsxs(ListContainer, {
452
499
  size: size,
453
500
  itemsType: customizationProps.itemsType,
454
501
  onScroll: handleScroll,
455
502
  ref: itemsListRef,
503
+ outline: outline,
456
504
  scrollable: customizationProps.scrollable,
457
505
  children: [customizationProps.menuContent && /*#__PURE__*/_jsxs(MenuContentContainer, {
458
506
  size: size,
@@ -469,31 +517,19 @@ var DropdownContent = function DropdownContent(_ref) {
469
517
  children: /*#__PURE__*/_jsx(Button, {
470
518
  width: "100%",
471
519
  icon: customizationProps.actionIcon,
520
+ ref: actionButtonRef,
472
521
  loading: customizationProps.actionLoading,
473
522
  disabled: customizationProps.actionDisabled,
474
523
  variant: (_customizationProps$a = customizationProps.actionVariant) !== null && _customizationProps$a !== void 0 ? _customizationProps$a : 'primary',
475
524
  size: size,
476
525
  onClick: function onClick() {
477
- if (customizationProps.action()) //closing the dropdown if action returns 'true'
478
- setIsOpen(false);
526
+ return customizationProps.action() && setIsOpen(false);
479
527
  },
480
528
  children: customizationProps.actionLabel
481
529
  })
482
530
  })]
483
531
  });
484
- /* ),
485
- {
486
- handleClickOutside: () => () => {
487
- if (isOpen) {
488
- setIsOpen(false);
489
- setFocused(null);
490
- }
491
- },
492
- },
493
- );
494
- return <Wrapped />; */
495
- };
496
-
532
+ });
497
533
  DropdownContent.propTypes = {
498
534
  isButton: _pt.bool.isRequired,
499
535
  customizationProps: _pt.shape({
@@ -527,12 +563,12 @@ DropdownContent.propTypes = {
527
563
  id: _pt.string.isRequired,
528
564
  filter: _pt.string.isRequired,
529
565
  width: _pt.string,
530
- hideOnClickOutside: _pt.bool.isRequired,
531
566
  selectedValues: _pt.arrayOf(_pt.string).isRequired,
532
567
  setSelectedValues: _pt.func.isRequired,
533
568
  messageOnNoResults: _pt.string.isRequired,
534
569
  focused: _pt.oneOfType([_pt.number, _pt.oneOf([null])]),
535
- setFocused: _pt.func.isRequired
570
+ setFocused: _pt.func.isRequired,
571
+ outline: _pt.bool
536
572
  };
537
573
  export default DropdownContent;
538
574
  //# sourceMappingURL=DropdownContent.js.map