@atlaskit/react-select 0.0.2

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 (197) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/LICENSE.md +11 -0
  3. package/README.md +10 -0
  4. package/async/package.json +15 -0
  5. package/base/package.json +15 -0
  6. package/creatable/package.json +15 -0
  7. package/dist/cjs/accessibility/helpers.js +34 -0
  8. package/dist/cjs/accessibility/index.js +74 -0
  9. package/dist/cjs/async-creatable.js +27 -0
  10. package/dist/cjs/async.js +30 -0
  11. package/dist/cjs/builtins.js +18 -0
  12. package/dist/cjs/components/containers.js +100 -0
  13. package/dist/cjs/components/control.js +67 -0
  14. package/dist/cjs/components/group.js +79 -0
  15. package/dist/cjs/components/index.js +53 -0
  16. package/dist/cjs/components/indicators.js +214 -0
  17. package/dist/cjs/components/input.js +93 -0
  18. package/dist/cjs/components/internal/a11y-text.js +34 -0
  19. package/dist/cjs/components/internal/dummy-input.js +43 -0
  20. package/dist/cjs/components/internal/index.js +34 -0
  21. package/dist/cjs/components/internal/required-input.js +43 -0
  22. package/dist/cjs/components/internal/scroll-manager.js +57 -0
  23. package/dist/cjs/components/internal/use-scroll-capture.js +132 -0
  24. package/dist/cjs/components/internal/use-scroll-lock.js +149 -0
  25. package/dist/cjs/components/live-region.js +153 -0
  26. package/dist/cjs/components/menu.js +464 -0
  27. package/dist/cjs/components/multi-value.js +129 -0
  28. package/dist/cjs/components/option.js +62 -0
  29. package/dist/cjs/components/placeholder.js +39 -0
  30. package/dist/cjs/components/single-value.js +46 -0
  31. package/dist/cjs/creatable.js +30 -0
  32. package/dist/cjs/diacritics.js +274 -0
  33. package/dist/cjs/filters.js +50 -0
  34. package/dist/cjs/index.js +55 -0
  35. package/dist/cjs/nonce-provider.js +30 -0
  36. package/dist/cjs/select.js +1803 -0
  37. package/dist/cjs/state-manager.js +31 -0
  38. package/dist/cjs/styles.js +66 -0
  39. package/dist/cjs/theme.js +42 -0
  40. package/dist/cjs/types.js +5 -0
  41. package/dist/cjs/use-async.js +156 -0
  42. package/dist/cjs/use-creatable.js +114 -0
  43. package/dist/cjs/use-state-manager.js +83 -0
  44. package/dist/cjs/utils.js +357 -0
  45. package/dist/es2019/accessibility/helpers.js +24 -0
  46. package/dist/es2019/accessibility/index.js +72 -0
  47. package/dist/es2019/async-creatable.js +17 -0
  48. package/dist/es2019/async.js +16 -0
  49. package/dist/es2019/builtins.js +4 -0
  50. package/dist/es2019/components/containers.js +100 -0
  51. package/dist/es2019/components/control.js +62 -0
  52. package/dist/es2019/components/group.js +74 -0
  53. package/dist/es2019/components/index.js +41 -0
  54. package/dist/es2019/components/indicators.js +211 -0
  55. package/dist/es2019/components/input.js +88 -0
  56. package/dist/es2019/components/internal/a11y-text.js +25 -0
  57. package/dist/es2019/components/internal/dummy-input.js +36 -0
  58. package/dist/es2019/components/internal/index.js +4 -0
  59. package/dist/es2019/components/internal/required-input.js +35 -0
  60. package/dist/es2019/components/internal/scroll-manager.js +49 -0
  61. package/dist/es2019/components/internal/use-scroll-capture.js +128 -0
  62. package/dist/es2019/components/internal/use-scroll-lock.js +143 -0
  63. package/dist/es2019/components/live-region.js +151 -0
  64. package/dist/es2019/components/menu.js +466 -0
  65. package/dist/es2019/components/multi-value.js +134 -0
  66. package/dist/es2019/components/option.js +57 -0
  67. package/dist/es2019/components/placeholder.js +34 -0
  68. package/dist/es2019/components/single-value.js +41 -0
  69. package/dist/es2019/creatable.js +15 -0
  70. package/dist/es2019/diacritics.js +264 -0
  71. package/dist/es2019/filters.js +36 -0
  72. package/dist/es2019/index.js +8 -0
  73. package/dist/es2019/nonce-provider.js +19 -0
  74. package/dist/es2019/select.js +1766 -0
  75. package/dist/es2019/state-manager.js +22 -0
  76. package/dist/es2019/styles.js +56 -0
  77. package/dist/es2019/theme.js +36 -0
  78. package/dist/es2019/types.js +1 -0
  79. package/dist/es2019/use-async.js +117 -0
  80. package/dist/es2019/use-creatable.js +81 -0
  81. package/dist/es2019/use-state-manager.js +60 -0
  82. package/dist/es2019/utils.js +309 -0
  83. package/dist/esm/accessibility/helpers.js +24 -0
  84. package/dist/esm/accessibility/index.js +68 -0
  85. package/dist/esm/async-creatable.js +17 -0
  86. package/dist/esm/async.js +16 -0
  87. package/dist/esm/builtins.js +12 -0
  88. package/dist/esm/components/containers.js +96 -0
  89. package/dist/esm/components/control.js +62 -0
  90. package/dist/esm/components/group.js +74 -0
  91. package/dist/esm/components/index.js +43 -0
  92. package/dist/esm/components/indicators.js +209 -0
  93. package/dist/esm/components/input.js +88 -0
  94. package/dist/esm/components/internal/a11y-text.js +27 -0
  95. package/dist/esm/components/internal/dummy-input.js +37 -0
  96. package/dist/esm/components/internal/index.js +4 -0
  97. package/dist/esm/components/internal/required-input.js +36 -0
  98. package/dist/esm/components/internal/scroll-manager.js +49 -0
  99. package/dist/esm/components/internal/use-scroll-capture.js +126 -0
  100. package/dist/esm/components/internal/use-scroll-lock.js +143 -0
  101. package/dist/esm/components/live-region.js +148 -0
  102. package/dist/esm/components/menu.js +460 -0
  103. package/dist/esm/components/multi-value.js +122 -0
  104. package/dist/esm/components/option.js +57 -0
  105. package/dist/esm/components/placeholder.js +34 -0
  106. package/dist/esm/components/single-value.js +41 -0
  107. package/dist/esm/creatable.js +15 -0
  108. package/dist/esm/diacritics.js +268 -0
  109. package/dist/esm/filters.js +43 -0
  110. package/dist/esm/index.js +8 -0
  111. package/dist/esm/nonce-provider.js +20 -0
  112. package/dist/esm/select.js +1794 -0
  113. package/dist/esm/state-manager.js +22 -0
  114. package/dist/esm/styles.js +58 -0
  115. package/dist/esm/theme.js +36 -0
  116. package/dist/esm/types.js +1 -0
  117. package/dist/esm/use-async.js +149 -0
  118. package/dist/esm/use-creatable.js +107 -0
  119. package/dist/esm/use-state-manager.js +76 -0
  120. package/dist/esm/utils.js +328 -0
  121. package/dist/types/accessibility/helpers.d.ts +5 -0
  122. package/dist/types/accessibility/index.d.ts +125 -0
  123. package/dist/types/async-creatable.d.ts +10 -0
  124. package/dist/types/async.d.ts +9 -0
  125. package/dist/types/builtins.d.ts +5 -0
  126. package/dist/types/components/containers.d.ts +50 -0
  127. package/dist/types/components/control.d.ts +33 -0
  128. package/dist/types/components/group.d.ts +53 -0
  129. package/dist/types/components/index.d.ts +73 -0
  130. package/dist/types/components/indicators.d.ts +72 -0
  131. package/dist/types/components/input.d.ts +33 -0
  132. package/dist/types/components/internal/a11y-text.d.ts +8 -0
  133. package/dist/types/components/internal/dummy-input.d.ts +9 -0
  134. package/dist/types/components/internal/index.d.ts +4 -0
  135. package/dist/types/components/internal/required-input.d.ts +10 -0
  136. package/dist/types/components/internal/scroll-manager.d.ts +17 -0
  137. package/dist/types/components/internal/use-scroll-capture.d.ts +12 -0
  138. package/dist/types/components/internal/use-scroll-lock.d.ts +9 -0
  139. package/dist/types/components/live-region.d.ts +24 -0
  140. package/dist/types/components/menu.d.ts +130 -0
  141. package/dist/types/components/multi-value.d.ts +47 -0
  142. package/dist/types/components/option.d.ts +49 -0
  143. package/dist/types/components/placeholder.d.ts +22 -0
  144. package/dist/types/components/single-value.d.ts +28 -0
  145. package/dist/types/creatable.d.ts +10 -0
  146. package/dist/types/diacritics.d.ts +1 -0
  147. package/dist/types/filters.d.ts +15 -0
  148. package/dist/types/index.d.ts +28 -0
  149. package/dist/types/nonce-provider.d.ts +8 -0
  150. package/dist/types/select.d.ts +616 -0
  151. package/dist/types/state-manager.d.ts +17 -0
  152. package/dist/types/styles.d.ts +68 -0
  153. package/dist/types/theme.d.ts +27 -0
  154. package/dist/types/types.d.ts +134 -0
  155. package/dist/types/use-async.d.ts +31 -0
  156. package/dist/types/use-creatable.d.ts +46 -0
  157. package/dist/types/use-state-manager.d.ts +15 -0
  158. package/dist/types/utils.d.ts +44 -0
  159. package/dist/types-ts4.5/accessibility/helpers.d.ts +5 -0
  160. package/dist/types-ts4.5/accessibility/index.d.ts +125 -0
  161. package/dist/types-ts4.5/async-creatable.d.ts +10 -0
  162. package/dist/types-ts4.5/async.d.ts +9 -0
  163. package/dist/types-ts4.5/builtins.d.ts +5 -0
  164. package/dist/types-ts4.5/components/containers.d.ts +50 -0
  165. package/dist/types-ts4.5/components/control.d.ts +33 -0
  166. package/dist/types-ts4.5/components/group.d.ts +53 -0
  167. package/dist/types-ts4.5/components/index.d.ts +73 -0
  168. package/dist/types-ts4.5/components/indicators.d.ts +72 -0
  169. package/dist/types-ts4.5/components/input.d.ts +33 -0
  170. package/dist/types-ts4.5/components/internal/a11y-text.d.ts +8 -0
  171. package/dist/types-ts4.5/components/internal/dummy-input.d.ts +9 -0
  172. package/dist/types-ts4.5/components/internal/index.d.ts +4 -0
  173. package/dist/types-ts4.5/components/internal/required-input.d.ts +10 -0
  174. package/dist/types-ts4.5/components/internal/scroll-manager.d.ts +17 -0
  175. package/dist/types-ts4.5/components/internal/use-scroll-capture.d.ts +12 -0
  176. package/dist/types-ts4.5/components/internal/use-scroll-lock.d.ts +9 -0
  177. package/dist/types-ts4.5/components/live-region.d.ts +24 -0
  178. package/dist/types-ts4.5/components/menu.d.ts +130 -0
  179. package/dist/types-ts4.5/components/multi-value.d.ts +47 -0
  180. package/dist/types-ts4.5/components/option.d.ts +49 -0
  181. package/dist/types-ts4.5/components/placeholder.d.ts +22 -0
  182. package/dist/types-ts4.5/components/single-value.d.ts +28 -0
  183. package/dist/types-ts4.5/creatable.d.ts +10 -0
  184. package/dist/types-ts4.5/diacritics.d.ts +1 -0
  185. package/dist/types-ts4.5/filters.d.ts +15 -0
  186. package/dist/types-ts4.5/index.d.ts +28 -0
  187. package/dist/types-ts4.5/nonce-provider.d.ts +8 -0
  188. package/dist/types-ts4.5/select.d.ts +616 -0
  189. package/dist/types-ts4.5/state-manager.d.ts +17 -0
  190. package/dist/types-ts4.5/styles.d.ts +68 -0
  191. package/dist/types-ts4.5/theme.d.ts +27 -0
  192. package/dist/types-ts4.5/types.d.ts +134 -0
  193. package/dist/types-ts4.5/use-async.d.ts +31 -0
  194. package/dist/types-ts4.5/use-creatable.d.ts +46 -0
  195. package/dist/types-ts4.5/use-state-manager.d.ts +15 -0
  196. package/dist/types-ts4.5/utils.d.ts +44 -0
  197. package/package.json +83 -0
@@ -0,0 +1,1803 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.defaultProps = exports.default = void 0;
9
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
12
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
13
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
14
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
15
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
16
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
18
+ var _react = _interopRequireWildcard(require("react"));
19
+ var _helpers = require("./accessibility/helpers");
20
+ var _builtins = require("./builtins");
21
+ var _components = require("./components");
22
+ var _internal = require("./components/internal");
23
+ var _liveRegion = _interopRequireDefault(require("./components/live-region"));
24
+ var _menu = require("./components/menu");
25
+ var _filters = require("./filters");
26
+ var _styles = require("./styles");
27
+ var _theme = require("./theme");
28
+ var _utils = require("./utils");
29
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
30
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
31
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
32
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
33
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
34
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
35
+ var defaultProps = exports.defaultProps = {
36
+ 'aria-live': 'polite',
37
+ backspaceRemovesValue: true,
38
+ blurInputOnSelect: (0, _utils.isTouchCapable)(),
39
+ captureMenuScroll: !(0, _utils.isTouchCapable)(),
40
+ classNames: {},
41
+ closeMenuOnSelect: true,
42
+ closeMenuOnScroll: false,
43
+ components: {},
44
+ controlShouldRenderValue: true,
45
+ escapeClearsValue: false,
46
+ filterOption: (0, _filters.createFilter)(),
47
+ formatGroupLabel: _builtins.formatGroupLabel,
48
+ getOptionLabel: _builtins.getOptionLabel,
49
+ getOptionValue: _builtins.getOptionValue,
50
+ isDisabled: false,
51
+ isLoading: false,
52
+ isMulti: false,
53
+ isRtl: false,
54
+ isSearchable: true,
55
+ isOptionDisabled: _builtins.isOptionDisabled,
56
+ loadingMessage: function loadingMessage() {
57
+ return 'Loading...';
58
+ },
59
+ maxMenuHeight: 300,
60
+ minMenuHeight: 140,
61
+ menuIsOpen: false,
62
+ menuPlacement: 'bottom',
63
+ menuPosition: 'absolute',
64
+ menuShouldBlockScroll: false,
65
+ menuShouldScrollIntoView: !(0, _utils.isMobileDevice)(),
66
+ noOptionsMessage: function noOptionsMessage() {
67
+ return 'No options';
68
+ },
69
+ openMenuOnFocus: false,
70
+ openMenuOnClick: true,
71
+ options: [],
72
+ pageSize: 5,
73
+ placeholder: 'Select...',
74
+ screenReaderStatus: function screenReaderStatus(_ref) {
75
+ var count = _ref.count;
76
+ return "".concat(count, " result").concat(count !== 1 ? 's' : '', " available");
77
+ },
78
+ styles: {},
79
+ tabIndex: 0,
80
+ tabSelectsValue: true,
81
+ unstyled: false
82
+ };
83
+ function toCategorizedOption(props, option, selectValue, index) {
84
+ var isDisabled = _isOptionDisabled(props, option, selectValue);
85
+ var isSelected = _isOptionSelected(props, option, selectValue);
86
+ var label = getOptionLabel(props, option);
87
+ var value = getOptionValue(props, option);
88
+ return {
89
+ type: 'option',
90
+ data: option,
91
+ isDisabled: isDisabled,
92
+ isSelected: isSelected,
93
+ label: label,
94
+ value: value,
95
+ index: index
96
+ };
97
+ }
98
+ function buildCategorizedOptions(props, selectValue) {
99
+ return props.options.map(function (groupOrOption, groupOrOptionIndex) {
100
+ //@ts-ignore
101
+ if ('options' in groupOrOption) {
102
+ var categorizedOptions = groupOrOption.options.map(function (option, optionIndex) {
103
+ return toCategorizedOption(props, option, selectValue, optionIndex);
104
+ }).filter(function (categorizedOption) {
105
+ return isFocusable(props, categorizedOption);
106
+ });
107
+ return categorizedOptions.length > 0 ? {
108
+ type: 'group',
109
+ data: groupOrOption,
110
+ options: categorizedOptions,
111
+ index: groupOrOptionIndex
112
+ } : undefined;
113
+ }
114
+ var categorizedOption = toCategorizedOption(props, groupOrOption, selectValue, groupOrOptionIndex);
115
+ return isFocusable(props, categorizedOption) ? categorizedOption : undefined;
116
+ }).filter(_utils.notNullish);
117
+ }
118
+ function buildFocusableOptionsFromCategorizedOptions(categorizedOptions) {
119
+ return categorizedOptions.reduce(function (optionsAccumulator, categorizedOption) {
120
+ if (categorizedOption.type === 'group') {
121
+ optionsAccumulator.push.apply(optionsAccumulator, (0, _toConsumableArray2.default)(categorizedOption.options.map(function (option) {
122
+ return option.data;
123
+ })));
124
+ } else {
125
+ optionsAccumulator.push(categorizedOption.data);
126
+ }
127
+ return optionsAccumulator;
128
+ }, []);
129
+ }
130
+ function buildFocusableOptionsWithIds(categorizedOptions, optionId) {
131
+ return categorizedOptions.reduce(function (optionsAccumulator, categorizedOption) {
132
+ if (categorizedOption.type === 'group') {
133
+ optionsAccumulator.push.apply(optionsAccumulator, (0, _toConsumableArray2.default)(categorizedOption.options.map(function (option) {
134
+ return {
135
+ data: option.data,
136
+ id: "".concat(optionId, "-").concat(categorizedOption.index, "-").concat(option.index)
137
+ };
138
+ })));
139
+ } else {
140
+ optionsAccumulator.push({
141
+ data: categorizedOption.data,
142
+ id: "".concat(optionId, "-").concat(categorizedOption.index)
143
+ });
144
+ }
145
+ return optionsAccumulator;
146
+ }, []);
147
+ }
148
+ function buildFocusableOptions(props, selectValue) {
149
+ return buildFocusableOptionsFromCategorizedOptions(buildCategorizedOptions(props, selectValue));
150
+ }
151
+ function isFocusable(props, categorizedOption) {
152
+ var _props$inputValue = props.inputValue,
153
+ inputValue = _props$inputValue === void 0 ? '' : _props$inputValue;
154
+ var data = categorizedOption.data,
155
+ isSelected = categorizedOption.isSelected,
156
+ label = categorizedOption.label,
157
+ value = categorizedOption.value;
158
+ return (!shouldHideSelectedOptions(props) || !isSelected) && _filterOption(props, {
159
+ label: label,
160
+ value: value,
161
+ data: data
162
+ }, inputValue);
163
+ }
164
+ function getNextFocusedValue(state, nextSelectValue) {
165
+ var focusedValue = state.focusedValue,
166
+ lastSelectValue = state.selectValue;
167
+ var lastFocusedIndex = lastSelectValue.indexOf(focusedValue);
168
+ if (lastFocusedIndex > -1) {
169
+ var nextFocusedIndex = nextSelectValue.indexOf(focusedValue);
170
+ if (nextFocusedIndex > -1) {
171
+ // the focused value is still in the selectValue, return it
172
+ return focusedValue;
173
+ } else if (lastFocusedIndex < nextSelectValue.length) {
174
+ // the focusedValue is not present in the next selectValue array by
175
+ // reference, so return the new value at the same index
176
+ return nextSelectValue[lastFocusedIndex];
177
+ }
178
+ }
179
+ return null;
180
+ }
181
+ function getNextFocusedOption(state, options) {
182
+ var lastFocusedOption = state.focusedOption;
183
+ return lastFocusedOption && options.indexOf(lastFocusedOption) > -1 ? lastFocusedOption : options[0];
184
+ }
185
+ var getFocusedOptionId = function getFocusedOptionId(focusableOptionsWithIds, focusedOption) {
186
+ var _focusableOptionsWith;
187
+ var focusedOptionId = (_focusableOptionsWith = focusableOptionsWithIds.find(function (option) {
188
+ return option.data === focusedOption;
189
+ })) === null || _focusableOptionsWith === void 0 ? void 0 : _focusableOptionsWith.id;
190
+ return focusedOptionId || null;
191
+ };
192
+ var getOptionLabel = function getOptionLabel(props, data) {
193
+ return props.getOptionLabel(data);
194
+ };
195
+ var getOptionValue = function getOptionValue(props, data) {
196
+ return props.getOptionValue(data);
197
+ };
198
+ function _isOptionDisabled(props, option, selectValue) {
199
+ return typeof props.isOptionDisabled === 'function' ? props.isOptionDisabled(option, selectValue) : false;
200
+ }
201
+ function _isOptionSelected(props, option, selectValue) {
202
+ if (selectValue.indexOf(option) > -1) {
203
+ return true;
204
+ }
205
+ if (typeof props.isOptionSelected === 'function') {
206
+ return props.isOptionSelected(option, selectValue);
207
+ }
208
+ var candidate = getOptionValue(props, option);
209
+ return selectValue.some(function (i) {
210
+ return getOptionValue(props, i) === candidate;
211
+ });
212
+ }
213
+ function _filterOption(props, option, inputValue) {
214
+ return props.filterOption ? props.filterOption(option, inputValue) : true;
215
+ }
216
+ var shouldHideSelectedOptions = function shouldHideSelectedOptions(props) {
217
+ var hideSelectedOptions = props.hideSelectedOptions,
218
+ isMulti = props.isMulti;
219
+ if (hideSelectedOptions === undefined) {
220
+ return isMulti;
221
+ }
222
+ return hideSelectedOptions;
223
+ };
224
+ var instanceId = 1;
225
+
226
+ // eslint-disable-next-line @repo/internal/react/no-class-components
227
+ var Select = exports.default = /*#__PURE__*/function (_Component) {
228
+ (0, _inherits2.default)(Select, _Component);
229
+ var _super = _createSuper(Select);
230
+ // Lifecycle
231
+ // ------------------------------
232
+
233
+ function Select(_props) {
234
+ var _this;
235
+ (0, _classCallCheck2.default)(this, Select);
236
+ _this = _super.call(this, _props);
237
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "state", {
238
+ ariaSelection: null,
239
+ focusedOption: null,
240
+ focusedOptionId: null,
241
+ focusableOptionsWithIds: [],
242
+ focusedValue: null,
243
+ inputIsHidden: false,
244
+ isFocused: false,
245
+ selectValue: [],
246
+ clearFocusValueOnUpdate: false,
247
+ prevWasFocused: false,
248
+ inputIsHiddenAfterUpdate: undefined,
249
+ prevProps: undefined,
250
+ instancePrefix: ''
251
+ });
252
+ // Misc. Instance Properties
253
+ // ------------------------------
254
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "blockOptionHover", false);
255
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "isComposing", false);
256
+ // TODO
257
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "initialTouchX", 0);
258
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "initialTouchY", 0);
259
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "openAfterFocus", false);
260
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "scrollToFocusedOptionOnUpdate", false);
261
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "isAppleDevice", (0, _helpers.isAppleDevice)());
262
+ // Refs
263
+ // ------------------------------
264
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "controlRef", null);
265
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getControlRef", function (ref) {
266
+ _this.controlRef = ref;
267
+ });
268
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "focusedOptionRef", null);
269
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getFocusedOptionRef", function (ref) {
270
+ _this.focusedOptionRef = ref;
271
+ });
272
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "menuListRef", null);
273
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getMenuListRef", function (ref) {
274
+ _this.menuListRef = ref;
275
+ });
276
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "inputRef", null);
277
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getInputRef", function (ref) {
278
+ _this.inputRef = ref;
279
+ });
280
+ // aliased for consumers
281
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "focus", _this.focusInput);
282
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "blur", _this.blurInput);
283
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onChange", function (newValue, actionMeta) {
284
+ var _this$props = _this.props,
285
+ onChange = _this$props.onChange,
286
+ name = _this$props.name;
287
+ actionMeta.name = name;
288
+ _this.ariaOnChange(newValue, actionMeta);
289
+ onChange(newValue, actionMeta);
290
+ });
291
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "setValue", function (newValue, action, option) {
292
+ var _this$props2 = _this.props,
293
+ closeMenuOnSelect = _this$props2.closeMenuOnSelect,
294
+ isMulti = _this$props2.isMulti,
295
+ inputValue = _this$props2.inputValue;
296
+ _this.onInputChange('', {
297
+ action: 'set-value',
298
+ prevInputValue: inputValue
299
+ });
300
+ if (closeMenuOnSelect) {
301
+ _this.setState({
302
+ inputIsHiddenAfterUpdate: !isMulti
303
+ });
304
+ _this.onMenuClose();
305
+ }
306
+ // when the select value should change, we should reset focusedValue
307
+ _this.setState({
308
+ clearFocusValueOnUpdate: true
309
+ });
310
+ _this.onChange(newValue, {
311
+ action: action,
312
+ option: option
313
+ });
314
+ });
315
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "selectOption", function (newValue) {
316
+ var _this$props3 = _this.props,
317
+ blurInputOnSelect = _this$props3.blurInputOnSelect,
318
+ isMulti = _this$props3.isMulti,
319
+ name = _this$props3.name;
320
+ var selectValue = _this.state.selectValue;
321
+ var deselected = isMulti && _this.isOptionSelected(newValue, selectValue);
322
+ var isDisabled = _this.isOptionDisabled(newValue, selectValue);
323
+ if (deselected) {
324
+ var candidate = _this.getOptionValue(newValue);
325
+ _this.setValue((0, _utils.multiValueAsValue)(selectValue.filter(function (i) {
326
+ return _this.getOptionValue(i) !== candidate;
327
+ })), 'deselect-option', newValue);
328
+ } else if (!isDisabled) {
329
+ // Select option if option is not disabled
330
+ if (isMulti) {
331
+ _this.setValue((0, _utils.multiValueAsValue)([].concat((0, _toConsumableArray2.default)(selectValue), [newValue])), 'select-option', newValue);
332
+ } else {
333
+ _this.setValue((0, _utils.singleValueAsValue)(newValue), 'select-option');
334
+ }
335
+ } else {
336
+ _this.ariaOnChange((0, _utils.singleValueAsValue)(newValue), {
337
+ action: 'select-option',
338
+ option: newValue,
339
+ name: name
340
+ });
341
+ return;
342
+ }
343
+ if (blurInputOnSelect) {
344
+ _this.blurInput();
345
+ }
346
+ });
347
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "removeValue", function (removedValue) {
348
+ var isMulti = _this.props.isMulti;
349
+ var selectValue = _this.state.selectValue;
350
+ var candidate = _this.getOptionValue(removedValue);
351
+ var newValueArray = selectValue.filter(function (i) {
352
+ return _this.getOptionValue(i) !== candidate;
353
+ });
354
+ var newValue = (0, _utils.valueTernary)(isMulti, newValueArray, newValueArray[0] || null);
355
+ _this.onChange(newValue, {
356
+ action: 'remove-value',
357
+ removedValue: removedValue
358
+ });
359
+ _this.focusInput();
360
+ });
361
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "clearValue", function () {
362
+ var selectValue = _this.state.selectValue;
363
+ _this.onChange((0, _utils.valueTernary)(_this.props.isMulti, [], null), {
364
+ action: 'clear',
365
+ removedValues: selectValue
366
+ });
367
+ });
368
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "popValue", function () {
369
+ var isMulti = _this.props.isMulti;
370
+ var selectValue = _this.state.selectValue;
371
+ var lastSelectedValue = selectValue[selectValue.length - 1];
372
+ var newValueArray = selectValue.slice(0, selectValue.length - 1);
373
+ var newValue = (0, _utils.valueTernary)(isMulti, newValueArray, newValueArray[0] || null);
374
+ _this.onChange(newValue, {
375
+ action: 'pop-value',
376
+ removedValue: lastSelectedValue
377
+ });
378
+ });
379
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getFocusedOptionId", function (focusedOption) {
380
+ return getFocusedOptionId(_this.state.focusableOptionsWithIds, focusedOption);
381
+ });
382
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getFocusableOptionsWithIds", function () {
383
+ return buildFocusableOptionsWithIds(buildCategorizedOptions(_this.props, _this.state.selectValue), _this.getElementId('option'));
384
+ });
385
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getValue", function () {
386
+ return _this.state.selectValue;
387
+ });
388
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "cx", function () {
389
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
390
+ args[_key] = arguments[_key];
391
+ }
392
+ return _utils.classNames.apply(void 0, [_this.props.classNamePrefix].concat(args));
393
+ });
394
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getOptionLabel", function (data) {
395
+ return getOptionLabel(_this.props, data);
396
+ });
397
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getOptionValue", function (data) {
398
+ return getOptionValue(_this.props, data);
399
+ });
400
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getStyles", function (key, props) {
401
+ var unstyled = _this.props.unstyled;
402
+ var base = _styles.defaultStyles[key](props, unstyled);
403
+ base.boxSizing = 'border-box';
404
+ var custom = _this.props.styles[key];
405
+ return custom ? custom(base, props) : base;
406
+ });
407
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getClassNames", function (key, props) {
408
+ var _this$props$className, _this$props$className2;
409
+ return (_this$props$className = (_this$props$className2 = _this.props.classNames)[key]) === null || _this$props$className === void 0 ? void 0 : _this$props$className.call(_this$props$className2, props);
410
+ });
411
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getElementId", function (element) {
412
+ return "".concat(_this.state.instancePrefix, "-").concat(element);
413
+ });
414
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getComponents", function () {
415
+ return (0, _components.defaultComponents)(_this.props);
416
+ });
417
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "buildCategorizedOptions", function () {
418
+ return buildCategorizedOptions(_this.props, _this.state.selectValue);
419
+ });
420
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getCategorizedOptions", function () {
421
+ return _this.props.menuIsOpen ? _this.buildCategorizedOptions() : [];
422
+ });
423
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "buildFocusableOptions", function () {
424
+ return buildFocusableOptionsFromCategorizedOptions(_this.buildCategorizedOptions());
425
+ });
426
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getFocusableOptions", function () {
427
+ return _this.props.menuIsOpen ? _this.buildFocusableOptions() : [];
428
+ });
429
+ // ==============================
430
+ // Helpers
431
+ // ==============================
432
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "ariaOnChange", function (value, actionMeta) {
433
+ _this.setState({
434
+ ariaSelection: _objectSpread({
435
+ value: value
436
+ }, actionMeta)
437
+ });
438
+ });
439
+ // ==============================
440
+ // Mouse Handlers
441
+ // ==============================
442
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onMenuMouseDown", function (event) {
443
+ if (event.button !== 0) {
444
+ return;
445
+ }
446
+ event.stopPropagation();
447
+ event.preventDefault();
448
+ _this.focusInput();
449
+ });
450
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onMenuMouseMove", function (event) {
451
+ _this.blockOptionHover = false;
452
+ });
453
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onControlMouseDown", function (event) {
454
+ // Event captured by dropdown indicator
455
+ if (event.defaultPrevented) {
456
+ return;
457
+ }
458
+ var openMenuOnClick = _this.props.openMenuOnClick;
459
+ if (!_this.state.isFocused) {
460
+ if (openMenuOnClick) {
461
+ _this.openAfterFocus = true;
462
+ }
463
+ _this.focusInput();
464
+ } else if (!_this.props.menuIsOpen) {
465
+ if (openMenuOnClick) {
466
+ _this.openMenu('first');
467
+ }
468
+ } else {
469
+ if (event.target.tagName !== 'INPUT' && event.target.tagName !== 'TEXTAREA') {
470
+ _this.onMenuClose();
471
+ }
472
+ }
473
+ if (event.target.tagName !== 'INPUT' && event.target.tagName !== 'TEXTAREA') {
474
+ event.preventDefault();
475
+ }
476
+ });
477
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onDropdownIndicatorMouseDown", function (event) {
478
+ // ignore mouse events that weren't triggered by the primary button
479
+ if (event && event.type === 'mousedown' && event.button !== 0) {
480
+ return;
481
+ }
482
+ if (_this.props.isDisabled) {
483
+ return;
484
+ }
485
+ var _this$props4 = _this.props,
486
+ isMulti = _this$props4.isMulti,
487
+ menuIsOpen = _this$props4.menuIsOpen;
488
+ _this.focusInput();
489
+ if (menuIsOpen) {
490
+ _this.setState({
491
+ inputIsHiddenAfterUpdate: !isMulti
492
+ });
493
+ _this.onMenuClose();
494
+ } else {
495
+ _this.openMenu('first');
496
+ }
497
+ event.preventDefault();
498
+ });
499
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onClearIndicatorMouseDown", function (event) {
500
+ // ignore mouse events that weren't triggered by the primary button
501
+ if (event && event.type === 'mousedown' && event.button !== 0) {
502
+ return;
503
+ }
504
+ _this.clearValue();
505
+ event.preventDefault();
506
+ _this.openAfterFocus = false;
507
+ if (event.type === 'touchend') {
508
+ _this.focusInput();
509
+ } else {
510
+ setTimeout(function () {
511
+ return _this.focusInput();
512
+ });
513
+ }
514
+ });
515
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onScroll", function (event) {
516
+ if (typeof _this.props.closeMenuOnScroll === 'boolean') {
517
+ if (event.target instanceof HTMLElement && (0, _utils.isDocumentElement)(event.target)) {
518
+ _this.props.onMenuClose();
519
+ }
520
+ } else if (typeof _this.props.closeMenuOnScroll === 'function') {
521
+ if (_this.props.closeMenuOnScroll(event)) {
522
+ _this.props.onMenuClose();
523
+ }
524
+ }
525
+ });
526
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onCompositionStart", function () {
527
+ _this.isComposing = true;
528
+ });
529
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onCompositionEnd", function () {
530
+ _this.isComposing = false;
531
+ });
532
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onTouchStart", function (_ref2) {
533
+ var touches = _ref2.touches;
534
+ var touch = touches && touches.item(0);
535
+ if (!touch) {
536
+ return;
537
+ }
538
+ _this.initialTouchX = touch.clientX;
539
+ _this.initialTouchY = touch.clientY;
540
+ _this.userIsDragging = false;
541
+ });
542
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onTouchMove", function (_ref3) {
543
+ var touches = _ref3.touches;
544
+ var touch = touches && touches.item(0);
545
+ if (!touch) {
546
+ return;
547
+ }
548
+ var deltaX = Math.abs(touch.clientX - _this.initialTouchX);
549
+ var deltaY = Math.abs(touch.clientY - _this.initialTouchY);
550
+ var moveThreshold = 5;
551
+ _this.userIsDragging = deltaX > moveThreshold || deltaY > moveThreshold;
552
+ });
553
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onTouchEnd", function (event) {
554
+ if (_this.userIsDragging) {
555
+ return;
556
+ }
557
+
558
+ // close the menu if the user taps outside
559
+ // we're checking on event.target here instead of event.currentTarget, because we want to assert information
560
+ // on events on child elements, not the document (which we've attached this handler to).
561
+ if (_this.controlRef && !_this.controlRef.contains(event.target) && _this.menuListRef && !_this.menuListRef.contains(event.target)) {
562
+ _this.blurInput();
563
+ }
564
+
565
+ // reset move vars
566
+ _this.initialTouchX = 0;
567
+ _this.initialTouchY = 0;
568
+ });
569
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onControlTouchEnd", function (event) {
570
+ if (_this.userIsDragging) {
571
+ return;
572
+ }
573
+ _this.onControlMouseDown(event);
574
+ });
575
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onClearIndicatorTouchEnd", function (event) {
576
+ if (_this.userIsDragging) {
577
+ return;
578
+ }
579
+ _this.onClearIndicatorMouseDown(event);
580
+ });
581
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onDropdownIndicatorTouchEnd", function (event) {
582
+ if (_this.userIsDragging) {
583
+ return;
584
+ }
585
+ _this.onDropdownIndicatorMouseDown(event);
586
+ });
587
+ // ==============================
588
+ // Focus Handlers
589
+ // ==============================
590
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleInputChange", function (event) {
591
+ var prevInputValue = _this.props.inputValue;
592
+ var inputValue = event.currentTarget.value;
593
+ _this.setState({
594
+ inputIsHiddenAfterUpdate: false
595
+ });
596
+ _this.onInputChange(inputValue, {
597
+ action: 'input-change',
598
+ prevInputValue: prevInputValue
599
+ });
600
+ if (!_this.props.menuIsOpen) {
601
+ _this.onMenuOpen();
602
+ }
603
+ });
604
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onInputFocus", function (event) {
605
+ if (_this.props.onFocus) {
606
+ _this.props.onFocus(event);
607
+ }
608
+ _this.setState({
609
+ inputIsHiddenAfterUpdate: false,
610
+ isFocused: true
611
+ });
612
+ if (_this.openAfterFocus || _this.props.openMenuOnFocus) {
613
+ _this.openMenu('first');
614
+ }
615
+ _this.openAfterFocus = false;
616
+ });
617
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onInputBlur", function (event) {
618
+ var prevInputValue = _this.props.inputValue;
619
+ if (_this.menuListRef && _this.menuListRef.contains(document.activeElement)) {
620
+ _this.inputRef.focus();
621
+ return;
622
+ }
623
+ if (_this.props.onBlur) {
624
+ _this.props.onBlur(event);
625
+ }
626
+ _this.onInputChange('', {
627
+ action: 'input-blur',
628
+ prevInputValue: prevInputValue
629
+ });
630
+ _this.onMenuClose();
631
+ _this.setState({
632
+ focusedValue: null,
633
+ isFocused: false
634
+ });
635
+ });
636
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onOptionHover", function (focusedOption) {
637
+ if (_this.blockOptionHover || _this.state.focusedOption === focusedOption) {
638
+ return;
639
+ }
640
+ var options = _this.getFocusableOptions();
641
+ var focusedOptionIndex = options.indexOf(focusedOption);
642
+ _this.setState({
643
+ focusedOption: focusedOption,
644
+ focusedOptionId: focusedOptionIndex > -1 ? _this.getFocusedOptionId(focusedOption) : null
645
+ });
646
+ });
647
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "shouldHideSelectedOptions", function () {
648
+ return shouldHideSelectedOptions(_this.props);
649
+ });
650
+ // If the hidden input gets focus through form submit,
651
+ // redirect focus to focusable input.
652
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onValueInputFocus", function (e) {
653
+ e.preventDefault();
654
+ e.stopPropagation();
655
+ _this.focus();
656
+ });
657
+ // ==============================
658
+ // Keyboard Handlers
659
+ // ==============================
660
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onKeyDown", function (event) {
661
+ var _this$props5 = _this.props,
662
+ isMulti = _this$props5.isMulti,
663
+ backspaceRemovesValue = _this$props5.backspaceRemovesValue,
664
+ escapeClearsValue = _this$props5.escapeClearsValue,
665
+ inputValue = _this$props5.inputValue,
666
+ isClearable = _this$props5.isClearable,
667
+ isDisabled = _this$props5.isDisabled,
668
+ menuIsOpen = _this$props5.menuIsOpen,
669
+ onKeyDown = _this$props5.onKeyDown,
670
+ tabSelectsValue = _this$props5.tabSelectsValue,
671
+ openMenuOnFocus = _this$props5.openMenuOnFocus;
672
+ var _this$state = _this.state,
673
+ focusedOption = _this$state.focusedOption,
674
+ focusedValue = _this$state.focusedValue,
675
+ selectValue = _this$state.selectValue;
676
+ if (isDisabled) {
677
+ return;
678
+ }
679
+ if (typeof onKeyDown === 'function') {
680
+ onKeyDown(event);
681
+ if (event.defaultPrevented) {
682
+ return;
683
+ }
684
+ }
685
+
686
+ // Block option hover events when the user has just pressed a key
687
+ _this.blockOptionHover = true;
688
+ switch (event.key) {
689
+ case 'ArrowLeft':
690
+ if (!isMulti || inputValue) {
691
+ return;
692
+ }
693
+ _this.focusValue('previous');
694
+ break;
695
+ case 'ArrowRight':
696
+ if (!isMulti || inputValue) {
697
+ return;
698
+ }
699
+ _this.focusValue('next');
700
+ break;
701
+ case 'Delete':
702
+ case 'Backspace':
703
+ if (inputValue) {
704
+ return;
705
+ }
706
+ if (focusedValue) {
707
+ _this.removeValue(focusedValue);
708
+ } else {
709
+ if (!backspaceRemovesValue) {
710
+ return;
711
+ }
712
+ if (isMulti) {
713
+ _this.popValue();
714
+ } else if (isClearable) {
715
+ _this.clearValue();
716
+ }
717
+ }
718
+ break;
719
+ case 'Tab':
720
+ if (_this.isComposing) {
721
+ return;
722
+ }
723
+ if (event.shiftKey || !menuIsOpen || !tabSelectsValue || !focusedOption ||
724
+ // don't capture the event if the menu opens on focus and the focused
725
+ // option is already selected; it breaks the flow of navigation
726
+ openMenuOnFocus && _this.isOptionSelected(focusedOption, selectValue)) {
727
+ return;
728
+ }
729
+ _this.selectOption(focusedOption);
730
+ break;
731
+ case 'Enter':
732
+ if (event.keyCode === 229) {
733
+ // ignore the keydown event from an Input Method Editor(IME)
734
+ // ref. https://www.w3.org/TR/uievents/#determine-keydown-keyup-keyCode
735
+ break;
736
+ }
737
+ if (menuIsOpen) {
738
+ if (!focusedOption) {
739
+ return;
740
+ }
741
+ if (_this.isComposing) {
742
+ return;
743
+ }
744
+ _this.selectOption(focusedOption);
745
+ break;
746
+ }
747
+ return;
748
+ case 'Escape':
749
+ if (menuIsOpen) {
750
+ _this.setState({
751
+ inputIsHiddenAfterUpdate: false
752
+ });
753
+ _this.onInputChange('', {
754
+ action: 'menu-close',
755
+ prevInputValue: inputValue
756
+ });
757
+ _this.onMenuClose();
758
+ } else if (isClearable && escapeClearsValue) {
759
+ _this.clearValue();
760
+ }
761
+ break;
762
+ case ' ':
763
+ // space
764
+ if (inputValue) {
765
+ return;
766
+ }
767
+ if (!menuIsOpen) {
768
+ _this.openMenu('first');
769
+ break;
770
+ }
771
+ if (!focusedOption) {
772
+ return;
773
+ }
774
+ _this.selectOption(focusedOption);
775
+ break;
776
+ case 'ArrowUp':
777
+ if (menuIsOpen) {
778
+ _this.focusOption('up');
779
+ } else {
780
+ _this.openMenu('last');
781
+ }
782
+ break;
783
+ case 'ArrowDown':
784
+ if (menuIsOpen) {
785
+ _this.focusOption('down');
786
+ } else {
787
+ _this.openMenu('first');
788
+ }
789
+ break;
790
+ case 'PageUp':
791
+ if (!menuIsOpen) {
792
+ return;
793
+ }
794
+ _this.focusOption('pageup');
795
+ break;
796
+ case 'PageDown':
797
+ if (!menuIsOpen) {
798
+ return;
799
+ }
800
+ _this.focusOption('pagedown');
801
+ break;
802
+ case 'Home':
803
+ if (!menuIsOpen) {
804
+ return;
805
+ }
806
+ _this.focusOption('first');
807
+ break;
808
+ case 'End':
809
+ if (!menuIsOpen) {
810
+ return;
811
+ }
812
+ _this.focusOption('last');
813
+ break;
814
+ default:
815
+ return;
816
+ }
817
+ event.preventDefault();
818
+ });
819
+ _this.state.instancePrefix = 'react-select-' + (_this.props.instanceId || ++instanceId);
820
+ //@ts-ignore
821
+ _this.state.selectValue = (0, _utils.cleanValue)(_props.value);
822
+ // Set focusedOption if menuIsOpen is set on init (e.g. defaultMenuIsOpen)
823
+ if (_props.menuIsOpen && _this.state.selectValue.length) {
824
+ var focusableOptionsWithIds = _this.getFocusableOptionsWithIds();
825
+ var focusableOptions = _this.buildFocusableOptions();
826
+ var optionIndex = focusableOptions.indexOf(_this.state.selectValue[0]);
827
+ _this.state.focusableOptionsWithIds = focusableOptionsWithIds;
828
+ _this.state.focusedOption = focusableOptions[optionIndex];
829
+ _this.state.focusedOptionId = getFocusedOptionId(focusableOptionsWithIds, focusableOptions[optionIndex]);
830
+ }
831
+ return _this;
832
+ }
833
+ (0, _createClass2.default)(Select, [{
834
+ key: "componentDidMount",
835
+ value: function componentDidMount() {
836
+ this.startListeningComposition();
837
+ this.startListeningToTouch();
838
+ if (this.props.closeMenuOnScroll && document && document.addEventListener) {
839
+ // Listen to all scroll events, and filter them out inside of 'onScroll'
840
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
841
+ document.addEventListener('scroll', this.onScroll, true);
842
+ }
843
+ if (this.props.autoFocus) {
844
+ this.focusInput();
845
+ }
846
+
847
+ // Scroll focusedOption into view if menuIsOpen is set on mount (e.g. defaultMenuIsOpen)
848
+ if (this.props.menuIsOpen && this.state.focusedOption && this.menuListRef && this.focusedOptionRef) {
849
+ (0, _utils.scrollIntoView)(this.menuListRef, this.focusedOptionRef);
850
+ }
851
+ }
852
+ }, {
853
+ key: "componentDidUpdate",
854
+ value: function componentDidUpdate(prevProps) {
855
+ var _this$props6 = this.props,
856
+ isDisabled = _this$props6.isDisabled,
857
+ menuIsOpen = _this$props6.menuIsOpen;
858
+ var isFocused = this.state.isFocused;
859
+ if (
860
+ // ensure focus is restored correctly when the control becomes enabled
861
+ isFocused && !isDisabled && prevProps.isDisabled ||
862
+ // ensure focus is on the Input when the menu opens
863
+ isFocused && menuIsOpen && !prevProps.menuIsOpen) {
864
+ this.focusInput();
865
+ }
866
+ if (isFocused && isDisabled && !prevProps.isDisabled) {
867
+ // ensure select state gets blurred in case Select is programmatically disabled while focused
868
+ // eslint-disable-next-line react/no-did-update-set-state
869
+ this.setState({
870
+ isFocused: false
871
+ }, this.onMenuClose);
872
+ } else if (!isFocused && !isDisabled && prevProps.isDisabled && this.inputRef === document.activeElement) {
873
+ // ensure select state gets focused in case Select is programatically re-enabled while focused (Firefox)
874
+ // eslint-disable-next-line react/no-did-update-set-state
875
+ this.setState({
876
+ isFocused: true
877
+ });
878
+ }
879
+
880
+ // scroll the focused option into view if necessary
881
+ if (this.menuListRef && this.focusedOptionRef && this.scrollToFocusedOptionOnUpdate) {
882
+ (0, _utils.scrollIntoView)(this.menuListRef, this.focusedOptionRef);
883
+ this.scrollToFocusedOptionOnUpdate = false;
884
+ }
885
+ }
886
+ }, {
887
+ key: "componentWillUnmount",
888
+ value: function componentWillUnmount() {
889
+ this.stopListeningComposition();
890
+ this.stopListeningToTouch();
891
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
892
+ document.removeEventListener('scroll', this.onScroll, true);
893
+ }
894
+
895
+ // ==============================
896
+ // Consumer Handlers
897
+ // ==============================
898
+ }, {
899
+ key: "onMenuOpen",
900
+ value: function onMenuOpen() {
901
+ this.props.onMenuOpen();
902
+ }
903
+ }, {
904
+ key: "onMenuClose",
905
+ value: function onMenuClose() {
906
+ this.onInputChange('', {
907
+ action: 'menu-close',
908
+ prevInputValue: this.props.inputValue
909
+ });
910
+ this.props.onMenuClose();
911
+ }
912
+ }, {
913
+ key: "onInputChange",
914
+ value: function onInputChange(newValue, actionMeta) {
915
+ this.props.onInputChange(newValue, actionMeta);
916
+ }
917
+
918
+ // ==============================
919
+ // Methods
920
+ // ==============================
921
+ }, {
922
+ key: "focusInput",
923
+ value: function focusInput() {
924
+ if (!this.inputRef) {
925
+ return;
926
+ }
927
+ this.inputRef.focus();
928
+ }
929
+ }, {
930
+ key: "blurInput",
931
+ value: function blurInput() {
932
+ if (!this.inputRef) {
933
+ return;
934
+ }
935
+ this.inputRef.blur();
936
+ }
937
+ }, {
938
+ key: "openMenu",
939
+ value: function openMenu(focusOption) {
940
+ var _this2 = this;
941
+ var _this$state2 = this.state,
942
+ selectValue = _this$state2.selectValue,
943
+ isFocused = _this$state2.isFocused;
944
+ var focusableOptions = this.buildFocusableOptions();
945
+ var openAtIndex = focusOption === 'first' ? 0 : focusableOptions.length - 1;
946
+ if (!this.props.isMulti) {
947
+ var selectedIndex = focusableOptions.indexOf(selectValue[0]);
948
+ if (selectedIndex > -1) {
949
+ openAtIndex = selectedIndex;
950
+ }
951
+ }
952
+
953
+ // only scroll if the menu isn't already open
954
+ this.scrollToFocusedOptionOnUpdate = !(isFocused && this.menuListRef);
955
+ this.setState({
956
+ inputIsHiddenAfterUpdate: false,
957
+ focusedValue: null,
958
+ focusedOption: focusableOptions[openAtIndex],
959
+ focusedOptionId: this.getFocusedOptionId(focusableOptions[openAtIndex])
960
+ }, function () {
961
+ return _this2.onMenuOpen();
962
+ });
963
+ }
964
+ }, {
965
+ key: "focusValue",
966
+ value: function focusValue(direction) {
967
+ var _this$state3 = this.state,
968
+ selectValue = _this$state3.selectValue,
969
+ focusedValue = _this$state3.focusedValue;
970
+
971
+ // Only multiselects support value focusing
972
+ if (!this.props.isMulti) {
973
+ return;
974
+ }
975
+ this.setState({
976
+ focusedOption: null
977
+ });
978
+ var focusedIndex = selectValue.indexOf(focusedValue);
979
+ if (!focusedValue) {
980
+ focusedIndex = -1;
981
+ }
982
+ var lastIndex = selectValue.length - 1;
983
+ var nextFocus = -1;
984
+ if (!selectValue.length) {
985
+ return;
986
+ }
987
+ switch (direction) {
988
+ case 'previous':
989
+ if (focusedIndex === 0) {
990
+ // don't cycle from the start to the end
991
+ nextFocus = 0;
992
+ } else if (focusedIndex === -1) {
993
+ // if nothing is focused, focus the last value first
994
+ nextFocus = lastIndex;
995
+ } else {
996
+ nextFocus = focusedIndex - 1;
997
+ }
998
+ break;
999
+ case 'next':
1000
+ if (focusedIndex > -1 && focusedIndex < lastIndex) {
1001
+ nextFocus = focusedIndex + 1;
1002
+ }
1003
+ break;
1004
+ }
1005
+ this.setState({
1006
+ inputIsHidden: nextFocus !== -1,
1007
+ focusedValue: selectValue[nextFocus]
1008
+ });
1009
+ }
1010
+ }, {
1011
+ key: "focusOption",
1012
+ value: function focusOption() {
1013
+ var direction = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'first';
1014
+ var pageSize = this.props.pageSize;
1015
+ var focusedOption = this.state.focusedOption;
1016
+ var options = this.getFocusableOptions();
1017
+ if (!options.length) {
1018
+ return;
1019
+ }
1020
+ var nextFocus = 0; // handles 'first'
1021
+ var focusedIndex = options.indexOf(focusedOption);
1022
+ if (!focusedOption) {
1023
+ focusedIndex = -1;
1024
+ }
1025
+ if (direction === 'up') {
1026
+ nextFocus = focusedIndex > 0 ? focusedIndex - 1 : options.length - 1;
1027
+ } else if (direction === 'down') {
1028
+ nextFocus = (focusedIndex + 1) % options.length;
1029
+ } else if (direction === 'pageup') {
1030
+ nextFocus = focusedIndex - pageSize;
1031
+ if (nextFocus < 0) {
1032
+ nextFocus = 0;
1033
+ }
1034
+ } else if (direction === 'pagedown') {
1035
+ nextFocus = focusedIndex + pageSize;
1036
+ if (nextFocus > options.length - 1) {
1037
+ nextFocus = options.length - 1;
1038
+ }
1039
+ } else if (direction === 'last') {
1040
+ nextFocus = options.length - 1;
1041
+ }
1042
+ this.scrollToFocusedOptionOnUpdate = true;
1043
+ this.setState({
1044
+ focusedOption: options[nextFocus],
1045
+ focusedValue: null,
1046
+ focusedOptionId: this.getFocusedOptionId(options[nextFocus])
1047
+ });
1048
+ }
1049
+ }, {
1050
+ key: "getTheme",
1051
+ value:
1052
+ // ==============================
1053
+ // Getters
1054
+ // ==============================
1055
+
1056
+ function getTheme() {
1057
+ // Use the default theme if there are no customisations.
1058
+ if (!this.props.theme) {
1059
+ return _theme.defaultTheme;
1060
+ }
1061
+ // If the theme prop is a function, assume the function
1062
+ // knows how to merge the passed-in default theme with
1063
+ // its own modifications.
1064
+ if (typeof this.props.theme === 'function') {
1065
+ return this.props.theme(_theme.defaultTheme);
1066
+ }
1067
+ // Otherwise, if a plain theme object was passed in,
1068
+ // overlay it with the default theme.
1069
+ return _objectSpread(_objectSpread({}, _theme.defaultTheme), this.props.theme);
1070
+ }
1071
+ }, {
1072
+ key: "getCommonProps",
1073
+ value: function getCommonProps() {
1074
+ var clearValue = this.clearValue,
1075
+ cx = this.cx,
1076
+ getStyles = this.getStyles,
1077
+ getClassNames = this.getClassNames,
1078
+ getValue = this.getValue,
1079
+ selectOption = this.selectOption,
1080
+ setValue = this.setValue,
1081
+ props = this.props;
1082
+ var isMulti = props.isMulti,
1083
+ isRtl = props.isRtl,
1084
+ options = props.options;
1085
+ var hasValue = this.hasValue();
1086
+ return {
1087
+ clearValue: clearValue,
1088
+ cx: cx,
1089
+ getStyles: getStyles,
1090
+ getClassNames: getClassNames,
1091
+ getValue: getValue,
1092
+ hasValue: hasValue,
1093
+ isMulti: isMulti,
1094
+ isRtl: isRtl,
1095
+ options: options,
1096
+ selectOption: selectOption,
1097
+ selectProps: props,
1098
+ setValue: setValue,
1099
+ theme: this.getTheme()
1100
+ };
1101
+ }
1102
+ }, {
1103
+ key: "hasValue",
1104
+ value: function hasValue() {
1105
+ var selectValue = this.state.selectValue;
1106
+ return selectValue.length > 0;
1107
+ }
1108
+ }, {
1109
+ key: "hasOptions",
1110
+ value: function hasOptions() {
1111
+ return !!this.getFocusableOptions().length;
1112
+ }
1113
+ }, {
1114
+ key: "isClearable",
1115
+ value: function isClearable() {
1116
+ var _this$props7 = this.props,
1117
+ isClearable = _this$props7.isClearable,
1118
+ isMulti = _this$props7.isMulti;
1119
+
1120
+ // single select, by default, IS NOT clearable
1121
+ // multi select, by default, IS clearable
1122
+ if (isClearable === undefined) {
1123
+ return isMulti;
1124
+ }
1125
+ return isClearable;
1126
+ }
1127
+ }, {
1128
+ key: "isOptionDisabled",
1129
+ value: function isOptionDisabled(option, selectValue) {
1130
+ return _isOptionDisabled(this.props, option, selectValue);
1131
+ }
1132
+ }, {
1133
+ key: "isOptionSelected",
1134
+ value: function isOptionSelected(option, selectValue) {
1135
+ return _isOptionSelected(this.props, option, selectValue);
1136
+ }
1137
+ }, {
1138
+ key: "filterOption",
1139
+ value: function filterOption(option, inputValue) {
1140
+ return _filterOption(this.props, option, inputValue);
1141
+ }
1142
+ }, {
1143
+ key: "formatOptionLabel",
1144
+ value: function formatOptionLabel(data, context) {
1145
+ if (typeof this.props.formatOptionLabel === 'function') {
1146
+ var _inputValue = this.props.inputValue;
1147
+ var _selectValue = this.state.selectValue;
1148
+ return this.props.formatOptionLabel(data, {
1149
+ context: context,
1150
+ inputValue: _inputValue,
1151
+ selectValue: _selectValue
1152
+ });
1153
+ } else {
1154
+ return this.getOptionLabel(data);
1155
+ }
1156
+ }
1157
+ }, {
1158
+ key: "formatGroupLabel",
1159
+ value: function formatGroupLabel(data) {
1160
+ return this.props.formatGroupLabel(data);
1161
+ }
1162
+ }, {
1163
+ key: "startListeningComposition",
1164
+ value:
1165
+ // ==============================
1166
+ // Composition Handlers
1167
+ // ==============================
1168
+
1169
+ function startListeningComposition() {
1170
+ if (document && document.addEventListener) {
1171
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
1172
+ document.addEventListener('compositionstart', this.onCompositionStart, false);
1173
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
1174
+ document.addEventListener('compositionend', this.onCompositionEnd, false);
1175
+ }
1176
+ }
1177
+ }, {
1178
+ key: "stopListeningComposition",
1179
+ value: function stopListeningComposition() {
1180
+ if (document && document.removeEventListener) {
1181
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
1182
+ document.removeEventListener('compositionstart', this.onCompositionStart);
1183
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
1184
+ document.removeEventListener('compositionend', this.onCompositionEnd);
1185
+ }
1186
+ }
1187
+ }, {
1188
+ key: "startListeningToTouch",
1189
+ value:
1190
+ // ==============================
1191
+ // Touch Handlers
1192
+ // ==============================
1193
+
1194
+ function startListeningToTouch() {
1195
+ if (document && document.addEventListener) {
1196
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
1197
+ document.addEventListener('touchstart', this.onTouchStart, false);
1198
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
1199
+ document.addEventListener('touchmove', this.onTouchMove, false);
1200
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
1201
+ document.addEventListener('touchend', this.onTouchEnd, false);
1202
+ }
1203
+ }
1204
+ }, {
1205
+ key: "stopListeningToTouch",
1206
+ value: function stopListeningToTouch() {
1207
+ if (document && document.removeEventListener) {
1208
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
1209
+ document.removeEventListener('touchstart', this.onTouchStart);
1210
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
1211
+ document.removeEventListener('touchmove', this.onTouchMove);
1212
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
1213
+ document.removeEventListener('touchend', this.onTouchEnd);
1214
+ }
1215
+ }
1216
+ }, {
1217
+ key: "renderInput",
1218
+ value:
1219
+ // ==============================
1220
+ // Renderers
1221
+ // ==============================
1222
+ function renderInput() {
1223
+ var _this$props8 = this.props,
1224
+ isDisabled = _this$props8.isDisabled,
1225
+ isSearchable = _this$props8.isSearchable,
1226
+ inputId = _this$props8.inputId,
1227
+ inputValue = _this$props8.inputValue,
1228
+ tabIndex = _this$props8.tabIndex,
1229
+ form = _this$props8.form,
1230
+ menuIsOpen = _this$props8.menuIsOpen,
1231
+ required = _this$props8.required;
1232
+ var _this$getComponents = this.getComponents(),
1233
+ Input = _this$getComponents.Input;
1234
+ var _this$state4 = this.state,
1235
+ inputIsHidden = _this$state4.inputIsHidden,
1236
+ ariaSelection = _this$state4.ariaSelection;
1237
+ var commonProps = this.commonProps;
1238
+ var id = inputId || this.getElementId('input');
1239
+
1240
+ // aria attributes makes the JSX "noisy", separated for clarity
1241
+ var ariaAttributes = _objectSpread(_objectSpread(_objectSpread({
1242
+ 'aria-autocomplete': 'list',
1243
+ 'aria-expanded': menuIsOpen,
1244
+ 'aria-haspopup': 'listbox',
1245
+ 'aria-errormessage': this.props['aria-errormessage'],
1246
+ 'aria-describedby': this.props['aria-describedby'],
1247
+ 'aria-invalid': this.props['aria-invalid'],
1248
+ 'aria-label': this.props['aria-label'],
1249
+ 'aria-labelledby': this.props['aria-labelledby'],
1250
+ 'aria-required': required,
1251
+ role: 'combobox',
1252
+ 'aria-activedescendant': this.isAppleDevice ? undefined : this.state.focusedOptionId
1253
+ }, menuIsOpen && {
1254
+ 'aria-controls': this.getElementId('listbox')
1255
+ }), !isSearchable && {
1256
+ 'aria-readonly': true
1257
+ }), this.hasValue() ? (ariaSelection === null || ariaSelection === void 0 ? void 0 : ariaSelection.action) === 'initial-input-focus' && {
1258
+ 'aria-describedby': this.getElementId('live-region')
1259
+ } : {
1260
+ 'aria-describedby': this.getElementId('placeholder')
1261
+ });
1262
+ if (!isSearchable) {
1263
+ // use a dummy input to maintain focus/blur functionality
1264
+ return (
1265
+ /*#__PURE__*/
1266
+ //@ts-ignore
1267
+ _react.default.createElement(_internal.DummyInput, (0, _extends2.default)({
1268
+ id: id,
1269
+ innerRef: this.getInputRef,
1270
+ onBlur: this.onInputBlur,
1271
+ onChange: _utils.noop,
1272
+ onFocus: this.onInputFocus,
1273
+ disabled: isDisabled,
1274
+ tabIndex: tabIndex,
1275
+ inputMode: "none",
1276
+ form: form,
1277
+ value: ""
1278
+ }, ariaAttributes))
1279
+ );
1280
+ }
1281
+ return /*#__PURE__*/_react.default.createElement(Input, (0, _extends2.default)({}, commonProps, {
1282
+ autoCapitalize: "none",
1283
+ autoComplete: "off",
1284
+ autoCorrect: "off",
1285
+ id: id,
1286
+ innerRef: this.getInputRef,
1287
+ isDisabled: isDisabled,
1288
+ isHidden: inputIsHidden,
1289
+ onBlur: this.onInputBlur,
1290
+ onChange: this.handleInputChange,
1291
+ onFocus: this.onInputFocus,
1292
+ spellCheck: "false",
1293
+ tabIndex: tabIndex,
1294
+ form: form,
1295
+ type: "text",
1296
+ value: inputValue
1297
+ }, ariaAttributes));
1298
+ }
1299
+ }, {
1300
+ key: "renderPlaceholderOrValue",
1301
+ value: function renderPlaceholderOrValue() {
1302
+ var _this3 = this;
1303
+ var _this$getComponents2 = this.getComponents(),
1304
+ MultiValue = _this$getComponents2.MultiValue,
1305
+ MultiValueContainer = _this$getComponents2.MultiValueContainer,
1306
+ MultiValueLabel = _this$getComponents2.MultiValueLabel,
1307
+ MultiValueRemove = _this$getComponents2.MultiValueRemove,
1308
+ SingleValue = _this$getComponents2.SingleValue,
1309
+ Placeholder = _this$getComponents2.Placeholder;
1310
+ var commonProps = this.commonProps;
1311
+ var _this$props9 = this.props,
1312
+ controlShouldRenderValue = _this$props9.controlShouldRenderValue,
1313
+ isDisabled = _this$props9.isDisabled,
1314
+ isMulti = _this$props9.isMulti,
1315
+ inputValue = _this$props9.inputValue,
1316
+ placeholder = _this$props9.placeholder;
1317
+ var _this$state5 = this.state,
1318
+ selectValue = _this$state5.selectValue,
1319
+ focusedValue = _this$state5.focusedValue,
1320
+ isFocused = _this$state5.isFocused;
1321
+ if (!this.hasValue() || !controlShouldRenderValue) {
1322
+ return inputValue ? null : /*#__PURE__*/_react.default.createElement(Placeholder, (0, _extends2.default)({}, commonProps, {
1323
+ key: "placeholder",
1324
+ isDisabled: isDisabled,
1325
+ isFocused: isFocused,
1326
+ innerProps: {
1327
+ id: this.getElementId('placeholder')
1328
+ }
1329
+ }), placeholder);
1330
+ }
1331
+ if (isMulti) {
1332
+ return selectValue.map(function (opt, index) {
1333
+ var isOptionFocused = opt === focusedValue;
1334
+ var key = "".concat(_this3.getOptionLabel(opt), "-").concat(_this3.getOptionValue(opt));
1335
+ return /*#__PURE__*/_react.default.createElement(MultiValue, (0, _extends2.default)({}, commonProps, {
1336
+ components: {
1337
+ Container: MultiValueContainer,
1338
+ Label: MultiValueLabel,
1339
+ Remove: MultiValueRemove
1340
+ },
1341
+ isFocused: isOptionFocused,
1342
+ isDisabled: isDisabled,
1343
+ key: key,
1344
+ index: index,
1345
+ removeProps: {
1346
+ onClick: function onClick() {
1347
+ return _this3.removeValue(opt);
1348
+ },
1349
+ onTouchEnd: function onTouchEnd() {
1350
+ return _this3.removeValue(opt);
1351
+ },
1352
+ onMouseDown: function onMouseDown(e) {
1353
+ e.preventDefault();
1354
+ }
1355
+ },
1356
+ data: opt
1357
+ }), _this3.formatOptionLabel(opt, 'value'));
1358
+ });
1359
+ }
1360
+ if (inputValue) {
1361
+ return null;
1362
+ }
1363
+ var singleValue = selectValue[0];
1364
+ return /*#__PURE__*/_react.default.createElement(SingleValue, (0, _extends2.default)({}, commonProps, {
1365
+ data: singleValue,
1366
+ isDisabled: isDisabled
1367
+ }), this.formatOptionLabel(singleValue, 'value'));
1368
+ }
1369
+ }, {
1370
+ key: "renderClearIndicator",
1371
+ value: function renderClearIndicator() {
1372
+ var _this$getComponents3 = this.getComponents(),
1373
+ ClearIndicator = _this$getComponents3.ClearIndicator;
1374
+ var commonProps = this.commonProps;
1375
+ var _this$props10 = this.props,
1376
+ isDisabled = _this$props10.isDisabled,
1377
+ isLoading = _this$props10.isLoading;
1378
+ var isFocused = this.state.isFocused;
1379
+ if (!this.isClearable() || !ClearIndicator || isDisabled || !this.hasValue() || isLoading) {
1380
+ return null;
1381
+ }
1382
+ var innerProps = {
1383
+ onMouseDown: this.onClearIndicatorMouseDown,
1384
+ onTouchEnd: this.onClearIndicatorTouchEnd,
1385
+ 'aria-hidden': 'true'
1386
+ };
1387
+ return /*#__PURE__*/_react.default.createElement(ClearIndicator, (0, _extends2.default)({}, commonProps, {
1388
+ innerProps: innerProps,
1389
+ isFocused: isFocused
1390
+ }));
1391
+ }
1392
+ }, {
1393
+ key: "renderLoadingIndicator",
1394
+ value: function renderLoadingIndicator() {
1395
+ var _this$getComponents4 = this.getComponents(),
1396
+ LoadingIndicator = _this$getComponents4.LoadingIndicator;
1397
+ var commonProps = this.commonProps;
1398
+ var _this$props11 = this.props,
1399
+ isDisabled = _this$props11.isDisabled,
1400
+ isLoading = _this$props11.isLoading;
1401
+ var isFocused = this.state.isFocused;
1402
+ if (!LoadingIndicator || !isLoading) {
1403
+ return null;
1404
+ }
1405
+ var innerProps = {
1406
+ 'aria-hidden': 'true'
1407
+ };
1408
+ return /*#__PURE__*/_react.default.createElement(LoadingIndicator, (0, _extends2.default)({}, commonProps, {
1409
+ innerProps: innerProps,
1410
+ isDisabled: isDisabled,
1411
+ isFocused: isFocused
1412
+ }));
1413
+ }
1414
+ }, {
1415
+ key: "renderIndicatorSeparator",
1416
+ value: function renderIndicatorSeparator() {
1417
+ var _this$getComponents5 = this.getComponents(),
1418
+ DropdownIndicator = _this$getComponents5.DropdownIndicator,
1419
+ IndicatorSeparator = _this$getComponents5.IndicatorSeparator;
1420
+
1421
+ // separator doesn't make sense without the dropdown indicator
1422
+ if (!DropdownIndicator || !IndicatorSeparator) {
1423
+ return null;
1424
+ }
1425
+ var commonProps = this.commonProps;
1426
+ var isDisabled = this.props.isDisabled;
1427
+ var isFocused = this.state.isFocused;
1428
+ return /*#__PURE__*/_react.default.createElement(IndicatorSeparator, (0, _extends2.default)({}, commonProps, {
1429
+ isDisabled: isDisabled,
1430
+ isFocused: isFocused
1431
+ }));
1432
+ }
1433
+ }, {
1434
+ key: "renderDropdownIndicator",
1435
+ value: function renderDropdownIndicator() {
1436
+ var _this$getComponents6 = this.getComponents(),
1437
+ DropdownIndicator = _this$getComponents6.DropdownIndicator;
1438
+ if (!DropdownIndicator) {
1439
+ return null;
1440
+ }
1441
+ var commonProps = this.commonProps;
1442
+ var isDisabled = this.props.isDisabled;
1443
+ var isFocused = this.state.isFocused;
1444
+ var innerProps = {
1445
+ onMouseDown: this.onDropdownIndicatorMouseDown,
1446
+ onTouchEnd: this.onDropdownIndicatorTouchEnd,
1447
+ 'aria-hidden': 'true'
1448
+ };
1449
+ return /*#__PURE__*/_react.default.createElement(DropdownIndicator, (0, _extends2.default)({}, commonProps, {
1450
+ innerProps: innerProps,
1451
+ isDisabled: isDisabled,
1452
+ isFocused: isFocused
1453
+ }));
1454
+ }
1455
+ }, {
1456
+ key: "renderMenu",
1457
+ value: function renderMenu() {
1458
+ var _this4 = this;
1459
+ var _this$getComponents7 = this.getComponents(),
1460
+ Group = _this$getComponents7.Group,
1461
+ GroupHeading = _this$getComponents7.GroupHeading,
1462
+ Menu = _this$getComponents7.Menu,
1463
+ MenuList = _this$getComponents7.MenuList,
1464
+ MenuPortal = _this$getComponents7.MenuPortal,
1465
+ LoadingMessage = _this$getComponents7.LoadingMessage,
1466
+ NoOptionsMessage = _this$getComponents7.NoOptionsMessage,
1467
+ Option = _this$getComponents7.Option;
1468
+ var commonProps = this.commonProps;
1469
+ var focusedOption = this.state.focusedOption;
1470
+ var _this$props12 = this.props,
1471
+ captureMenuScroll = _this$props12.captureMenuScroll,
1472
+ inputValue = _this$props12.inputValue,
1473
+ isLoading = _this$props12.isLoading,
1474
+ loadingMessage = _this$props12.loadingMessage,
1475
+ minMenuHeight = _this$props12.minMenuHeight,
1476
+ maxMenuHeight = _this$props12.maxMenuHeight,
1477
+ menuIsOpen = _this$props12.menuIsOpen,
1478
+ menuPlacement = _this$props12.menuPlacement,
1479
+ menuPosition = _this$props12.menuPosition,
1480
+ menuPortalTarget = _this$props12.menuPortalTarget,
1481
+ menuShouldBlockScroll = _this$props12.menuShouldBlockScroll,
1482
+ menuShouldScrollIntoView = _this$props12.menuShouldScrollIntoView,
1483
+ noOptionsMessage = _this$props12.noOptionsMessage,
1484
+ onMenuScrollToTop = _this$props12.onMenuScrollToTop,
1485
+ onMenuScrollToBottom = _this$props12.onMenuScrollToBottom;
1486
+ if (!menuIsOpen) {
1487
+ return null;
1488
+ }
1489
+
1490
+ // TODO: Internal Option Type here
1491
+ var render = function render(props, id) {
1492
+ var type = props.type,
1493
+ data = props.data,
1494
+ isDisabled = props.isDisabled,
1495
+ isSelected = props.isSelected,
1496
+ label = props.label,
1497
+ value = props.value;
1498
+ var isFocused = focusedOption === data;
1499
+ var onHover = isDisabled ? undefined : function () {
1500
+ return _this4.onOptionHover(data);
1501
+ };
1502
+ var onSelect = isDisabled ? undefined : function () {
1503
+ return _this4.selectOption(data);
1504
+ };
1505
+ var optionId = "".concat(_this4.getElementId('option'), "-").concat(id);
1506
+ var innerProps = {
1507
+ id: optionId,
1508
+ onClick: onSelect,
1509
+ onMouseMove: onHover,
1510
+ onMouseOver: onHover,
1511
+ role: 'option',
1512
+ 'aria-selected': _this4.isAppleDevice ? undefined : isSelected // is not supported on Apple devices
1513
+ };
1514
+ return /*#__PURE__*/_react.default.createElement(Option, (0, _extends2.default)({}, commonProps, {
1515
+ innerProps: innerProps,
1516
+ data: data,
1517
+ isDisabled: isDisabled,
1518
+ isSelected: isSelected,
1519
+ key: optionId,
1520
+ label: label,
1521
+ type: type,
1522
+ value: value,
1523
+ isFocused: isFocused,
1524
+ innerRef: isFocused ? _this4.getFocusedOptionRef : undefined
1525
+ }), _this4.formatOptionLabel(props.data, 'menu'));
1526
+ };
1527
+ var menuUI;
1528
+ if (this.hasOptions()) {
1529
+ menuUI = this.getCategorizedOptions().map(function (item) {
1530
+ if (item.type === 'group') {
1531
+ var _data = item.data,
1532
+ options = item.options,
1533
+ groupIndex = item.index;
1534
+ var groupId = "".concat(_this4.getElementId('group'), "-").concat(groupIndex);
1535
+ var headingId = "".concat(groupId, "-heading");
1536
+ return /*#__PURE__*/_react.default.createElement(Group, (0, _extends2.default)({}, commonProps, {
1537
+ key: groupId,
1538
+ data: _data,
1539
+ options: options,
1540
+ Heading: GroupHeading,
1541
+ headingProps: {
1542
+ id: headingId,
1543
+ data: item.data
1544
+ },
1545
+ label: _this4.formatGroupLabel(item.data)
1546
+ }), item.options.map(function (option) {
1547
+ return render(option, "".concat(groupIndex, "-").concat(option.index));
1548
+ }));
1549
+ } else if (item.type === 'option') {
1550
+ return render(item, "".concat(item.index));
1551
+ }
1552
+ });
1553
+ } else if (isLoading) {
1554
+ var message = loadingMessage({
1555
+ inputValue: inputValue
1556
+ });
1557
+ if (message === null) {
1558
+ return null;
1559
+ }
1560
+ menuUI = /*#__PURE__*/_react.default.createElement(LoadingMessage, commonProps, message);
1561
+ } else {
1562
+ var _message = noOptionsMessage({
1563
+ inputValue: inputValue
1564
+ });
1565
+ if (_message === null) {
1566
+ return null;
1567
+ }
1568
+ menuUI = /*#__PURE__*/_react.default.createElement(NoOptionsMessage, commonProps, _message);
1569
+ }
1570
+ var menuPlacementProps = {
1571
+ minMenuHeight: minMenuHeight,
1572
+ maxMenuHeight: maxMenuHeight,
1573
+ menuPlacement: menuPlacement,
1574
+ menuPosition: menuPosition,
1575
+ menuShouldScrollIntoView: menuShouldScrollIntoView
1576
+ };
1577
+ var menuElement = /*#__PURE__*/_react.default.createElement(_menu.MenuPlacer, (0, _extends2.default)({}, commonProps, menuPlacementProps), function (_ref4) {
1578
+ var ref = _ref4.ref,
1579
+ _ref4$placerProps = _ref4.placerProps,
1580
+ placement = _ref4$placerProps.placement,
1581
+ maxHeight = _ref4$placerProps.maxHeight;
1582
+ return /*#__PURE__*/_react.default.createElement(Menu, (0, _extends2.default)({}, commonProps, menuPlacementProps, {
1583
+ innerRef: ref,
1584
+ innerProps: {
1585
+ onMouseDown: _this4.onMenuMouseDown,
1586
+ onMouseMove: _this4.onMenuMouseMove
1587
+ },
1588
+ isLoading: isLoading,
1589
+ placement: placement
1590
+ }), /*#__PURE__*/_react.default.createElement(_internal.ScrollManager, {
1591
+ captureEnabled: captureMenuScroll,
1592
+ onTopArrive: onMenuScrollToTop,
1593
+ onBottomArrive: onMenuScrollToBottom,
1594
+ lockEnabled: menuShouldBlockScroll
1595
+ }, function (scrollTargetRef) {
1596
+ return /*#__PURE__*/_react.default.createElement(MenuList, (0, _extends2.default)({}, commonProps, {
1597
+ innerRef: function innerRef(instance) {
1598
+ _this4.getMenuListRef(instance);
1599
+ scrollTargetRef(instance);
1600
+ },
1601
+ innerProps: {
1602
+ role: 'listbox',
1603
+ 'aria-multiselectable': commonProps.isMulti,
1604
+ id: _this4.getElementId('listbox')
1605
+ },
1606
+ isLoading: isLoading,
1607
+ maxHeight: maxHeight,
1608
+ focusedOption: focusedOption
1609
+ }), menuUI);
1610
+ }));
1611
+ });
1612
+
1613
+ // positioning behaviour is almost identical for portalled and fixed,
1614
+ // so we use the same component. the actual portalling logic is forked
1615
+ // within the component based on `menuPosition`
1616
+ return menuPortalTarget || menuPosition === 'fixed' ? /*#__PURE__*/_react.default.createElement(MenuPortal, (0, _extends2.default)({}, commonProps, {
1617
+ appendTo: menuPortalTarget,
1618
+ controlElement: this.controlRef,
1619
+ menuPlacement: menuPlacement,
1620
+ menuPosition: menuPosition
1621
+ }), menuElement) : menuElement;
1622
+ }
1623
+ }, {
1624
+ key: "renderFormField",
1625
+ value: function renderFormField() {
1626
+ var _this5 = this;
1627
+ var _this$props13 = this.props,
1628
+ delimiter = _this$props13.delimiter,
1629
+ isDisabled = _this$props13.isDisabled,
1630
+ isMulti = _this$props13.isMulti,
1631
+ name = _this$props13.name,
1632
+ required = _this$props13.required;
1633
+ var selectValue = this.state.selectValue;
1634
+ if (required && !this.hasValue() && !isDisabled) {
1635
+ return /*#__PURE__*/_react.default.createElement(_internal.RequiredInput, {
1636
+ name: name,
1637
+ onFocus: this.onValueInputFocus
1638
+ });
1639
+ }
1640
+ if (!name || isDisabled) {
1641
+ return;
1642
+ }
1643
+ if (isMulti) {
1644
+ if (delimiter) {
1645
+ var value = selectValue.map(function (opt) {
1646
+ return _this5.getOptionValue(opt);
1647
+ }).join(delimiter);
1648
+ return /*#__PURE__*/_react.default.createElement("input", {
1649
+ name: name,
1650
+ type: "hidden",
1651
+ value: value
1652
+ });
1653
+ } else {
1654
+ var input = selectValue.length > 0 ? selectValue.map(function (opt, i) {
1655
+ return /*#__PURE__*/_react.default.createElement("input", {
1656
+ key: "i-".concat(i),
1657
+ name: name,
1658
+ type: "hidden",
1659
+ value: _this5.getOptionValue(opt)
1660
+ });
1661
+ }) : /*#__PURE__*/_react.default.createElement("input", {
1662
+ name: name,
1663
+ type: "hidden",
1664
+ value: ""
1665
+ });
1666
+ return /*#__PURE__*/_react.default.createElement("div", null, input);
1667
+ }
1668
+ } else {
1669
+ var _value = selectValue[0] ? this.getOptionValue(selectValue[0]) : '';
1670
+ return /*#__PURE__*/_react.default.createElement("input", {
1671
+ name: name,
1672
+ type: "hidden",
1673
+ value: _value
1674
+ });
1675
+ }
1676
+ }
1677
+ }, {
1678
+ key: "renderLiveRegion",
1679
+ value: function renderLiveRegion() {
1680
+ var commonProps = this.commonProps;
1681
+ var _this$state6 = this.state,
1682
+ ariaSelection = _this$state6.ariaSelection,
1683
+ focusedOption = _this$state6.focusedOption,
1684
+ focusedValue = _this$state6.focusedValue,
1685
+ isFocused = _this$state6.isFocused,
1686
+ selectValue = _this$state6.selectValue;
1687
+ var focusableOptions = this.getFocusableOptions();
1688
+ return /*#__PURE__*/_react.default.createElement(_liveRegion.default, (0, _extends2.default)({}, commonProps, {
1689
+ id: this.getElementId('live-region'),
1690
+ ariaSelection: ariaSelection,
1691
+ focusedOption: focusedOption,
1692
+ focusedValue: focusedValue,
1693
+ isFocused: isFocused,
1694
+ selectValue: selectValue,
1695
+ focusableOptions: focusableOptions,
1696
+ isAppleDevice: this.isAppleDevice
1697
+ }));
1698
+ }
1699
+ }, {
1700
+ key: "render",
1701
+ value: function render() {
1702
+ var _this$getComponents8 = this.getComponents(),
1703
+ Control = _this$getComponents8.Control,
1704
+ IndicatorsContainer = _this$getComponents8.IndicatorsContainer,
1705
+ SelectContainer = _this$getComponents8.SelectContainer,
1706
+ ValueContainer = _this$getComponents8.ValueContainer;
1707
+ var _this$props14 = this.props,
1708
+ className = _this$props14.className,
1709
+ id = _this$props14.id,
1710
+ isDisabled = _this$props14.isDisabled,
1711
+ menuIsOpen = _this$props14.menuIsOpen;
1712
+ var isFocused = this.state.isFocused;
1713
+ var commonProps = this.commonProps = this.getCommonProps();
1714
+ return /*#__PURE__*/_react.default.createElement(SelectContainer, (0, _extends2.default)({}, commonProps, {
1715
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop
1716
+ className: className,
1717
+ innerProps: {
1718
+ id: id,
1719
+ onKeyDown: this.onKeyDown
1720
+ },
1721
+ isDisabled: isDisabled,
1722
+ isFocused: isFocused
1723
+ }), this.renderLiveRegion(), /*#__PURE__*/_react.default.createElement(Control, (0, _extends2.default)({}, commonProps, {
1724
+ innerRef: this.getControlRef,
1725
+ innerProps: {
1726
+ onMouseDown: this.onControlMouseDown,
1727
+ onTouchEnd: this.onControlTouchEnd
1728
+ },
1729
+ isDisabled: isDisabled,
1730
+ isFocused: isFocused,
1731
+ menuIsOpen: menuIsOpen
1732
+ }), /*#__PURE__*/_react.default.createElement(ValueContainer, (0, _extends2.default)({}, commonProps, {
1733
+ isDisabled: isDisabled
1734
+ }), this.renderPlaceholderOrValue(), this.renderInput()), /*#__PURE__*/_react.default.createElement(IndicatorsContainer, (0, _extends2.default)({}, commonProps, {
1735
+ isDisabled: isDisabled
1736
+ }), this.renderClearIndicator(), this.renderLoadingIndicator(), this.renderIndicatorSeparator(), this.renderDropdownIndicator())), this.renderMenu(), this.renderFormField());
1737
+ }
1738
+ }], [{
1739
+ key: "getDerivedStateFromProps",
1740
+ value: function getDerivedStateFromProps(props, state) {
1741
+ var prevProps = state.prevProps,
1742
+ clearFocusValueOnUpdate = state.clearFocusValueOnUpdate,
1743
+ inputIsHiddenAfterUpdate = state.inputIsHiddenAfterUpdate,
1744
+ ariaSelection = state.ariaSelection,
1745
+ isFocused = state.isFocused,
1746
+ prevWasFocused = state.prevWasFocused,
1747
+ instancePrefix = state.instancePrefix;
1748
+ var options = props.options,
1749
+ value = props.value,
1750
+ menuIsOpen = props.menuIsOpen,
1751
+ inputValue = props.inputValue,
1752
+ isMulti = props.isMulti;
1753
+ //@ts-ignore
1754
+ var selectValue = (0, _utils.cleanValue)(value);
1755
+ var newMenuOptionsState = {};
1756
+ if (prevProps && (value !== prevProps.value || options !== prevProps.options || menuIsOpen !== prevProps.menuIsOpen || inputValue !== prevProps.inputValue)) {
1757
+ var focusableOptions = menuIsOpen ? buildFocusableOptions(props, selectValue) : [];
1758
+ var focusableOptionsWithIds = menuIsOpen ? buildFocusableOptionsWithIds(buildCategorizedOptions(props, selectValue), "".concat(instancePrefix, "-option")) : [];
1759
+ var focusedValue = clearFocusValueOnUpdate ? getNextFocusedValue(state, selectValue) : null;
1760
+ var focusedOption = getNextFocusedOption(state, focusableOptions);
1761
+ var focusedOptionId = getFocusedOptionId(focusableOptionsWithIds, focusedOption);
1762
+ newMenuOptionsState = {
1763
+ selectValue: selectValue,
1764
+ focusedOption: focusedOption,
1765
+ focusedOptionId: focusedOptionId,
1766
+ focusableOptionsWithIds: focusableOptionsWithIds,
1767
+ focusedValue: focusedValue,
1768
+ clearFocusValueOnUpdate: false
1769
+ };
1770
+ }
1771
+ // some updates should toggle the state of the input visibility
1772
+ var newInputIsHiddenState = inputIsHiddenAfterUpdate != null && props !== prevProps ? {
1773
+ inputIsHidden: inputIsHiddenAfterUpdate,
1774
+ inputIsHiddenAfterUpdate: undefined
1775
+ } : {};
1776
+ var newAriaSelection = ariaSelection;
1777
+ var hasKeptFocus = isFocused && prevWasFocused;
1778
+ if (isFocused && !hasKeptFocus) {
1779
+ // If `value` or `defaultValue` props are not empty then announce them
1780
+ // when the Select is initially focused
1781
+ newAriaSelection = {
1782
+ value: (0, _utils.valueTernary)(isMulti, selectValue, selectValue[0] || null),
1783
+ options: selectValue,
1784
+ action: 'initial-input-focus'
1785
+ };
1786
+ hasKeptFocus = !prevWasFocused;
1787
+ }
1788
+
1789
+ // If the 'initial-input-focus' action has been set already
1790
+ // then reset the ariaSelection to null
1791
+ if ((ariaSelection === null || ariaSelection === void 0 ? void 0 : ariaSelection.action) === 'initial-input-focus') {
1792
+ newAriaSelection = null;
1793
+ }
1794
+ return _objectSpread(_objectSpread(_objectSpread({}, newMenuOptionsState), newInputIsHiddenState), {}, {
1795
+ prevProps: props,
1796
+ ariaSelection: newAriaSelection,
1797
+ prevWasFocused: hasKeptFocus
1798
+ });
1799
+ }
1800
+ }]);
1801
+ return Select;
1802
+ }(_react.Component);
1803
+ (0, _defineProperty2.default)(Select, "defaultProps", defaultProps);