@instructure/ui-select 11.7.3 → 11.7.4-pr-snapshot-1781695314229

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