@instructure/ui-simple-select 8.25.1-snapshot-7 → 8.25.1-snapshot-10

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.
@@ -37,7 +37,7 @@ const _excluded = ["id", "value", "children", "renderBeforeLabel", "renderAfterL
37
37
  _excluded2 = ["id", "renderLabel", "children"],
38
38
  _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"];
39
39
 
40
- var _dec, _dec2, _class, _class2;
40
+ var _dec, _dec2, _class;
41
41
 
42
42
  /**
43
43
  ---
@@ -46,141 +46,33 @@ tags: form, field, dropdown
46
46
  ---
47
47
  @tsProps
48
48
  **/
49
- let SimpleSelect = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = (_class2 = class SimpleSelect extends _react.Component {
49
+ let SimpleSelect = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = class SimpleSelect extends _react.Component {
50
+ static displayName = "SimpleSelect";
51
+ static componentId = 'SimpleSelect';
52
+ static Option = _Option.Option;
53
+ static Group = _Group.Group;
54
+ static allowedProps = _props.allowedProps;
55
+ static propTypes = _props.propTypes;
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
+ };
65
+ ref = null;
66
+ _emptyOptionId;
67
+
50
68
  constructor(props) {
51
69
  super(props);
52
- this.ref = null;
53
- this._emptyOptionId = void 0;
54
-
55
- this.getOption = (field, value) => {
56
- const children = _react.Children.toArray(this.props.children);
57
-
58
- let match;
59
-
60
- for (let i = 0; i < children.length; ++i) {
61
- const child = children[i];
62
-
63
- if ((0, _matchComponentTypes.matchComponentTypes)(child, [_Option.Option])) {
64
- if (child.props[field] === value) {
65
- match = child;
66
- }
67
- } else if ((0, _matchComponentTypes.matchComponentTypes)(child, [_Group.Group])) {
68
- const groupChildren = _react.Children.toArray(child.props.children);
69
-
70
- for (let j = 0; j < groupChildren.length; ++j) {
71
- const groupChild = groupChildren[j];
72
-
73
- if (groupChild.props[field] === value) {
74
- match = groupChild;
75
- break;
76
- }
77
- }
78
- }
79
-
80
- if (match) break;
81
- }
82
-
83
- return match;
84
- };
85
-
86
- this.handleRef = node => {
87
- this.ref = node;
88
- };
89
-
90
- this.handleBlur = event => {
91
- this.setState({
92
- highlightedOptionId: void 0
93
- });
94
-
95
- if (typeof this.props.onBlur === 'function') {
96
- this.props.onBlur(event);
97
- }
98
- };
99
-
100
- this.handleShowOptions = event => {
101
- this.setState({
102
- isShowingOptions: true
103
- });
104
-
105
- if (typeof this.props.onShowOptions === 'function') {
106
- this.props.onShowOptions(event);
107
- }
108
- };
109
-
110
- this.handleHideOptions = event => {
111
- this.setState(state => {
112
- const option = this.getOption('id', state.selectedOptionId);
113
- return {
114
- isShowingOptions: false,
115
- highlightedOptionId: void 0,
116
- inputValue: option ? option.props.children : ''
117
- };
118
- });
119
-
120
- if (typeof this.props.onHideOptions === 'function') {
121
- this.props.onHideOptions(event);
122
- }
123
- };
124
-
125
- this.handleHighlightOption = (event, _ref) => {
126
- let id = _ref.id;
127
- if (id === this._emptyOptionId) return;
128
- const option = this.getOption('id', id);
129
- const label = option === null || option === void 0 ? void 0 : option.props.children;
130
- const inputValue = event.type === 'keydown' ? label : this.state.inputValue;
131
- this.setState({
132
- highlightedOptionId: id,
133
- inputValue
134
- });
135
- };
136
-
137
- this.handleSelectOption = (event, _ref2) => {
138
- let id = _ref2.id;
139
-
140
- if (id === this._emptyOptionId) {
141
- // selected option is the empty option
142
- this.setState({
143
- isShowingOptions: false
144
- });
145
- return;
146
- }
147
-
148
- const option = this.getOption('id', id);
149
- const value = option && option.props.value;
150
-
151
- if (this.isControlled) {
152
- this.setState({
153
- isShowingOptions: false
154
- });
155
- } else {
156
- this.setState(state => ({
157
- isShowingOptions: false,
158
- selectedOptionId: id,
159
- inputValue: option ? option.props.children : state.inputValue
160
- }));
161
- } // fire onChange if selected option changed
162
-
163
-
164
- if (option && typeof this.props.onChange === 'function') {
165
- this.props.onChange(event, {
166
- value,
167
- id
168
- });
169
- } // hide options list whenever selection is made
170
-
171
-
172
- if (typeof this.props.onHideOptions === 'function') {
173
- this.props.onHideOptions(event);
174
- }
175
- };
176
-
177
- const _option = this.getInitialOption(props);
178
-
70
+ const option = this.getInitialOption(props);
179
71
  this.state = {
180
- inputValue: _option ? _option.props.children : '',
72
+ inputValue: option ? option.props.children : '',
181
73
  isShowingOptions: false,
182
74
  highlightedOptionId: void 0,
183
- selectedOptionId: _option ? _option.props.id : void 0
75
+ selectedOptionId: option ? option.props.id : void 0
184
76
  };
185
77
  this._emptyOptionId = props.deterministicId('Select-EmptyOption');
186
78
  }
@@ -269,6 +161,122 @@ let SimpleSelect = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec
269
161
  return match;
270
162
  }
271
163
 
164
+ getOption = (field, value) => {
165
+ const children = _react.Children.toArray(this.props.children);
166
+
167
+ let match;
168
+
169
+ for (let i = 0; i < children.length; ++i) {
170
+ const child = children[i];
171
+
172
+ if ((0, _matchComponentTypes.matchComponentTypes)(child, [_Option.Option])) {
173
+ if (child.props[field] === value) {
174
+ match = child;
175
+ }
176
+ } else if ((0, _matchComponentTypes.matchComponentTypes)(child, [_Group.Group])) {
177
+ const groupChildren = _react.Children.toArray(child.props.children);
178
+
179
+ for (let j = 0; j < groupChildren.length; ++j) {
180
+ const groupChild = groupChildren[j];
181
+
182
+ if (groupChild.props[field] === value) {
183
+ match = groupChild;
184
+ break;
185
+ }
186
+ }
187
+ }
188
+
189
+ if (match) break;
190
+ }
191
+
192
+ return match;
193
+ };
194
+ handleRef = node => {
195
+ this.ref = node;
196
+ };
197
+ handleBlur = event => {
198
+ this.setState({
199
+ highlightedOptionId: void 0
200
+ });
201
+
202
+ if (typeof this.props.onBlur === 'function') {
203
+ this.props.onBlur(event);
204
+ }
205
+ };
206
+ handleShowOptions = event => {
207
+ this.setState({
208
+ isShowingOptions: true
209
+ });
210
+
211
+ if (typeof this.props.onShowOptions === 'function') {
212
+ this.props.onShowOptions(event);
213
+ }
214
+ };
215
+ handleHideOptions = event => {
216
+ this.setState(state => {
217
+ const option = this.getOption('id', state.selectedOptionId);
218
+ return {
219
+ isShowingOptions: false,
220
+ highlightedOptionId: void 0,
221
+ inputValue: option ? option.props.children : ''
222
+ };
223
+ });
224
+
225
+ if (typeof this.props.onHideOptions === 'function') {
226
+ this.props.onHideOptions(event);
227
+ }
228
+ };
229
+ handleHighlightOption = (event, _ref) => {
230
+ let id = _ref.id;
231
+ if (id === this._emptyOptionId) return;
232
+ const option = this.getOption('id', id);
233
+ const label = option === null || option === void 0 ? void 0 : option.props.children;
234
+ const inputValue = event.type === 'keydown' ? label : this.state.inputValue;
235
+ this.setState({
236
+ highlightedOptionId: id,
237
+ inputValue
238
+ });
239
+ };
240
+ handleSelectOption = (event, _ref2) => {
241
+ let id = _ref2.id;
242
+
243
+ if (id === this._emptyOptionId) {
244
+ // selected option is the empty option
245
+ this.setState({
246
+ isShowingOptions: false
247
+ });
248
+ return;
249
+ }
250
+
251
+ const option = this.getOption('id', id);
252
+ const value = option && option.props.value;
253
+
254
+ if (this.isControlled) {
255
+ this.setState({
256
+ isShowingOptions: false
257
+ });
258
+ } else {
259
+ this.setState(state => ({
260
+ isShowingOptions: false,
261
+ selectedOptionId: id,
262
+ inputValue: option ? option.props.children : state.inputValue
263
+ }));
264
+ } // fire onChange if selected option changed
265
+
266
+
267
+ if (option && typeof this.props.onChange === 'function') {
268
+ this.props.onChange(event, {
269
+ value,
270
+ id
271
+ });
272
+ } // hide options list whenever selection is made
273
+
274
+
275
+ if (typeof this.props.onHideOptions === 'function') {
276
+ this.props.onHideOptions(event);
277
+ }
278
+ };
279
+
272
280
  renderChildren() {
273
281
  let children = _react.Children.toArray(this.props.children);
274
282
 
@@ -410,15 +418,7 @@ let SimpleSelect = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec
410
418
  }, (0, _passthroughProps.passthroughProps)(rest)), this.renderChildren());
411
419
  }
412
420
 
413
- }, _class2.displayName = "SimpleSelect", _class2.componentId = 'SimpleSelect', _class2.Option = _Option.Option, _class2.Group = _Group.Group, _class2.allowedProps = _props.allowedProps, _class2.propTypes = _props.propTypes, _class2.defaultProps = {
414
- size: 'medium',
415
- isRequired: false,
416
- isInline: false,
417
- visibleOptionsCount: 8,
418
- placement: 'bottom stretch',
419
- constrain: 'window',
420
- renderEmptyOption: '---'
421
- }, _class2)) || _class) || _class);
421
+ }) || _class) || _class);
422
422
  exports.SimpleSelect = SimpleSelect;
423
423
  var _default = SimpleSelect;
424
424
  exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-simple-select",
3
- "version": "8.25.1-snapshot-7",
3
+ "version": "8.25.1-snapshot-10",
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",
@@ -24,22 +24,22 @@
24
24
  "license": "MIT",
25
25
  "dependencies": {
26
26
  "@babel/runtime": "^7.13.10",
27
- "@instructure/console": "8.25.1-snapshot-7",
28
- "@instructure/shared-types": "8.25.1-snapshot-7",
29
- "@instructure/ui-form-field": "8.25.1-snapshot-7",
30
- "@instructure/ui-position": "8.25.1-snapshot-7",
31
- "@instructure/ui-prop-types": "8.25.1-snapshot-7",
32
- "@instructure/ui-react-utils": "8.25.1-snapshot-7",
33
- "@instructure/ui-select": "8.25.1-snapshot-7",
34
- "@instructure/ui-testable": "8.25.1-snapshot-7",
27
+ "@instructure/console": "8.25.1-snapshot-10",
28
+ "@instructure/shared-types": "8.25.1-snapshot-10",
29
+ "@instructure/ui-form-field": "8.25.1-snapshot-10",
30
+ "@instructure/ui-position": "8.25.1-snapshot-10",
31
+ "@instructure/ui-prop-types": "8.25.1-snapshot-10",
32
+ "@instructure/ui-react-utils": "8.25.1-snapshot-10",
33
+ "@instructure/ui-select": "8.25.1-snapshot-10",
34
+ "@instructure/ui-testable": "8.25.1-snapshot-10",
35
35
  "prop-types": "^15"
36
36
  },
37
37
  "devDependencies": {
38
- "@instructure/ui-babel-preset": "8.25.1-snapshot-7",
39
- "@instructure/ui-color-utils": "8.25.1-snapshot-7",
40
- "@instructure/ui-icons": "8.25.1-snapshot-7",
41
- "@instructure/ui-test-locator": "8.25.1-snapshot-7",
42
- "@instructure/ui-test-utils": "8.25.1-snapshot-7"
38
+ "@instructure/ui-babel-preset": "8.25.1-snapshot-10",
39
+ "@instructure/ui-color-utils": "8.25.1-snapshot-10",
40
+ "@instructure/ui-icons": "8.25.1-snapshot-10",
41
+ "@instructure/ui-test-locator": "8.25.1-snapshot-10",
42
+ "@instructure/ui-test-utils": "8.25.1-snapshot-10"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "react": ">=16.8 <=17"