@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.
package/CHANGELOG.md CHANGED
@@ -3,7 +3,7 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [8.25.1-snapshot-7](https://github.com/instructure/instructure-ui/compare/v8.25.0...v8.25.1-snapshot-7) (2022-06-13)
6
+ ## [8.25.1-snapshot-10](https://github.com/instructure/instructure-ui/compare/v8.25.0...v8.25.1-snapshot-10) (2022-06-20)
7
7
 
8
8
  **Note:** Version bump only for package @instructure/ui-simple-select
9
9
 
@@ -32,7 +32,13 @@ id: SimpleSelect.Group
32
32
  **/
33
33
 
34
34
  class Group extends Component {
35
+ static displayName = "Group";
36
+ static componentId = 'SimpleSelect.Group';
37
+ static allowedProps = allowedProps;
38
+ static propTypes = propTypes;
39
+ static defaultProps = {};
35
40
  /* istanbul ignore next */
41
+
36
42
  render() {
37
43
  // this component is only used for prop validation. Select.Group children
38
44
  // are parsed in Select and rendered as Options components
@@ -41,10 +47,5 @@ class Group extends Component {
41
47
 
42
48
  }
43
49
 
44
- Group.displayName = "Group";
45
- Group.componentId = 'SimpleSelect.Group';
46
- Group.allowedProps = allowedProps;
47
- Group.propTypes = propTypes;
48
- Group.defaultProps = {};
49
50
  export default Group;
50
51
  export { Group };
@@ -32,7 +32,15 @@ id: SimpleSelect.Option
32
32
  **/
33
33
 
34
34
  class Option extends Component {
35
+ static displayName = "Option";
36
+ static componentId = 'SimpleSelect.Option';
37
+ static allowedProps = allowedProps;
38
+ static propTypes = propTypes;
39
+ static defaultProps = {
40
+ isDisabled: false
41
+ };
35
42
  /* istanbul ignore next */
43
+
36
44
  render() {
37
45
  // this component is only used for prop validation. SimpleSelect.Option children
38
46
  // are parsed in Select and rendered as Options.Item components
@@ -41,12 +49,5 @@ class Option extends Component {
41
49
 
42
50
  }
43
51
 
44
- Option.displayName = "Option";
45
- Option.componentId = 'SimpleSelect.Option';
46
- Option.allowedProps = allowedProps;
47
- Option.propTypes = propTypes;
48
- Option.defaultProps = {
49
- isDisabled: false
50
- };
51
52
  export default Option;
52
53
  export { Option };
@@ -3,7 +3,7 @@ const _excluded = ["id", "value", "children", "renderBeforeLabel", "renderAfterL
3
3
  _excluded2 = ["id", "renderLabel", "children"],
4
4
  _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"];
5
5
 
6
- var _dec, _dec2, _class, _class2;
6
+ var _dec, _dec2, _class;
7
7
 
8
8
  /*
9
9
  * The MIT License (MIT)
@@ -43,140 +43,33 @@ tags: form, field, dropdown
43
43
  ---
44
44
  @tsProps
45
45
  **/
46
- let SimpleSelect = (_dec = withDeterministicId(), _dec2 = testable(), _dec(_class = _dec2(_class = (_class2 = class SimpleSelect extends Component {
46
+ let SimpleSelect = (_dec = withDeterministicId(), _dec2 = testable(), _dec(_class = _dec2(_class = class SimpleSelect extends Component {
47
+ static displayName = "SimpleSelect";
48
+ static componentId = 'SimpleSelect';
49
+ static Option = Option;
50
+ static Group = Group;
51
+ static allowedProps = allowedProps;
52
+ static propTypes = propTypes;
53
+ static defaultProps = {
54
+ size: 'medium',
55
+ isRequired: false,
56
+ isInline: false,
57
+ visibleOptionsCount: 8,
58
+ placement: 'bottom stretch',
59
+ constrain: 'window',
60
+ renderEmptyOption: '---'
61
+ };
62
+ ref = null;
63
+ _emptyOptionId;
64
+
47
65
  constructor(props) {
48
66
  super(props);
49
- this.ref = null;
50
- this._emptyOptionId = void 0;
51
-
52
- this.getOption = (field, value) => {
53
- const children = Children.toArray(this.props.children);
54
- let match;
55
-
56
- for (let i = 0; i < children.length; ++i) {
57
- const child = children[i];
58
-
59
- if (matchComponentTypes(child, [Option])) {
60
- if (child.props[field] === value) {
61
- match = child;
62
- }
63
- } else if (matchComponentTypes(child, [Group])) {
64
- const groupChildren = Children.toArray(child.props.children);
65
-
66
- for (let j = 0; j < groupChildren.length; ++j) {
67
- const groupChild = groupChildren[j];
68
-
69
- if (groupChild.props[field] === value) {
70
- match = groupChild;
71
- break;
72
- }
73
- }
74
- }
75
-
76
- if (match) break;
77
- }
78
-
79
- return match;
80
- };
81
-
82
- this.handleRef = node => {
83
- this.ref = node;
84
- };
85
-
86
- this.handleBlur = event => {
87
- this.setState({
88
- highlightedOptionId: void 0
89
- });
90
-
91
- if (typeof this.props.onBlur === 'function') {
92
- this.props.onBlur(event);
93
- }
94
- };
95
-
96
- this.handleShowOptions = event => {
97
- this.setState({
98
- isShowingOptions: true
99
- });
100
-
101
- if (typeof this.props.onShowOptions === 'function') {
102
- this.props.onShowOptions(event);
103
- }
104
- };
105
-
106
- this.handleHideOptions = event => {
107
- this.setState(state => {
108
- const option = this.getOption('id', state.selectedOptionId);
109
- return {
110
- isShowingOptions: false,
111
- highlightedOptionId: void 0,
112
- inputValue: option ? option.props.children : ''
113
- };
114
- });
115
-
116
- if (typeof this.props.onHideOptions === 'function') {
117
- this.props.onHideOptions(event);
118
- }
119
- };
120
-
121
- this.handleHighlightOption = (event, _ref) => {
122
- let id = _ref.id;
123
- if (id === this._emptyOptionId) return;
124
- const option = this.getOption('id', id);
125
- const label = option === null || option === void 0 ? void 0 : option.props.children;
126
- const inputValue = event.type === 'keydown' ? label : this.state.inputValue;
127
- this.setState({
128
- highlightedOptionId: id,
129
- inputValue
130
- });
131
- };
132
-
133
- this.handleSelectOption = (event, _ref2) => {
134
- let id = _ref2.id;
135
-
136
- if (id === this._emptyOptionId) {
137
- // selected option is the empty option
138
- this.setState({
139
- isShowingOptions: false
140
- });
141
- return;
142
- }
143
-
144
- const option = this.getOption('id', id);
145
- const value = option && option.props.value;
146
-
147
- if (this.isControlled) {
148
- this.setState({
149
- isShowingOptions: false
150
- });
151
- } else {
152
- this.setState(state => ({
153
- isShowingOptions: false,
154
- selectedOptionId: id,
155
- inputValue: option ? option.props.children : state.inputValue
156
- }));
157
- } // fire onChange if selected option changed
158
-
159
-
160
- if (option && typeof this.props.onChange === 'function') {
161
- this.props.onChange(event, {
162
- value,
163
- id
164
- });
165
- } // hide options list whenever selection is made
166
-
167
-
168
- if (typeof this.props.onHideOptions === 'function') {
169
- this.props.onHideOptions(event);
170
- }
171
- };
172
-
173
- const _option = this.getInitialOption(props);
174
-
67
+ const option = this.getInitialOption(props);
175
68
  this.state = {
176
- inputValue: _option ? _option.props.children : '',
69
+ inputValue: option ? option.props.children : '',
177
70
  isShowingOptions: false,
178
71
  highlightedOptionId: void 0,
179
- selectedOptionId: _option ? _option.props.id : void 0
72
+ selectedOptionId: option ? option.props.id : void 0
180
73
  };
181
74
  this._emptyOptionId = props.deterministicId('Select-EmptyOption');
182
75
  }
@@ -264,6 +157,121 @@ let SimpleSelect = (_dec = withDeterministicId(), _dec2 = testable(), _dec(_clas
264
157
  return match;
265
158
  }
266
159
 
160
+ getOption = (field, value) => {
161
+ const children = Children.toArray(this.props.children);
162
+ let match;
163
+
164
+ for (let i = 0; i < children.length; ++i) {
165
+ const child = children[i];
166
+
167
+ if (matchComponentTypes(child, [Option])) {
168
+ if (child.props[field] === value) {
169
+ match = child;
170
+ }
171
+ } else if (matchComponentTypes(child, [Group])) {
172
+ const groupChildren = Children.toArray(child.props.children);
173
+
174
+ for (let j = 0; j < groupChildren.length; ++j) {
175
+ const groupChild = groupChildren[j];
176
+
177
+ if (groupChild.props[field] === value) {
178
+ match = groupChild;
179
+ break;
180
+ }
181
+ }
182
+ }
183
+
184
+ if (match) break;
185
+ }
186
+
187
+ return match;
188
+ };
189
+ handleRef = node => {
190
+ this.ref = node;
191
+ };
192
+ handleBlur = event => {
193
+ this.setState({
194
+ highlightedOptionId: void 0
195
+ });
196
+
197
+ if (typeof this.props.onBlur === 'function') {
198
+ this.props.onBlur(event);
199
+ }
200
+ };
201
+ handleShowOptions = event => {
202
+ this.setState({
203
+ isShowingOptions: true
204
+ });
205
+
206
+ if (typeof this.props.onShowOptions === 'function') {
207
+ this.props.onShowOptions(event);
208
+ }
209
+ };
210
+ handleHideOptions = event => {
211
+ this.setState(state => {
212
+ const option = this.getOption('id', state.selectedOptionId);
213
+ return {
214
+ isShowingOptions: false,
215
+ highlightedOptionId: void 0,
216
+ inputValue: option ? option.props.children : ''
217
+ };
218
+ });
219
+
220
+ if (typeof this.props.onHideOptions === 'function') {
221
+ this.props.onHideOptions(event);
222
+ }
223
+ };
224
+ handleHighlightOption = (event, _ref) => {
225
+ let id = _ref.id;
226
+ if (id === this._emptyOptionId) return;
227
+ const option = this.getOption('id', id);
228
+ const label = option === null || option === void 0 ? void 0 : option.props.children;
229
+ const inputValue = event.type === 'keydown' ? label : this.state.inputValue;
230
+ this.setState({
231
+ highlightedOptionId: id,
232
+ inputValue
233
+ });
234
+ };
235
+ handleSelectOption = (event, _ref2) => {
236
+ let id = _ref2.id;
237
+
238
+ if (id === this._emptyOptionId) {
239
+ // selected option is the empty option
240
+ this.setState({
241
+ isShowingOptions: false
242
+ });
243
+ return;
244
+ }
245
+
246
+ const option = this.getOption('id', id);
247
+ const value = option && option.props.value;
248
+
249
+ if (this.isControlled) {
250
+ this.setState({
251
+ isShowingOptions: false
252
+ });
253
+ } else {
254
+ this.setState(state => ({
255
+ isShowingOptions: false,
256
+ selectedOptionId: id,
257
+ inputValue: option ? option.props.children : state.inputValue
258
+ }));
259
+ } // fire onChange if selected option changed
260
+
261
+
262
+ if (option && typeof this.props.onChange === 'function') {
263
+ this.props.onChange(event, {
264
+ value,
265
+ id
266
+ });
267
+ } // hide options list whenever selection is made
268
+
269
+
270
+ if (typeof this.props.onHideOptions === 'function') {
271
+ this.props.onHideOptions(event);
272
+ }
273
+ };
274
+
267
275
  renderChildren() {
268
276
  let children = Children.toArray(this.props.children);
269
277
  children = Children.map(children, child => {
@@ -407,14 +415,6 @@ let SimpleSelect = (_dec = withDeterministicId(), _dec2 = testable(), _dec(_clas
407
415
  }, passthroughProps(rest)), this.renderChildren());
408
416
  }
409
417
 
410
- }, _class2.displayName = "SimpleSelect", _class2.componentId = 'SimpleSelect', _class2.Option = Option, _class2.Group = Group, _class2.allowedProps = allowedProps, _class2.propTypes = propTypes, _class2.defaultProps = {
411
- size: 'medium',
412
- isRequired: false,
413
- isInline: false,
414
- visibleOptionsCount: 8,
415
- placement: 'bottom stretch',
416
- constrain: 'window',
417
- renderEmptyOption: '---'
418
- }, _class2)) || _class) || _class);
418
+ }) || _class) || _class);
419
419
  export { SimpleSelect };
420
420
  export default SimpleSelect;
@@ -41,7 +41,13 @@ id: SimpleSelect.Group
41
41
  @tsProps
42
42
  **/
43
43
  class Group extends _react.Component {
44
+ static displayName = "Group";
45
+ static componentId = 'SimpleSelect.Group';
46
+ static allowedProps = _props.allowedProps;
47
+ static propTypes = _props.propTypes;
48
+ static defaultProps = {};
44
49
  /* istanbul ignore next */
50
+
45
51
  render() {
46
52
  // this component is only used for prop validation. Select.Group children
47
53
  // are parsed in Select and rendered as Options components
@@ -51,10 +57,5 @@ class Group extends _react.Component {
51
57
  }
52
58
 
53
59
  exports.Group = Group;
54
- Group.displayName = "Group";
55
- Group.componentId = 'SimpleSelect.Group';
56
- Group.allowedProps = _props.allowedProps;
57
- Group.propTypes = _props.propTypes;
58
- Group.defaultProps = {};
59
60
  var _default = Group;
60
61
  exports.default = _default;
@@ -41,7 +41,15 @@ id: SimpleSelect.Option
41
41
  @tsProps
42
42
  **/
43
43
  class Option extends _react.Component {
44
+ static displayName = "Option";
45
+ static componentId = 'SimpleSelect.Option';
46
+ static allowedProps = _props.allowedProps;
47
+ static propTypes = _props.propTypes;
48
+ static defaultProps = {
49
+ isDisabled: false
50
+ };
44
51
  /* istanbul ignore next */
52
+
45
53
  render() {
46
54
  // this component is only used for prop validation. SimpleSelect.Option children
47
55
  // are parsed in Select and rendered as Options.Item components
@@ -51,12 +59,5 @@ class Option extends _react.Component {
51
59
  }
52
60
 
53
61
  exports.Option = Option;
54
- Option.displayName = "Option";
55
- Option.componentId = 'SimpleSelect.Option';
56
- Option.allowedProps = _props.allowedProps;
57
- Option.propTypes = _props.propTypes;
58
- Option.defaultProps = {
59
- isDisabled: false
60
- };
61
62
  var _default = Option;
62
63
  exports.default = _default;