@instructure/ui-simple-select 11.7.3-snapshot-7 → 11.7.3-snapshot-26

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.
@@ -1,12 +1,10 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
3
  var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = exports.SimpleSelect = void 0;
9
- var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
10
8
  var _react = require("react");
11
9
  var utils = _interopRequireWildcard(require("@instructure/ui-utils"));
12
10
  var _matchComponentTypes = require("@instructure/ui-react-utils/lib/matchComponentTypes.js");
@@ -19,10 +17,7 @@ var _Option = require("./Option");
19
17
  var _Group = require("./Group");
20
18
  var _props = require("./props");
21
19
  var _jsxRuntime = require("@emotion/react/jsx-runtime");
22
- const _excluded = ["id", "value", "children", "renderBeforeLabel", "renderAfterLabel"],
23
- _excluded2 = ["id", "renderLabel", "children"],
24
- _excluded3 = ["renderLabel", "value", "defaultValue", "id", "size", "assistiveText", "placeholder", "interaction", "isRequired", "isInline", "width", "optionsMaxWidth", "optionsMaxHeight", "visibleOptionsCount", "messages", "placement", "constrain", "mountNode", "inputRef", "listRef", "renderEmptyOption", "renderBeforeInput", "renderAfterInput", "onFocus", "onBlur", "onShowOptions", "onHideOptions", "children", "layout"];
25
- var _dec, _class, _SimpleSelect;
20
+ var _dec, _class;
26
21
  /*
27
22
  * The MIT License (MIT)
28
23
  *
@@ -52,137 +47,32 @@ category: components
52
47
  tags: form, field, dropdown
53
48
  ---
54
49
  **/
55
- let SimpleSelect = exports.SimpleSelect = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec(_class = (_SimpleSelect = class SimpleSelect extends _react.Component {
50
+ let SimpleSelect = exports.SimpleSelect = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec(_class = class SimpleSelect extends _react.Component {
51
+ static displayName = "SimpleSelect";
52
+ static componentId = 'SimpleSelect';
53
+ static Option = _Option.Option;
54
+ static Group = _Group.Group;
55
+ static allowedProps = _props.allowedProps;
56
+ static defaultProps = {
57
+ size: 'medium',
58
+ isRequired: false,
59
+ isInline: false,
60
+ visibleOptionsCount: 8,
61
+ placement: 'bottom stretch',
62
+ constrain: 'window',
63
+ renderEmptyOption: '---',
64
+ isOptionContentAppliedToInput: false
65
+ };
66
+ ref = null;
67
+ _emptyOptionId;
56
68
  constructor(props) {
57
69
  super(props);
58
- this.ref = null;
59
- this._emptyOptionId = void 0;
60
- this.getOption = (field, value) => {
61
- const children = _react.Children.toArray(this.props.children);
62
- let match;
63
- for (let i = 0; i < children.length; ++i) {
64
- const child = children[i];
65
- if ((0, _matchComponentTypes.matchComponentTypes)(child, [_Option.Option])) {
66
- if (child.props[field] === value) {
67
- match = child;
68
- }
69
- } else if ((0, _matchComponentTypes.matchComponentTypes)(child, [_Group.Group])) {
70
- const groupChildren = _react.Children.toArray(child.props.children);
71
- for (let j = 0; j < groupChildren.length; ++j) {
72
- const groupChild = groupChildren[j];
73
- if (groupChild.props[field] === value) {
74
- match = groupChild;
75
- break;
76
- }
77
- }
78
- }
79
- if (match) break;
80
- }
81
- return match;
82
- };
83
- this.handleRef = node => {
84
- this.ref = node;
85
- };
86
- this.handleBlur = event => {
87
- this.setState({
88
- highlightedOptionId: void 0
89
- });
90
- if (typeof this.props.onBlur === 'function') {
91
- this.props.onBlur(event);
92
- }
93
- };
94
- this.handleShowOptions = event => {
95
- this.setState({
96
- isShowingOptions: true
97
- });
98
- if (typeof this.props.onShowOptions === 'function') {
99
- this.props.onShowOptions(event);
100
- }
101
- if (event.type.startsWith('key')) {
102
- const keyboardEvent = event;
103
- const children = _react.Children.toArray(this.props.children);
104
- if (!this.state.inputValue && children.length > 0) {
105
- const position = keyboardEvent.key === 'ArrowDown' ? 'first' : keyboardEvent.key === 'ArrowUp' ? 'last' : void 0;
106
- if (position) {
107
- var _this$getOptionByPosi;
108
- const optionId = (_this$getOptionByPosi = this.getOptionByPosition(position)) === null || _this$getOptionByPosi === void 0 ? void 0 : _this$getOptionByPosi.props.id;
109
- optionId && this.setState({
110
- highlightedOptionId: optionId
111
- });
112
- }
113
- }
114
- }
115
- };
116
- this.handleHideOptions = event => {
117
- this.setState(state => {
118
- const option = this.getOption('id', state.selectedOptionId);
119
- return {
120
- isShowingOptions: false,
121
- highlightedOptionId: void 0,
122
- inputValue: option ? option.props.children : ''
123
- };
124
- });
125
- if (typeof this.props.onHideOptions === 'function') {
126
- this.props.onHideOptions(event);
127
- }
128
- };
129
- this.handleHighlightOption = (_event, {
130
- id
131
- }) => {
132
- if (id === this._emptyOptionId) return;
133
- this.setState({
134
- highlightedOptionId: id,
135
- inputValue: this.state.inputValue
136
- });
137
- };
138
- this.handleSelectOption = (event, {
139
- id
140
- }) => {
141
- if (id === this._emptyOptionId) {
142
- // selected option is the empty option
143
- this.setState({
144
- isShowingOptions: false
145
- });
146
- return;
147
- }
148
- const option = this.getOption('id', id);
149
- const value = option && option.props.value;
150
-
151
- // Focus needs to be reapplied to input
152
- // after selecting an item to make sure VoiceOver behaves correctly on iOS
153
- if (utils.isAndroidOrIOS()) {
154
- this.blur();
155
- this.focus();
156
- }
157
- if (this.isControlled) {
158
- this.setState({
159
- isShowingOptions: false
160
- });
161
- } else {
162
- this.setState(state => ({
163
- isShowingOptions: false,
164
- selectedOptionId: id,
165
- inputValue: option ? option.props.children : state.inputValue
166
- }));
167
- }
168
- // fire onChange if selected option changed
169
- if (option && typeof this.props.onChange === 'function') {
170
- this.props.onChange(event, {
171
- value,
172
- id
173
- });
174
- }
175
- // hide options list whenever selection is made
176
- if (typeof this.props.onHideOptions === 'function') {
177
- this.props.onHideOptions(event);
178
- }
179
- };
180
- const _option = this.getInitialOption(props);
70
+ const option = this.getInitialOption(props);
181
71
  this.state = {
182
- inputValue: _option ? _option.props.children : '',
72
+ inputValue: option ? option.props.children : '',
183
73
  isShowingOptions: false,
184
- highlightedOptionId: void 0,
185
- selectedOptionId: _option ? _option.props.id : void 0
74
+ highlightedOptionId: undefined,
75
+ selectedOptionId: option ? option.props.id : undefined
186
76
  };
187
77
  this._emptyOptionId = props.deterministicId('Select-EmptyOption');
188
78
  }
@@ -199,7 +89,7 @@ let SimpleSelect = exports.SimpleSelect = (_dec = (0, _withDeterministicId.withD
199
89
  return this.ref ? this.ref.focused : false;
200
90
  }
201
91
  get id() {
202
- return this.ref ? this.ref.id : void 0;
92
+ return this.ref ? this.ref.id : undefined;
203
93
  }
204
94
  get isControlled() {
205
95
  return typeof this.props.value !== 'undefined';
@@ -226,7 +116,7 @@ let SimpleSelect = exports.SimpleSelect = (_dec = (0, _withDeterministicId.withD
226
116
  // state.inputValue
227
117
  const option = this.getOption('children', this.state.inputValue);
228
118
  this.setState({
229
- inputValue: option ? option.props.children : void 0,
119
+ inputValue: option ? option.props.children : undefined,
230
120
  selectedOptionId: option ? option.props.id : ''
231
121
  });
232
122
  }
@@ -245,8 +135,10 @@ let SimpleSelect = exports.SimpleSelect = (_dec = (0, _withDeterministicId.withD
245
135
  }
246
136
  }
247
137
  getInitialOption(props) {
248
- const value = props.value,
249
- defaultValue = props.defaultValue;
138
+ const {
139
+ value,
140
+ defaultValue
141
+ } = props;
250
142
  const initialValue = value || defaultValue;
251
143
  if (typeof initialValue === 'string' || typeof initialValue === 'number') {
252
144
  // get option based on value or defaultValue, if provided
@@ -276,6 +168,29 @@ let SimpleSelect = exports.SimpleSelect = (_dec = (0, _withDeterministicId.withD
276
168
  }
277
169
  return match;
278
170
  }
171
+ getOption = (field, value) => {
172
+ const children = _react.Children.toArray(this.props.children);
173
+ let match;
174
+ for (let i = 0; i < children.length; ++i) {
175
+ const child = children[i];
176
+ if ((0, _matchComponentTypes.matchComponentTypes)(child, [_Option.Option])) {
177
+ if (child.props[field] === value) {
178
+ match = child;
179
+ }
180
+ } else if ((0, _matchComponentTypes.matchComponentTypes)(child, [_Group.Group])) {
181
+ const groupChildren = _react.Children.toArray(child.props.children);
182
+ for (let j = 0; j < groupChildren.length; ++j) {
183
+ const groupChild = groupChildren[j];
184
+ if (groupChild.props[field] === value) {
185
+ match = groupChild;
186
+ break;
187
+ }
188
+ }
189
+ }
190
+ if (match) break;
191
+ }
192
+ return match;
193
+ };
279
194
  getOptionByPosition(position) {
280
195
  const children = _react.Children.toArray(this.props.children);
281
196
 
@@ -284,7 +199,7 @@ let SimpleSelect = exports.SimpleSelect = (_dec = (0, _withDeterministicId.withD
284
199
 
285
200
  // Check if child is an option or group
286
201
  const child = children[index];
287
- if (!child) return void 0;
202
+ if (!child) return undefined;
288
203
 
289
204
  // If it's a regular option, return it
290
205
  if ((0, _matchComponentTypes.matchComponentTypes)(child, [_Option.Option])) {
@@ -297,8 +212,104 @@ let SimpleSelect = exports.SimpleSelect = (_dec = (0, _withDeterministicId.withD
297
212
  const groupIndex = position === 'first' ? 0 : groupOptions.length - 1;
298
213
  return groupOptions[groupIndex];
299
214
  }
300
- return void 0;
215
+ return undefined;
301
216
  }
217
+ handleRef = node => {
218
+ this.ref = node;
219
+ };
220
+ handleBlur = event => {
221
+ this.setState({
222
+ highlightedOptionId: undefined
223
+ });
224
+ if (typeof this.props.onBlur === 'function') {
225
+ this.props.onBlur(event);
226
+ }
227
+ };
228
+ handleShowOptions = event => {
229
+ this.setState({
230
+ isShowingOptions: true
231
+ });
232
+ if (typeof this.props.onShowOptions === 'function') {
233
+ this.props.onShowOptions(event);
234
+ }
235
+ if (event.type.startsWith('key')) {
236
+ const keyboardEvent = event;
237
+ const children = _react.Children.toArray(this.props.children);
238
+ if (!this.state.inputValue && children.length > 0) {
239
+ const position = keyboardEvent.key === 'ArrowDown' ? 'first' : keyboardEvent.key === 'ArrowUp' ? 'last' : undefined;
240
+ if (position) {
241
+ const optionId = this.getOptionByPosition(position)?.props.id;
242
+ optionId && this.setState({
243
+ highlightedOptionId: optionId
244
+ });
245
+ }
246
+ }
247
+ }
248
+ };
249
+ handleHideOptions = event => {
250
+ this.setState(state => {
251
+ const option = this.getOption('id', state.selectedOptionId);
252
+ return {
253
+ isShowingOptions: false,
254
+ highlightedOptionId: undefined,
255
+ inputValue: option ? option.props.children : ''
256
+ };
257
+ });
258
+ if (typeof this.props.onHideOptions === 'function') {
259
+ this.props.onHideOptions(event);
260
+ }
261
+ };
262
+ handleHighlightOption = (_event, {
263
+ id
264
+ }) => {
265
+ if (id === this._emptyOptionId) return;
266
+ this.setState({
267
+ highlightedOptionId: id,
268
+ inputValue: this.state.inputValue
269
+ });
270
+ };
271
+ handleSelectOption = (event, {
272
+ id
273
+ }) => {
274
+ if (id === this._emptyOptionId) {
275
+ // selected option is the empty option
276
+ this.setState({
277
+ isShowingOptions: false
278
+ });
279
+ return;
280
+ }
281
+ const option = this.getOption('id', id);
282
+ const value = option && option.props.value;
283
+
284
+ // Focus needs to be reapplied to input
285
+ // after selecting an item to make sure VoiceOver behaves correctly on iOS
286
+ if (utils.isAndroidOrIOS()) {
287
+ this.blur();
288
+ this.focus();
289
+ }
290
+ if (this.isControlled) {
291
+ this.setState({
292
+ isShowingOptions: false
293
+ });
294
+ } else {
295
+ this.setState(state => ({
296
+ isShowingOptions: false,
297
+ selectedOptionId: id,
298
+ inputValue: option ? option.props.children : state.inputValue
299
+ }));
300
+ }
301
+ // fire onChange if selected option changed
302
+ if (option && typeof this.props.onChange === 'function') {
303
+ this.props.onChange(event, {
304
+ value,
305
+ id
306
+ });
307
+ }
308
+ // hide options list whenever selection is made
309
+ if (typeof this.props.onHideOptions === 'function') {
310
+ this.props.onHideOptions(event);
311
+ }
312
+ };
302
313
  renderChildren() {
303
314
  let children = _react.Children.toArray(this.props.children);
304
315
  children = _react.Children.map(children, child => {
@@ -324,20 +335,19 @@ let SimpleSelect = exports.SimpleSelect = (_dec = (0, _withDeterministicId.withD
324
335
  });
325
336
  }
326
337
  renderOption(option) {
327
- var _option$props$isDisab;
328
- const _option$props = option.props,
329
- id = _option$props.id,
330
- value = _option$props.value,
331
- children = _option$props.children,
332
- renderBeforeLabel = _option$props.renderBeforeLabel,
333
- renderAfterLabel = _option$props.renderAfterLabel,
334
- rest = (0, _objectWithoutProperties2.default)(_option$props, _excluded);
335
- const isDisabled = (_option$props$isDisab = option.props.isDisabled) !== null && _option$props$isDisab !== void 0 ? _option$props$isDisab : false; // after the react 19 upgrade `isDisabled` is undefined instead of defaulting to false if not specified (but only in vitest env for some reason)
338
+ const {
339
+ id,
340
+ value,
341
+ children,
342
+ renderBeforeLabel,
343
+ renderAfterLabel,
344
+ ...rest
345
+ } = option.props;
346
+ const isDisabled = option.props.isDisabled ?? false; // after the react 19 upgrade `isDisabled` is undefined instead of defaulting to false if not specified (but only in vitest env for some reason)
336
347
  const isSelected = id === this.state.selectedOptionId;
337
348
  const isHighlighted = id === this.state.highlightedOptionId;
338
349
  const getRenderLabel = renderLabel => {
339
- var _renderLabel$prototyp;
340
- if (typeof renderLabel === 'function' && !(renderLabel !== null && renderLabel !== void 0 && (_renderLabel$prototyp = renderLabel.prototype) !== null && _renderLabel$prototyp !== void 0 && _renderLabel$prototyp.isReactComponent)) {
350
+ if (typeof renderLabel === 'function' && !renderLabel?.prototype?.isReactComponent) {
341
351
  return renderLabel.bind(null, {
342
352
  id,
343
353
  isDisabled,
@@ -361,11 +371,12 @@ let SimpleSelect = exports.SimpleSelect = (_dec = (0, _withDeterministicId.withD
361
371
  }, option.key || id);
362
372
  }
363
373
  renderGroup(group) {
364
- const _group$props = group.props,
365
- id = _group$props.id,
366
- renderLabel = _group$props.renderLabel,
367
- children = _group$props.children,
368
- rest = (0, _objectWithoutProperties2.default)(_group$props, _excluded2);
374
+ const {
375
+ id,
376
+ renderLabel,
377
+ children,
378
+ ...rest
379
+ } = group.props;
369
380
  return (0, _jsxRuntime.jsx)(_latest.Select.Group, {
370
381
  renderLabel: renderLabel,
371
382
  ...(0, _passthroughProps.passthroughProps)(rest),
@@ -373,37 +384,38 @@ let SimpleSelect = exports.SimpleSelect = (_dec = (0, _withDeterministicId.withD
373
384
  }, group.key || id);
374
385
  }
375
386
  render() {
376
- const _this$props = this.props,
377
- renderLabel = _this$props.renderLabel,
378
- value = _this$props.value,
379
- defaultValue = _this$props.defaultValue,
380
- id = _this$props.id,
381
- size = _this$props.size,
382
- assistiveText = _this$props.assistiveText,
383
- placeholder = _this$props.placeholder,
384
- interaction = _this$props.interaction,
385
- isRequired = _this$props.isRequired,
386
- isInline = _this$props.isInline,
387
- width = _this$props.width,
388
- optionsMaxWidth = _this$props.optionsMaxWidth,
389
- optionsMaxHeight = _this$props.optionsMaxHeight,
390
- visibleOptionsCount = _this$props.visibleOptionsCount,
391
- messages = _this$props.messages,
392
- placement = _this$props.placement,
393
- constrain = _this$props.constrain,
394
- mountNode = _this$props.mountNode,
395
- inputRef = _this$props.inputRef,
396
- listRef = _this$props.listRef,
397
- renderEmptyOption = _this$props.renderEmptyOption,
398
- renderBeforeInput = _this$props.renderBeforeInput,
399
- renderAfterInput = _this$props.renderAfterInput,
400
- onFocus = _this$props.onFocus,
401
- onBlur = _this$props.onBlur,
402
- onShowOptions = _this$props.onShowOptions,
403
- onHideOptions = _this$props.onHideOptions,
404
- children = _this$props.children,
405
- layout = _this$props.layout,
406
- rest = (0, _objectWithoutProperties2.default)(_this$props, _excluded3);
387
+ const {
388
+ renderLabel,
389
+ value,
390
+ defaultValue,
391
+ id,
392
+ size,
393
+ assistiveText,
394
+ placeholder,
395
+ interaction,
396
+ isRequired,
397
+ isInline,
398
+ width,
399
+ optionsMaxWidth,
400
+ optionsMaxHeight,
401
+ visibleOptionsCount,
402
+ messages,
403
+ placement,
404
+ constrain,
405
+ mountNode,
406
+ inputRef,
407
+ listRef,
408
+ renderEmptyOption,
409
+ renderBeforeInput,
410
+ renderAfterInput,
411
+ onFocus,
412
+ onBlur,
413
+ onShowOptions,
414
+ onHideOptions,
415
+ children,
416
+ layout,
417
+ ...rest
418
+ } = this.props;
407
419
  return (0, _jsxRuntime.jsx)(_latest.Select, {
408
420
  renderLabel: renderLabel,
409
421
  inputValue: this.state.inputValue,
@@ -441,14 +453,5 @@ let SimpleSelect = exports.SimpleSelect = (_dec = (0, _withDeterministicId.withD
441
453
  children: this.renderChildren()
442
454
  });
443
455
  }
444
- }, _SimpleSelect.displayName = "SimpleSelect", _SimpleSelect.componentId = 'SimpleSelect', _SimpleSelect.Option = _Option.Option, _SimpleSelect.Group = _Group.Group, _SimpleSelect.allowedProps = _props.allowedProps, _SimpleSelect.defaultProps = {
445
- size: 'medium',
446
- isRequired: false,
447
- isInline: false,
448
- visibleOptionsCount: 8,
449
- placement: 'bottom stretch',
450
- constrain: 'window',
451
- renderEmptyOption: '---',
452
- isOptionContentAppliedToInput: false
453
- }, _SimpleSelect)) || _class);
456
+ }) || _class);
454
457
  var _default = exports.default = SimpleSelect;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-simple-select",
3
- "version": "11.7.3-snapshot-7",
3
+ "version": "11.7.3-snapshot-26",
4
4
  "description": "A component for standard select element behavior.",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -14,23 +14,23 @@
14
14
  "bugs": "https://github.com/instructure/instructure-ui/issues",
15
15
  "license": "MIT",
16
16
  "dependencies": {
17
- "@babel/runtime": "^7.27.6",
18
- "@instructure/console": "11.7.3-snapshot-7",
19
- "@instructure/shared-types": "11.7.3-snapshot-7",
20
- "@instructure/ui-position": "11.7.3-snapshot-7",
21
- "@instructure/ui-react-utils": "11.7.3-snapshot-7",
22
- "@instructure/ui-form-field": "11.7.3-snapshot-7",
23
- "@instructure/ui-select": "11.7.3-snapshot-7"
17
+ "@babel/runtime": "^7.29.2",
18
+ "@instructure/console": "11.7.3-snapshot-26",
19
+ "@instructure/ui-form-field": "11.7.3-snapshot-26",
20
+ "@instructure/ui-position": "11.7.3-snapshot-26",
21
+ "@instructure/ui-react-utils": "11.7.3-snapshot-26",
22
+ "@instructure/shared-types": "11.7.3-snapshot-26",
23
+ "@instructure/ui-select": "11.7.3-snapshot-26"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@testing-library/jest-dom": "^6.6.3",
27
27
  "@testing-library/react": "15.0.7",
28
28
  "@testing-library/user-event": "^14.6.1",
29
29
  "vitest": "^3.2.2",
30
- "@instructure/ui-babel-preset": "11.7.3-snapshot-7",
31
- "@instructure/ui-color-utils": "11.7.3-snapshot-7",
32
- "@instructure/ui-icons": "11.7.3-snapshot-7",
33
- "@instructure/ui-utils": "11.7.3-snapshot-7"
30
+ "@instructure/ui-color-utils": "11.7.3-snapshot-26",
31
+ "@instructure/ui-babel-preset": "11.7.3-snapshot-26",
32
+ "@instructure/ui-icons": "11.7.3-snapshot-26",
33
+ "@instructure/ui-utils": "11.7.3-snapshot-26"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "react": ">=18 <=19"