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