@instructure/ui-select 11.7.2-snapshot-47 → 11.7.2-snapshot-49

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 (44) hide show
  1. package/CHANGELOG.md +12 -2
  2. package/es/Select/v2/Group/index.js +47 -0
  3. package/es/Select/v2/Group/props.js +26 -0
  4. package/es/Select/v2/Option/index.js +51 -0
  5. package/es/Select/v2/Option/props.js +26 -0
  6. package/es/Select/v2/index.js +704 -0
  7. package/es/Select/v2/props.js +35 -0
  8. package/es/Select/v2/styles.js +41 -0
  9. package/es/exports/b.js +26 -0
  10. package/lib/Select/v2/Group/index.js +53 -0
  11. package/lib/Select/v2/Group/props.js +31 -0
  12. package/lib/Select/v2/Option/index.js +57 -0
  13. package/lib/Select/v2/Option/props.js +31 -0
  14. package/lib/Select/v2/index.js +714 -0
  15. package/lib/Select/v2/props.js +40 -0
  16. package/lib/Select/v2/styles.js +47 -0
  17. package/lib/exports/b.js +26 -0
  18. package/package.json +29 -29
  19. package/src/Select/v2/Group/index.tsx +52 -0
  20. package/src/Select/v2/Group/props.ts +48 -0
  21. package/src/Select/v2/Option/index.tsx +56 -0
  22. package/src/Select/v2/Option/props.ts +82 -0
  23. package/src/Select/v2/README.md +1342 -0
  24. package/src/Select/v2/index.tsx +897 -0
  25. package/src/Select/v2/props.ts +333 -0
  26. package/src/Select/v2/styles.ts +48 -0
  27. package/src/exports/b.ts +31 -0
  28. package/tsconfig.build.tsbuildinfo +1 -1
  29. package/types/Select/v2/Group/index.d.ts +21 -0
  30. package/types/Select/v2/Group/index.d.ts.map +1 -0
  31. package/types/Select/v2/Group/props.d.ts +19 -0
  32. package/types/Select/v2/Group/props.d.ts.map +1 -0
  33. package/types/Select/v2/Option/index.d.ts +28 -0
  34. package/types/Select/v2/Option/index.d.ts.map +1 -0
  35. package/types/Select/v2/Option/props.d.ts +43 -0
  36. package/types/Select/v2/Option/props.d.ts.map +1 -0
  37. package/types/Select/v2/index.d.ts +138 -0
  38. package/types/Select/v2/index.d.ts.map +1 -0
  39. package/types/Select/v2/props.d.ts +206 -0
  40. package/types/Select/v2/props.d.ts.map +1 -0
  41. package/types/Select/v2/styles.d.ts +12 -0
  42. package/types/Select/v2/styles.d.ts.map +1 -0
  43. package/types/exports/b.d.ts +7 -0
  44. package/types/exports/b.d.ts.map +1 -0
@@ -0,0 +1,714 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = exports.Select = void 0;
9
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
10
+ var _react = require("react");
11
+ var utils = _interopRequireWildcard(require("@instructure/ui-utils"));
12
+ var _combineDataCid = require("@instructure/ui-utils/lib/combineDataCid.js");
13
+ var _matchComponentTypes = require("@instructure/ui-react-utils/lib/matchComponentTypes.js");
14
+ var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js");
15
+ var _getInteraction = require("@instructure/ui-react-utils/lib/getInteraction.js");
16
+ var _withDeterministicId = require("@instructure/ui-react-utils/lib/DeterministicIdContext/withDeterministicId.js");
17
+ var _getBoundingClientRect = require("@instructure/ui-dom-utils/lib/getBoundingClientRect.js");
18
+ var _isActiveElement = require("@instructure/ui-dom-utils/lib/isActiveElement.js");
19
+ var _latest = require("@instructure/ui-view/latest");
20
+ var _Selectable = require("@instructure/ui-selectable/lib/Selectable");
21
+ var _latest2 = require("@instructure/ui-popover/latest");
22
+ var _latest3 = require("@instructure/ui-text-input/latest");
23
+ var _latest4 = require("@instructure/ui-options/latest");
24
+ var _uiIcons = require("@instructure/ui-icons");
25
+ var _emotion = require("@instructure/emotion");
26
+ var _styles = _interopRequireDefault(require("./styles"));
27
+ var _Group = require("./Group");
28
+ var _Option = require("./Option");
29
+ var _props = require("./props");
30
+ var _jsxRuntime = require("@emotion/react/jsx-runtime");
31
+ const _excluded = ["id", "renderLabel", "children"],
32
+ _excluded2 = ["renderLabel", "inputValue", "placeholder", "isRequired", "shouldNotWrap", "size", "isInline", "width", "htmlSize", "messages", "renderBeforeInput", "renderAfterInput", "onFocus", "onBlur", "onInputChange", "onRequestHideOptions", "layout"],
33
+ _excluded3 = ["ref"];
34
+ var _dec, _dec2, _class, _Select, _Options$Separator, _Options$Separator2;
35
+ /*
36
+ * The MIT License (MIT)
37
+ *
38
+ * Copyright (c) 2015 - present Instructure, Inc.
39
+ *
40
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
41
+ * of this software and associated documentation files (the "Software"), to deal
42
+ * in the Software without restriction, including without limitation the rights
43
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
44
+ * copies of the Software, and to permit persons to whom the Software is
45
+ * furnished to do so, subject to the following conditions:
46
+ *
47
+ * The above copyright notice and this permission notice shall be included in all
48
+ * copies or substantial portions of the Software.
49
+ *
50
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
51
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
52
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
53
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
54
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
55
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
56
+ * SOFTWARE.
57
+ */
58
+ const selectSizeToIconSize = {
59
+ small: 'sm',
60
+ medium: 'md',
61
+ large: 'lg'
62
+ };
63
+ // This memoed Option component is used to prevent unnecessary re-renders of
64
+ // Options.Item when the Select component is re-rendered. This is necessary
65
+ // because the Select component is re-rendered on every prop change of the <Select.Option>
66
+ // and with a large amount of options, this can cause a lot of unnecessary re-renders.
67
+ const MemoedOption = /*#__PURE__*/(0, _react.memo)(function Opt(props) {
68
+ const optionsItemProps = props.optionsItemProps,
69
+ children = props.children;
70
+ return (
71
+ // The main <Options> that renders this is always an "ul"
72
+ (0, _jsxRuntime.jsx)(_latest4.Options.Item, {
73
+ as: "li",
74
+ ...optionsItemProps,
75
+ children: children
76
+ })
77
+ );
78
+ },
79
+ // This is a custom equality function that checks if the props of the
80
+ // <Select.Option> have changed. If they haven't, then the Options.Item
81
+ // doesn't need to be re-rendered.
82
+ (prevProps, nextProps) => {
83
+ return prevProps.selectOption.props.isHighlighted === nextProps.selectOption.props.isHighlighted && prevProps.selectOption.props.isSelected === nextProps.selectOption.props.isSelected && prevProps.selectOption.props.isDisabled === nextProps.selectOption.props.isDisabled && prevProps.selectOption.props.children === nextProps.selectOption.props.children && prevProps.selectOption.props.id === nextProps.selectOption.props.id && prevProps.selectOption.props.renderBeforeLabel === nextProps.selectOption.props.renderBeforeLabel && prevProps.selectOption.props.renderAfterLabel === nextProps.selectOption.props.renderAfterLabel && prevProps.children === nextProps.children;
84
+ });
85
+ // This is needed so the propTypes in <Options> check are correct
86
+ MemoedOption.displayName = 'Item';
87
+
88
+ /**
89
+ ---
90
+ category: components
91
+ tags: autocomplete, typeahead, combobox, dropdown, search, form
92
+ ---
93
+ **/
94
+ let Select = exports.Select = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyle)(_styles.default), _dec(_class = _dec2(_class = (_Select = class Select extends _react.Component {
95
+ constructor(...args) {
96
+ super(...args);
97
+ this.SCROLL_TOLERANCE = 0.5;
98
+ this.state = {
99
+ hasInputRef: false
100
+ };
101
+ this.ref = null;
102
+ this._input = null;
103
+ this._defaultId = this.props.deterministicId();
104
+ this._inputContainer = null;
105
+ this._listView = null;
106
+ // temporarily stores actionable options
107
+ this._optionIds = [];
108
+ // best guess for first calculation of list height
109
+ this._optionHeight = 36;
110
+ this.handleInputRef = node => {
111
+ var _this$props$inputRef, _this$props;
112
+ // ensures list is positioned with respect to input if list is open on mount
113
+ if (!this.state.hasInputRef) {
114
+ this.setState({
115
+ hasInputRef: true
116
+ });
117
+ }
118
+ this._input = node;
119
+ (_this$props$inputRef = (_this$props = this.props).inputRef) === null || _this$props$inputRef === void 0 ? void 0 : _this$props$inputRef.call(_this$props, node);
120
+ };
121
+ this.handleListRef = node => {
122
+ var _this$props$listRef, _this$props2;
123
+ (_this$props$listRef = (_this$props2 = this.props).listRef) === null || _this$props$listRef === void 0 ? void 0 : _this$props$listRef.call(_this$props2, node);
124
+
125
+ // store option height to calculate list maxHeight
126
+ if (node && node.querySelector('[role="option"]')) {
127
+ this._optionHeight = node.querySelector('[role="option"]').offsetHeight;
128
+ }
129
+ };
130
+ this.handleInputContainerRef = node => {
131
+ this._inputContainer = node;
132
+ };
133
+ }
134
+ componentDidMount() {
135
+ var _this$props$makeStyle, _this$props3;
136
+ (_this$props$makeStyle = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props3);
137
+ }
138
+ componentDidUpdate() {
139
+ var _this$props$makeStyle2, _this$props4;
140
+ (_this$props$makeStyle2 = (_this$props4 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props4);
141
+ if (this.props.scrollToHighlightedOption) {
142
+ // scroll option into view if needed
143
+ requestAnimationFrame(() => this.scrollToOption(this.highlightedOptionId));
144
+ }
145
+ }
146
+ focus() {
147
+ this._input && this._input.focus();
148
+ }
149
+ blur() {
150
+ this._input && this._input.blur();
151
+ }
152
+ get childrenArray() {
153
+ return _react.Children.toArray(this.props.children);
154
+ }
155
+ getGroupChildrenArray(group) {
156
+ return _react.Children.toArray(group.props.children);
157
+ }
158
+ get focused() {
159
+ return this._input ? (0, _isActiveElement.isActiveElement)(this._input) : false;
160
+ }
161
+ get id() {
162
+ return this.props.id || this._defaultId;
163
+ }
164
+ get width() {
165
+ return this._inputContainer ? this._inputContainer.offsetWidth : void 0;
166
+ }
167
+ get interaction() {
168
+ return (0, _getInteraction.getInteraction)({
169
+ props: this.props
170
+ });
171
+ }
172
+ get highlightedOptionId() {
173
+ let highlightedOptionId;
174
+ this.childrenArray.forEach(child => {
175
+ if ((0, _matchComponentTypes.matchComponentTypes)(child, [_Group.Group])) {
176
+ // group found
177
+ this.getGroupChildrenArray(child).forEach(option => {
178
+ // check options in group
179
+ if (option.props.isHighlighted) {
180
+ highlightedOptionId = option.props.id;
181
+ }
182
+ });
183
+ } else {
184
+ // ungrouped option found
185
+ if (child.props.isHighlighted) {
186
+ highlightedOptionId = child.props.id;
187
+ }
188
+ }
189
+ });
190
+ return highlightedOptionId;
191
+ }
192
+ get selectedOptionId() {
193
+ const selectedOptionId = [];
194
+ this.childrenArray.forEach(child => {
195
+ if ((0, _matchComponentTypes.matchComponentTypes)(child, [_Group.Group])) {
196
+ // group found
197
+ this.getGroupChildrenArray(child).forEach(option => {
198
+ // check options in group
199
+ if (option.props.isSelected) {
200
+ selectedOptionId.push(option.props.id);
201
+ }
202
+ });
203
+ } else {
204
+ // ungrouped option found
205
+ if (child.props.isSelected) {
206
+ selectedOptionId.push(child.props.id);
207
+ }
208
+ }
209
+ });
210
+ if (selectedOptionId.length === 1) {
211
+ return selectedOptionId[0];
212
+ }
213
+ if (selectedOptionId.length === 0) {
214
+ return void 0;
215
+ }
216
+ return selectedOptionId;
217
+ }
218
+ scrollToOption(id) {
219
+ if (!this._listView || !id) return;
220
+ const option = this._listView.querySelector(`[id="${CSS.escape(id)}"]`);
221
+ if (!option) return;
222
+ const listItem = option.parentNode;
223
+ const parentTop = (0, _getBoundingClientRect.getBoundingClientRect)(this._listView).top;
224
+ const elemTop = (0, _getBoundingClientRect.getBoundingClientRect)(listItem).top;
225
+ const parentBottom = parentTop + this._listView.clientHeight;
226
+ const elemBottom = elemTop + (listItem ? listItem.clientHeight : 0);
227
+ if (elemBottom > parentBottom) {
228
+ this._listView.scrollTop += elemBottom - parentBottom;
229
+ } else if (elemTop < parentTop) {
230
+ this._listView.scrollTop -= parentTop - elemTop;
231
+ }
232
+ }
233
+ highlightOption(event, id) {
234
+ const onRequestHighlightOption = this.props.onRequestHighlightOption;
235
+ if (id) {
236
+ onRequestHighlightOption === null || onRequestHighlightOption === void 0 ? void 0 : onRequestHighlightOption(event, {
237
+ id
238
+ });
239
+ }
240
+ }
241
+ getEventHandlers() {
242
+ const _this$props5 = this.props,
243
+ isShowingOptions = _this$props5.isShowingOptions,
244
+ onRequestShowOptions = _this$props5.onRequestShowOptions,
245
+ onRequestHideOptions = _this$props5.onRequestHideOptions,
246
+ onRequestSelectOption = _this$props5.onRequestSelectOption;
247
+ return this.interaction === 'enabled' ? {
248
+ onRequestShowOptions: event => {
249
+ onRequestShowOptions === null || onRequestShowOptions === void 0 ? void 0 : onRequestShowOptions(event);
250
+ const selectedOptionId = this.selectedOptionId;
251
+ if (selectedOptionId && !Array.isArray(selectedOptionId)) {
252
+ // highlight selected option on show
253
+ this.highlightOption(event, selectedOptionId);
254
+ }
255
+ },
256
+ onRequestHideOptions: event => {
257
+ onRequestHideOptions === null || onRequestHideOptions === void 0 ? void 0 : onRequestHideOptions(event);
258
+ },
259
+ onRequestHighlightOption: (event, {
260
+ id,
261
+ direction
262
+ }) => {
263
+ if (!isShowingOptions) return;
264
+ const highlightedOptionId = this.highlightedOptionId;
265
+ // if id exists, use that
266
+ let highlightId = this._optionIds.indexOf(id) > -1 ? id : void 0;
267
+ if (!highlightId) {
268
+ if (!highlightedOptionId) {
269
+ // nothing highlighted yet, highlight first option
270
+ highlightId = this._optionIds[0];
271
+ } else {
272
+ // find next id based on direction
273
+ const index = this._optionIds.indexOf(highlightedOptionId);
274
+ highlightId = index > -1 ? this._optionIds[index + direction] : void 0;
275
+ }
276
+ }
277
+ if (highlightId) {
278
+ // only highlight if id exists as a valid option
279
+ this.highlightOption(event, highlightId);
280
+ }
281
+ },
282
+ onRequestHighlightFirstOption: event => {
283
+ this.highlightOption(event, this._optionIds[0]);
284
+ },
285
+ onRequestHighlightLastOption: event => {
286
+ this.highlightOption(event, this._optionIds[this._optionIds.length - 1]);
287
+ },
288
+ onRequestSelectOption: (event, {
289
+ id
290
+ }) => {
291
+ if (id && this._optionIds.indexOf(id) !== -1) {
292
+ // only select if id exists as a valid option
293
+ onRequestSelectOption === null || onRequestSelectOption === void 0 ? void 0 : onRequestSelectOption(event, {
294
+ id
295
+ });
296
+ }
297
+ }
298
+ } : {};
299
+ }
300
+ renderOption(option, data) {
301
+ const getOptionProps = data.getOptionProps,
302
+ getDisabledOptionProps = data.getDisabledOptionProps;
303
+ const _option$props = option.props,
304
+ id = _option$props.id,
305
+ isDisabled = _option$props.isDisabled,
306
+ isHighlighted = _option$props.isHighlighted,
307
+ isSelected = _option$props.isSelected,
308
+ renderBeforeLabel = _option$props.renderBeforeLabel,
309
+ renderAfterLabel = _option$props.renderAfterLabel,
310
+ children = _option$props.children;
311
+ const getRenderOptionLabel = renderOptionLabel => {
312
+ var _renderOptionLabel$pr;
313
+ return typeof renderOptionLabel === 'function' && !(renderOptionLabel !== null && renderOptionLabel !== void 0 && (_renderOptionLabel$pr = renderOptionLabel.prototype) !== null && _renderOptionLabel$pr !== void 0 && _renderOptionLabel$pr.isReactComponent) ? renderOptionLabel.bind(null, {
314
+ id,
315
+ isDisabled,
316
+ isSelected,
317
+ isHighlighted,
318
+ children
319
+ }) : renderOptionLabel;
320
+ };
321
+ const _this$props6 = this.props,
322
+ isOptionContentAppliedToInput = _this$props6.isOptionContentAppliedToInput,
323
+ _this$props6$size = _this$props6.size,
324
+ size = _this$props6$size === void 0 ? 'medium' : _this$props6$size;
325
+ const iconSize = selectSizeToIconSize[size];
326
+ const checkIcon = isSelected && !isOptionContentAppliedToInput ? (0, _jsxRuntime.jsx)(_uiIcons.CheckInstUIIcon, {
327
+ inline: false,
328
+ size: iconSize,
329
+ color: "inverseColor"
330
+ }) : null;
331
+ let optionProps = {
332
+ // passthrough props
333
+ ...(0, _omitProps.omitProps)(option.props, [..._Option.Option.allowedProps, ..._latest4.Options.Item.allowedProps]),
334
+ // props from selectable
335
+ ...getOptionProps({
336
+ id
337
+ }),
338
+ // Options.Item props
339
+ renderBeforeLabel: getRenderOptionLabel(renderBeforeLabel),
340
+ renderAfterLabel: checkIcon !== null && checkIcon !== void 0 ? checkIcon : getRenderOptionLabel(renderAfterLabel)
341
+ };
342
+ // should option be treated as highlighted or selected
343
+ if (isSelected && isHighlighted) {
344
+ optionProps.variant = 'selected-highlighted';
345
+ optionProps.isSelected = true;
346
+ } else if (isSelected) {
347
+ optionProps.variant = 'selected';
348
+ optionProps.isSelected = true;
349
+ } else if (isHighlighted) {
350
+ optionProps.variant = 'highlighted';
351
+ }
352
+ // should option be treated as disabled
353
+ if (isDisabled) {
354
+ optionProps.variant = 'disabled';
355
+ optionProps = {
356
+ ...optionProps,
357
+ ...getDisabledOptionProps()
358
+ };
359
+ } else {
360
+ // track as valid option if not disabled
361
+ this._optionIds.push(id);
362
+ }
363
+ return (0, _jsxRuntime.jsx)(MemoedOption, {
364
+ optionsItemProps: optionProps,
365
+ selectOption: option,
366
+ children: children
367
+ });
368
+ }
369
+ renderGroup(group, data) {
370
+ const getOptionProps = data.getOptionProps,
371
+ getDisabledOptionProps = data.getDisabledOptionProps,
372
+ isFirstChild = data.isFirstChild,
373
+ isLastChild = data.isLastChild,
374
+ afterGroup = data.afterGroup;
375
+ const _group$props = group.props,
376
+ id = _group$props.id,
377
+ renderLabel = _group$props.renderLabel,
378
+ children = _group$props.children,
379
+ rest = (0, _objectWithoutProperties2.default)(_group$props, _excluded);
380
+ const groupChildren = [];
381
+ // add a separator above
382
+ if (!isFirstChild && !afterGroup) {
383
+ groupChildren.push(_Options$Separator || (_Options$Separator = (0, _jsxRuntime.jsx)(_latest4.Options.Separator, {})));
384
+ }
385
+ // create a sublist as a group
386
+ // a wrapping listitem will be created by Options
387
+ groupChildren.push((0, _jsxRuntime.jsx)(_latest4.Options, {
388
+ id: id,
389
+ as: "ul",
390
+ role: "group",
391
+ renderLabel: renderLabel,
392
+ ...(0, _omitProps.omitProps)(rest, [..._latest4.Options.allowedProps, ..._Group.Group.allowedProps]),
393
+ children: _react.Children.map(children, child => {
394
+ return this.renderOption(child, {
395
+ getOptionProps,
396
+ getDisabledOptionProps
397
+ });
398
+ })
399
+ }));
400
+ // add a separator below
401
+ if (!isLastChild) {
402
+ groupChildren.push(_Options$Separator2 || (_Options$Separator2 = (0, _jsxRuntime.jsx)(_latest4.Options.Separator, {})));
403
+ }
404
+ return groupChildren;
405
+ }
406
+ renderList(data) {
407
+ const getListProps = data.getListProps,
408
+ getOptionProps = data.getOptionProps,
409
+ getDisabledOptionProps = data.getDisabledOptionProps;
410
+ const _this$props7 = this.props,
411
+ isShowingOptions = _this$props7.isShowingOptions,
412
+ optionsMaxWidth = _this$props7.optionsMaxWidth,
413
+ optionsMaxHeight = _this$props7.optionsMaxHeight,
414
+ visibleOptionsCount = _this$props7.visibleOptionsCount,
415
+ children = _this$props7.children;
416
+ let lastWasGroup = false;
417
+ const viewProps = isShowingOptions ? {
418
+ display: 'block',
419
+ overflowY: 'auto',
420
+ maxHeight: optionsMaxHeight || this._optionHeight * visibleOptionsCount - (
421
+ // in Chrome, we need to prevent scrolling when the bottom area of last item is hovered
422
+ utils.isChromium() ? this.SCROLL_TOLERANCE : 0),
423
+ maxWidth: optionsMaxWidth || this.width,
424
+ background: 'primary',
425
+ elementRef: node => this._listView = node,
426
+ borderRadius: 'inherit'
427
+ } : {
428
+ maxHeight: 0
429
+ };
430
+ return (0, _jsxRuntime.jsx)(_latest.View, {
431
+ ...viewProps,
432
+ children: (0, _jsxRuntime.jsx)(_latest4.Options, {
433
+ ...getListProps({
434
+ as: 'ul',
435
+ elementRef: this.handleListRef
436
+ }),
437
+ children: isShowingOptions ? _react.Children.map(children, (child, index) => {
438
+ if (!child || !(0, _matchComponentTypes.matchComponentTypes)(child, [_Group.Group, _Option.Option])) {
439
+ return; // ignore invalid children
440
+ }
441
+ if ((0, _matchComponentTypes.matchComponentTypes)(child, [_Option.Option])) {
442
+ lastWasGroup = false;
443
+ return this.renderOption(child, {
444
+ getOptionProps,
445
+ getDisabledOptionProps
446
+ });
447
+ }
448
+ if ((0, _matchComponentTypes.matchComponentTypes)(child, [_Group.Group])) {
449
+ const afterGroup = lastWasGroup;
450
+ lastWasGroup = true;
451
+ return this.renderGroup(child, {
452
+ getOptionProps,
453
+ getDisabledOptionProps,
454
+ // for rendering separators appropriately
455
+ isFirstChild: index === 0,
456
+ isLastChild: index === _react.Children.count(children) - 1,
457
+ afterGroup
458
+ });
459
+ }
460
+ return;
461
+ }) : null
462
+ })
463
+ });
464
+ }
465
+ renderIcon() {
466
+ const _this$props8 = this.props,
467
+ isShowingOptions = _this$props8.isShowingOptions,
468
+ _this$props8$size = _this$props8.size,
469
+ size = _this$props8$size === void 0 ? 'medium' : _this$props8$size;
470
+ const iconSize = selectSizeToIconSize[size];
471
+ return (0, _jsxRuntime.jsx)("span", {
472
+ children: isShowingOptions ? (0, _jsxRuntime.jsx)(_uiIcons.ChevronUpInstUIIcon, {
473
+ inline: false,
474
+ size: iconSize,
475
+ color: "baseColor"
476
+ }) : (0, _jsxRuntime.jsx)(_uiIcons.ChevronDownInstUIIcon, {
477
+ inline: false,
478
+ size: iconSize,
479
+ color: "baseColor"
480
+ })
481
+ });
482
+ }
483
+ renderContentBeforeOrAfterInput(position) {
484
+ for (const child of this.childrenArray) {
485
+ if ((0, _matchComponentTypes.matchComponentTypes)(child, [_Group.Group])) {
486
+ // Group found
487
+ const options = this.getGroupChildrenArray(child);
488
+ for (const option of options) {
489
+ if (option.props.isSelected) {
490
+ return position === 'before' ? option.props.renderBeforeLabel : option.props.renderAfterLabel ? option.props.renderAfterLabel : this.renderIcon();
491
+ }
492
+ }
493
+ } else {
494
+ // Ungrouped option found
495
+ if (child.props.isSelected) {
496
+ return position === 'before' ? child.props.renderBeforeLabel : child.props.renderAfterLabel ? child.props.renderAfterLabel : this.renderIcon();
497
+ }
498
+ }
499
+ }
500
+ // if no option with isSelected is found
501
+ if (position === 'after') {
502
+ return this.renderIcon();
503
+ }
504
+ return void 0;
505
+ }
506
+ handleInputContentRender(renderLabelInput, inputValue, isOptionContentAppliedToInput, position, defaultReturn) {
507
+ const isInputValueEmpty = !inputValue || inputValue === '';
508
+ if (renderLabelInput && isOptionContentAppliedToInput) {
509
+ if (!isInputValueEmpty) {
510
+ return this.renderContentBeforeOrAfterInput(position);
511
+ }
512
+ return renderLabelInput;
513
+ }
514
+ if (isOptionContentAppliedToInput) {
515
+ if (isInputValueEmpty) {
516
+ return defaultReturn;
517
+ }
518
+ return this.renderContentBeforeOrAfterInput(position);
519
+ }
520
+ if (renderLabelInput) {
521
+ return renderLabelInput;
522
+ }
523
+ return defaultReturn;
524
+ }
525
+ handleRenderBeforeInput() {
526
+ const _this$props9 = this.props,
527
+ renderBeforeInput = _this$props9.renderBeforeInput,
528
+ inputValue = _this$props9.inputValue,
529
+ isOptionContentAppliedToInput = _this$props9.isOptionContentAppliedToInput;
530
+ return this.handleInputContentRender(renderBeforeInput, inputValue, isOptionContentAppliedToInput, 'before', null // default for before
531
+ );
532
+ }
533
+ handleRenderAfterInput() {
534
+ const _this$props0 = this.props,
535
+ renderAfterInput = _this$props0.renderAfterInput,
536
+ inputValue = _this$props0.inputValue,
537
+ isOptionContentAppliedToInput = _this$props0.isOptionContentAppliedToInput;
538
+ return this.handleInputContentRender(renderAfterInput, inputValue, isOptionContentAppliedToInput, 'after', this.renderIcon() // default for after
539
+ );
540
+ }
541
+ renderInput(data) {
542
+ const getInputProps = data.getInputProps,
543
+ getTriggerProps = data.getTriggerProps;
544
+ const _this$props1 = this.props,
545
+ renderLabel = _this$props1.renderLabel,
546
+ inputValue = _this$props1.inputValue,
547
+ placeholder = _this$props1.placeholder,
548
+ isRequired = _this$props1.isRequired,
549
+ shouldNotWrap = _this$props1.shouldNotWrap,
550
+ size = _this$props1.size,
551
+ isInline = _this$props1.isInline,
552
+ width = _this$props1.width,
553
+ htmlSize = _this$props1.htmlSize,
554
+ messages = _this$props1.messages,
555
+ renderBeforeInput = _this$props1.renderBeforeInput,
556
+ renderAfterInput = _this$props1.renderAfterInput,
557
+ onFocus = _this$props1.onFocus,
558
+ onBlur = _this$props1.onBlur,
559
+ onInputChange = _this$props1.onInputChange,
560
+ onRequestHideOptions = _this$props1.onRequestHideOptions,
561
+ layout = _this$props1.layout,
562
+ rest = (0, _objectWithoutProperties2.default)(_this$props1, _excluded2);
563
+ const interaction = this.interaction;
564
+ const passthroughProps = (0, _omitProps.omitProps)(rest, Select.allowedProps);
565
+ const _getTriggerProps = getTriggerProps({
566
+ ...passthroughProps
567
+ }),
568
+ ref = _getTriggerProps.ref,
569
+ triggerProps = (0, _objectWithoutProperties2.default)(_getTriggerProps, _excluded3);
570
+ const isEditable = typeof onInputChange !== 'undefined';
571
+
572
+ // props to ensure screen readers treat uneditable selects as accessible
573
+ // popup buttons rather than comboboxes.
574
+ const overrideProps = !isEditable ? {
575
+ // We need role="combobox" for the 'open list' button shortcut to work
576
+ // with desktop screenreaders.
577
+ // But desktop Safari with Voiceover does not support proper combobox
578
+ // handling, a 'button' role is set as a workaround.
579
+ // See https://bugs.webkit.org/show_bug.cgi?id=236881
580
+ // Also on iOS Chrome with role='combobox' it announces unnecessarily
581
+ // that its 'read-only' and that this is a 'textfield', see INSTUI-4500
582
+ role: utils.isSafari() || utils.isAndroidOrIOS() || interaction === 'disabled' && utils.isChromium() ? 'button' : 'combobox',
583
+ title: inputValue,
584
+ 'aria-autocomplete': void 0,
585
+ 'aria-readonly': true
586
+ } : interaction === 'disabled' && utils.isChromium() ? {
587
+ role: 'button'
588
+ } : {};
589
+
590
+ // backdoor to autocomplete attr to work around chrome autofill issues
591
+ if (passthroughProps['autoComplete']) {
592
+ overrideProps.autoComplete = passthroughProps['autoComplete'];
593
+ }
594
+ const inputProps = {
595
+ id: this.id,
596
+ renderLabel,
597
+ placeholder,
598
+ size,
599
+ width,
600
+ htmlSize,
601
+ messages,
602
+ value: inputValue,
603
+ inputRef: utils.createChainedFunction(ref, this.handleInputRef),
604
+ inputContainerRef: this.handleInputContainerRef,
605
+ interaction: interaction === 'enabled' && !isEditable ? 'readonly' // prevent keyboard cursor
606
+ : interaction,
607
+ isRequired,
608
+ shouldNotWrap,
609
+ layout,
610
+ display: isInline ? 'inline-block' : 'block',
611
+ renderBeforeInput: this.handleRenderBeforeInput(),
612
+ // On iOS VoiceOver, if there is a custom element instead of the changing up and down arrow button
613
+ // the listbox closes on a swipe, so a DOM change is enforced by the key change
614
+ // that seems to inform VoiceOver to behave the correct way
615
+ renderAfterInput: utils.isAndroidOrIOS() && renderAfterInput !== void 0 ? (0, _jsxRuntime.jsx)("span", {
616
+ children: this.handleRenderAfterInput()
617
+ }, this.props.isShowingOptions ? 'open' : 'closed') : this.handleRenderAfterInput(),
618
+ // If `inputValue` is provided, we need to pass a default onChange handler,
619
+ // because TextInput `value` is a controlled prop,
620
+ // and onChange is not required for Select
621
+ // (before it was handled by TextInput's defaultProp)
622
+ onChange: typeof onInputChange === 'function' ? onInputChange : inputValue ? () => {} : void 0,
623
+ onFocus,
624
+ onBlur: utils.createChainedFunction(onBlur, onRequestHideOptions),
625
+ ...overrideProps
626
+ };
627
+ // suppressHydrationWarning is needed because `role` depends on the browser type
628
+ return (0, _jsxRuntime.jsx)(_latest3.TextInput, {
629
+ ...triggerProps,
630
+ ...getInputProps(inputProps),
631
+ suppressHydrationWarning: true,
632
+ ...(interaction === 'enabled' && !isEditable && {
633
+ themeOverride: componentTheme => ({
634
+ backgroundReadonlyColor: componentTheme.backgroundColor
635
+ })
636
+ })
637
+ });
638
+ }
639
+ render() {
640
+ const _this$props10 = this.props,
641
+ constrain = _this$props10.constrain,
642
+ placement = _this$props10.placement,
643
+ mountNode = _this$props10.mountNode,
644
+ assistiveText = _this$props10.assistiveText,
645
+ isShowingOptions = _this$props10.isShowingOptions,
646
+ styles = _this$props10.styles;
647
+ // clear temporary option store
648
+ this._optionIds = [];
649
+ const highlightedOptionId = this.highlightedOptionId;
650
+ const selectedOptionId = this.selectedOptionId;
651
+ return (0, _jsxRuntime.jsx)(_Selectable.Selectable, {
652
+ highlightedOptionId: highlightedOptionId,
653
+ isShowingOptions: isShowingOptions,
654
+ selectedOptionId: selectedOptionId,
655
+ ...this.getEventHandlers(),
656
+ children: ({
657
+ getRootProps,
658
+ getInputProps,
659
+ getTriggerProps,
660
+ getListProps,
661
+ getOptionProps,
662
+ getDisabledOptionProps,
663
+ getDescriptionProps
664
+ }) => (0, _jsxRuntime.jsxs)("span", {
665
+ ...getRootProps(),
666
+ ref: el => {
667
+ this.ref = el;
668
+ },
669
+ "data-cid": (0, _combineDataCid.combineDataCid)('Select', this.props),
670
+ children: [this.renderInput({
671
+ getInputProps,
672
+ getTriggerProps
673
+ }), (0, _jsxRuntime.jsx)("span", {
674
+ ...getDescriptionProps(),
675
+ css: styles === null || styles === void 0 ? void 0 : styles.assistiveText,
676
+ children: assistiveText
677
+ }), (0, _jsxRuntime.jsx)(_latest2.Popover, {
678
+ constrain: constrain,
679
+ placement: placement
680
+ // On iOS VoiceOver, the Popover is mounted right after the input
681
+ // in order to be able to navigate through the list items with a swipe.
682
+ // The swipe would result in closing the listbox if mounted elsewhere.
683
+ ,
684
+ mountNode: mountNode !== void 0 ? mountNode : utils.isAndroidOrIOS() ? this.ref : void 0,
685
+ positionTarget: this._inputContainer,
686
+ isShowingContent: isShowingOptions,
687
+ shouldReturnFocus: false,
688
+ withArrow: false,
689
+ borderWidth: styles === null || styles === void 0 ? void 0 : styles.popoverBorderWidth,
690
+ children: this.renderList({
691
+ getListProps,
692
+ getOptionProps,
693
+ getDisabledOptionProps
694
+ })
695
+ })]
696
+ })
697
+ });
698
+ }
699
+ }, _Select.displayName = "Select", _Select.componentId = 'Select', _Select.allowedProps = _props.allowedProps, _Select.defaultProps = {
700
+ inputValue: '',
701
+ isShowingOptions: false,
702
+ size: 'medium',
703
+ // Leave interaction default undefined so that `disabled` and `readOnly` can also be supplied
704
+ interaction: void 0,
705
+ isRequired: false,
706
+ isInline: false,
707
+ visibleOptionsCount: 8,
708
+ placement: 'bottom stretch',
709
+ constrain: 'window',
710
+ shouldNotWrap: false,
711
+ scrollToHighlightedOption: true,
712
+ isOptionContentAppliedToInput: false
713
+ }, _Select.Option = _Option.Option, _Select.Group = _Group.Group, _Select)) || _class) || _class);
714
+ var _default = exports.default = Select;