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