@instructure/ui-select 8.14.1-snapshot.63 → 8.14.1-snapshot.66

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.
@@ -48,6 +48,7 @@ import generateComponentTheme from './theme';
48
48
  import { Group } from './Group';
49
49
  import { Option } from './Option';
50
50
  import { allowedProps, propTypes } from './props';
51
+
51
52
  /**
52
53
  ---
53
54
  category: components
@@ -55,7 +56,6 @@ tags: autocomplete, typeahead, combobox, dropdown, search, form
55
56
  ---
56
57
  @tsProps
57
58
  **/
58
-
59
59
  let Select = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = testable(), _dec(_class = _dec2(_class = (_temp = _class2 = class Select extends Component {
60
60
  constructor() {
61
61
  super(...arguments);
@@ -120,6 +120,14 @@ let Select = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = t
120
120
  return this.ref;
121
121
  }
122
122
 
123
+ get childrenArray() {
124
+ return Children.toArray(this.props.children);
125
+ }
126
+
127
+ getGroupChildrenArray(group) {
128
+ return Children.toArray(group.props.children);
129
+ }
130
+
123
131
  get focused() {
124
132
  return this.ref ? isActiveElement(this.ref) : false;
125
133
  }
@@ -140,11 +148,10 @@ let Select = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = t
140
148
 
141
149
  get highlightedOptionId() {
142
150
  let highlightedOptionId;
143
- Children.toArray(this.props.children).forEach(child => {
151
+ this.childrenArray.forEach(child => {
144
152
  if (matchComponentTypes(child, [Group])) {
145
153
  // group found
146
- ;
147
- Children.toArray(child.props.children).forEach(option => {
154
+ this.getGroupChildrenArray(child).forEach(option => {
148
155
  // check options in group
149
156
  if (option.props.isHighlighted) {
150
157
  highlightedOptionId = option.props.id;
@@ -162,11 +169,10 @@ let Select = (_dec = withStyle(generateStyle, generateComponentTheme), _dec2 = t
162
169
 
163
170
  get selectedOptionId() {
164
171
  const selectedOptionId = [];
165
- Children.toArray(this.props.children).forEach(child => {
172
+ this.childrenArray.forEach(child => {
166
173
  if (matchComponentTypes(child, [Group])) {
167
174
  // group found
168
- ;
169
- Children.toArray(child.props.children).forEach(option => {
175
+ this.getGroupChildrenArray(child).forEach(option => {
170
176
  // check options in group
171
177
  if (option.props.isSelected) {
172
178
  selectedOptionId.push(option.props.id);
@@ -132,6 +132,14 @@ let Select = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _
132
132
  return this.ref;
133
133
  }
134
134
 
135
+ get childrenArray() {
136
+ return _react.Children.toArray(this.props.children);
137
+ }
138
+
139
+ getGroupChildrenArray(group) {
140
+ return _react.Children.toArray(group.props.children);
141
+ }
142
+
135
143
  get focused() {
136
144
  return this.ref ? (0, _isActiveElement.isActiveElement)(this.ref) : false;
137
145
  }
@@ -152,13 +160,10 @@ let Select = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _
152
160
 
153
161
  get highlightedOptionId() {
154
162
  let highlightedOptionId;
155
-
156
- _react.Children.toArray(this.props.children).forEach(child => {
163
+ this.childrenArray.forEach(child => {
157
164
  if ((0, _matchComponentTypes.matchComponentTypes)(child, [_Group.Group])) {
158
165
  // group found
159
- ;
160
-
161
- _react.Children.toArray(child.props.children).forEach(option => {
166
+ this.getGroupChildrenArray(child).forEach(option => {
162
167
  // check options in group
163
168
  if (option.props.isHighlighted) {
164
169
  highlightedOptionId = option.props.id;
@@ -171,19 +176,15 @@ let Select = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _
171
176
  }
172
177
  }
173
178
  });
174
-
175
179
  return highlightedOptionId;
176
180
  }
177
181
 
178
182
  get selectedOptionId() {
179
183
  const selectedOptionId = [];
180
-
181
- _react.Children.toArray(this.props.children).forEach(child => {
184
+ this.childrenArray.forEach(child => {
182
185
  if ((0, _matchComponentTypes.matchComponentTypes)(child, [_Group.Group])) {
183
186
  // group found
184
- ;
185
-
186
- _react.Children.toArray(child.props.children).forEach(option => {
187
+ this.getGroupChildrenArray(child).forEach(option => {
187
188
  // check options in group
188
189
  if (option.props.isSelected) {
189
190
  selectedOptionId.push(option.props.id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-select",
3
- "version": "8.14.1-snapshot.63+2acf47d5b",
3
+ "version": "8.14.1-snapshot.66+ff0decd44",
4
4
  "description": "A component for select and autocomplete behavior.",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "type": "commonjs",
@@ -24,30 +24,30 @@
24
24
  },
25
25
  "license": "MIT",
26
26
  "devDependencies": {
27
- "@instructure/ui-babel-preset": "8.14.1-snapshot.63+2acf47d5b",
28
- "@instructure/ui-color-utils": "8.14.1-snapshot.63+2acf47d5b",
29
- "@instructure/ui-test-locator": "8.14.1-snapshot.63+2acf47d5b",
30
- "@instructure/ui-test-utils": "8.14.1-snapshot.63+2acf47d5b",
31
- "@instructure/ui-themes": "8.14.1-snapshot.63+2acf47d5b"
27
+ "@instructure/ui-babel-preset": "8.14.1-snapshot.66+ff0decd44",
28
+ "@instructure/ui-color-utils": "8.14.1-snapshot.66+ff0decd44",
29
+ "@instructure/ui-test-locator": "8.14.1-snapshot.66+ff0decd44",
30
+ "@instructure/ui-test-utils": "8.14.1-snapshot.66+ff0decd44",
31
+ "@instructure/ui-themes": "8.14.1-snapshot.66+ff0decd44"
32
32
  },
33
33
  "dependencies": {
34
34
  "@babel/runtime": "^7.13.10",
35
- "@instructure/emotion": "8.14.1-snapshot.63+2acf47d5b",
36
- "@instructure/shared-types": "8.14.1-snapshot.63+2acf47d5b",
37
- "@instructure/ui-dom-utils": "8.14.1-snapshot.63+2acf47d5b",
38
- "@instructure/ui-form-field": "8.14.1-snapshot.63+2acf47d5b",
39
- "@instructure/ui-icons": "8.14.1-snapshot.63+2acf47d5b",
40
- "@instructure/ui-options": "8.14.1-snapshot.63+2acf47d5b",
41
- "@instructure/ui-popover": "8.14.1-snapshot.63+2acf47d5b",
42
- "@instructure/ui-position": "8.14.1-snapshot.63+2acf47d5b",
43
- "@instructure/ui-prop-types": "8.14.1-snapshot.63+2acf47d5b",
44
- "@instructure/ui-react-utils": "8.14.1-snapshot.63+2acf47d5b",
45
- "@instructure/ui-selectable": "8.14.1-snapshot.63+2acf47d5b",
46
- "@instructure/ui-testable": "8.14.1-snapshot.63+2acf47d5b",
47
- "@instructure/ui-text-input": "8.14.1-snapshot.63+2acf47d5b",
48
- "@instructure/ui-utils": "8.14.1-snapshot.63+2acf47d5b",
49
- "@instructure/ui-view": "8.14.1-snapshot.63+2acf47d5b",
50
- "@instructure/uid": "8.14.1-snapshot.63+2acf47d5b",
35
+ "@instructure/emotion": "8.14.1-snapshot.66+ff0decd44",
36
+ "@instructure/shared-types": "8.14.1-snapshot.66+ff0decd44",
37
+ "@instructure/ui-dom-utils": "8.14.1-snapshot.66+ff0decd44",
38
+ "@instructure/ui-form-field": "8.14.1-snapshot.66+ff0decd44",
39
+ "@instructure/ui-icons": "8.14.1-snapshot.66+ff0decd44",
40
+ "@instructure/ui-options": "8.14.1-snapshot.66+ff0decd44",
41
+ "@instructure/ui-popover": "8.14.1-snapshot.66+ff0decd44",
42
+ "@instructure/ui-position": "8.14.1-snapshot.66+ff0decd44",
43
+ "@instructure/ui-prop-types": "8.14.1-snapshot.66+ff0decd44",
44
+ "@instructure/ui-react-utils": "8.14.1-snapshot.66+ff0decd44",
45
+ "@instructure/ui-selectable": "8.14.1-snapshot.66+ff0decd44",
46
+ "@instructure/ui-testable": "8.14.1-snapshot.66+ff0decd44",
47
+ "@instructure/ui-text-input": "8.14.1-snapshot.66+ff0decd44",
48
+ "@instructure/ui-utils": "8.14.1-snapshot.66+ff0decd44",
49
+ "@instructure/ui-view": "8.14.1-snapshot.66+ff0decd44",
50
+ "@instructure/uid": "8.14.1-snapshot.66+ff0decd44",
51
51
  "prop-types": "^15"
52
52
  },
53
53
  "peerDependencies": {
@@ -57,5 +57,5 @@
57
57
  "access": "public"
58
58
  },
59
59
  "sideEffects": false,
60
- "gitHead": "2acf47d5bc73bd07f4f5228bdc7654a3df997d3e"
60
+ "gitHead": "ff0decd44fd390bd7f50885610373d2c9c793053"
61
61
  }
@@ -65,13 +65,19 @@ import generateStyle from './styles'
65
65
  import generateComponentTheme from './theme'
66
66
 
67
67
  import { Group } from './Group'
68
+ import type { SelectGroupProps } from './Group/props'
68
69
  import { Option } from './Option'
70
+ import type { SelectOptionProps } from './Option/props'
69
71
 
70
72
  import type { RenderSelectOptionLabel } from './Option/props'
71
73
 
72
74
  import type { SelectProps } from './props'
73
75
  import { allowedProps, propTypes } from './props'
74
76
 
77
+ type GroupChild = React.ComponentElement<SelectGroupProps, Group>
78
+ type OptionChild = React.ComponentElement<SelectOptionProps, Option>
79
+ type SelectChildren = (GroupChild | OptionChild)[]
80
+
75
81
  /**
76
82
  ---
77
83
  category: components
@@ -141,6 +147,14 @@ class Select extends Component<SelectProps> {
141
147
  return this.ref
142
148
  }
143
149
 
150
+ get childrenArray() {
151
+ return Children.toArray(this.props.children) as SelectChildren
152
+ }
153
+
154
+ getGroupChildrenArray(group: GroupChild) {
155
+ return Children.toArray(group.props.children) as OptionChild[]
156
+ }
157
+
144
158
  get focused() {
145
159
  return this.ref ? isActiveElement(this.ref) : false
146
160
  }
@@ -160,12 +174,10 @@ class Select extends Component<SelectProps> {
160
174
  get highlightedOptionId(): string | undefined {
161
175
  let highlightedOptionId: string | undefined
162
176
 
163
- Children.toArray(this.props.children).forEach((child) => {
164
- if (matchComponentTypes(child, [Group])) {
177
+ this.childrenArray.forEach((child) => {
178
+ if (matchComponentTypes<GroupChild>(child, [Group])) {
165
179
  // group found
166
- ;(
167
- Children.toArray((child as Group).props.children) as Option[]
168
- ).forEach((option) => {
180
+ this.getGroupChildrenArray(child).forEach((option) => {
169
181
  // check options in group
170
182
  if (option.props.isHighlighted) {
171
183
  highlightedOptionId = option.props.id
@@ -173,8 +185,8 @@ class Select extends Component<SelectProps> {
173
185
  })
174
186
  } else {
175
187
  // ungrouped option found
176
- if ((child as Option).props.isHighlighted) {
177
- highlightedOptionId = (child as Option).props.id
188
+ if (child.props.isHighlighted) {
189
+ highlightedOptionId = child.props.id
178
190
  }
179
191
  }
180
192
  })
@@ -185,12 +197,10 @@ class Select extends Component<SelectProps> {
185
197
  get selectedOptionId() {
186
198
  const selectedOptionId: string[] = []
187
199
 
188
- Children.toArray(this.props.children).forEach((child) => {
189
- if (matchComponentTypes(child, [Group])) {
200
+ this.childrenArray.forEach((child) => {
201
+ if (matchComponentTypes<GroupChild>(child, [Group])) {
190
202
  // group found
191
- ;(
192
- Children.toArray((child as Group).props.children) as Option[]
193
- ).forEach((option) => {
203
+ this.getGroupChildrenArray(child).forEach((option) => {
194
204
  // check options in group
195
205
  if (option.props.isSelected) {
196
206
  selectedOptionId.push(option.props.id)
@@ -198,8 +208,8 @@ class Select extends Component<SelectProps> {
198
208
  })
199
209
  } else {
200
210
  // ungrouped option found
201
- if ((child as Option).props.isSelected) {
202
- selectedOptionId.push((child as Option).props.id)
211
+ if (child.props.isSelected) {
212
+ selectedOptionId.push(child.props.id)
203
213
  }
204
214
  }
205
215
  })
@@ -331,7 +341,7 @@ class Select extends Component<SelectProps> {
331
341
  }
332
342
 
333
343
  renderOption(
334
- option: Option,
344
+ option: OptionChild,
335
345
  data: Pick<SelectableRender, 'getOptionProps' | 'getDisabledOptionProps'>
336
346
  ) {
337
347
  const { getOptionProps, getDisabledOptionProps } = data
@@ -390,7 +400,7 @@ class Select extends Component<SelectProps> {
390
400
  }
391
401
 
392
402
  renderGroup(
393
- group: Group,
403
+ group: GroupChild,
394
404
  data: Pick<
395
405
  SelectableRender,
396
406
  'getOptionProps' | 'getDisabledOptionProps'
@@ -426,7 +436,7 @@ class Select extends Component<SelectProps> {
426
436
  renderLabel={renderLabel}
427
437
  {...omitProps(rest, [...Options.allowedProps, ...Group.allowedProps])}
428
438
  >
429
- {Children.map(children as Option[], (child) => {
439
+ {Children.map(children as OptionChild[], (child) => {
430
440
  return this.renderOption(child, {
431
441
  getOptionProps,
432
442
  getDisabledOptionProps
@@ -471,21 +481,21 @@ class Select extends Component<SelectProps> {
471
481
  {...getListProps({ as: 'ul', elementRef: this.handleListRef })}
472
482
  >
473
483
  {isShowingOptions
474
- ? Children.map(children, (child, index) => {
484
+ ? Children.map(children as SelectChildren, (child, index) => {
475
485
  if (!child || !matchComponentTypes(child, [Group, Option])) {
476
486
  return // ignore invalid children
477
487
  }
478
- if (matchComponentTypes(child, [Option])) {
488
+ if (matchComponentTypes<OptionChild>(child, [Option])) {
479
489
  lastWasGroup = false
480
- return this.renderOption(child as Option, {
490
+ return this.renderOption(child, {
481
491
  getOptionProps,
482
492
  getDisabledOptionProps
483
493
  })
484
494
  }
485
- if (matchComponentTypes(child, [Group])) {
495
+ if (matchComponentTypes<GroupChild>(child, [Group])) {
486
496
  const afterGroup = lastWasGroup
487
497
  lastWasGroup = true
488
- return this.renderGroup(child as Group, {
498
+ return this.renderGroup(child, {
489
499
  getOptionProps,
490
500
  getDisabledOptionProps,
491
501
  // for rendering separators appropriately