@instructure/ui-simple-select 8.14.1-snapshot.7 → 8.14.1-snapshot.70

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 (35) hide show
  1. package/es/SimpleSelect/Group/index.js +2 -3
  2. package/es/SimpleSelect/Group/props.js +0 -7
  3. package/es/SimpleSelect/Option/index.js +2 -2
  4. package/es/SimpleSelect/Option/props.js +0 -23
  5. package/es/SimpleSelect/SimpleSelectLocator.js +3 -1
  6. package/es/SimpleSelect/index.js +74 -68
  7. package/es/SimpleSelect/props.js +0 -130
  8. package/lib/SimpleSelect/Group/index.js +2 -3
  9. package/lib/SimpleSelect/Group/props.js +0 -7
  10. package/lib/SimpleSelect/Option/index.js +2 -2
  11. package/lib/SimpleSelect/Option/props.js +0 -23
  12. package/lib/SimpleSelect/SimpleSelectLocator.js +2 -0
  13. package/lib/SimpleSelect/index.js +73 -70
  14. package/lib/SimpleSelect/props.js +0 -130
  15. package/package.json +15 -15
  16. package/src/SimpleSelect/Group/index.tsx +3 -4
  17. package/src/SimpleSelect/Group/props.ts +10 -8
  18. package/src/SimpleSelect/Option/index.tsx +2 -2
  19. package/src/SimpleSelect/Option/props.ts +35 -21
  20. package/src/SimpleSelect/index.tsx +88 -111
  21. package/src/SimpleSelect/props.ts +147 -94
  22. package/tsconfig.build.tsbuildinfo +1 -1
  23. package/types/SimpleSelect/Group/index.d.ts +4 -5
  24. package/types/SimpleSelect/Group/index.d.ts.map +1 -1
  25. package/types/SimpleSelect/Group/props.d.ts +7 -1
  26. package/types/SimpleSelect/Group/props.d.ts.map +1 -1
  27. package/types/SimpleSelect/Option/index.d.ts +7 -7
  28. package/types/SimpleSelect/Option/index.d.ts.map +1 -1
  29. package/types/SimpleSelect/Option/props.d.ts +30 -4
  30. package/types/SimpleSelect/Option/props.d.ts.map +1 -1
  31. package/types/SimpleSelect/SimpleSelectLocator.d.ts +4 -4
  32. package/types/SimpleSelect/index.d.ts +45 -61
  33. package/types/SimpleSelect/index.d.ts.map +1 -1
  34. package/types/SimpleSelect/props.d.ts +127 -16
  35. package/types/SimpleSelect/props.d.ts.map +1 -1
@@ -32,24 +32,39 @@ import {
32
32
  getInteraction
33
33
  } from '@instructure/ui-react-utils'
34
34
  import { uid } from '@instructure/uid'
35
- import { Select } from '@instructure/ui-select'
36
35
 
36
+ import { Select } from '@instructure/ui-select'
37
37
  import type { SelectProps } from '@instructure/ui-select'
38
38
 
39
39
  import { Option } from './Option'
40
+ import type {
41
+ SimpleSelectOptionProps,
42
+ RenderSimpleSelectOptionLabel
43
+ } from './Option/props'
44
+
40
45
  import { Group } from './Group'
46
+ import type { SimpleSelectGroupProps } from './Group/props'
41
47
 
42
48
  import type { SimpleSelectProps } from './props'
43
- import { allowedProps, propTypes } from './props'
49
+ import { allowedProps, propTypes, SimpleSelectState } from './props'
50
+
51
+ type OptionChild = React.ComponentElement<SimpleSelectOptionProps, Option>
52
+ type GroupChild = React.ComponentElement<SimpleSelectGroupProps, Group>
53
+
54
+ type GetOption = <F extends 'id' | 'value'>(
55
+ field: F,
56
+ value?: SimpleSelectOptionProps[F]
57
+ ) => OptionChild | undefined
44
58
 
45
59
  /**
46
60
  ---
47
61
  category: components
48
62
  tags: form, field, dropdown
49
63
  ---
64
+ @tsProps
50
65
  **/
51
66
  @testable()
52
- class SimpleSelect extends Component<SimpleSelectProps> {
67
+ class SimpleSelect extends Component<SimpleSelectProps, SimpleSelectState> {
53
68
  static readonly componentId = 'SimpleSelect'
54
69
 
55
70
  static Option = Option
@@ -60,51 +75,32 @@ class SimpleSelect extends Component<SimpleSelectProps> {
60
75
 
61
76
  static defaultProps = {
62
77
  size: 'medium',
63
- placeholder: null,
64
78
  isRequired: false,
65
79
  isInline: false,
66
80
  visibleOptionsCount: 8,
67
81
  placement: 'bottom stretch',
68
82
  constrain: 'window',
69
- // @ts-expect-error ts-migrate(6133) FIXME: 'event' is declared but its value is never read.
70
- onChange: (event, data) => {},
71
- // @ts-expect-error ts-migrate(6133) FIXME: 'event' is declared but its value is never read.
72
- onFocus: (event) => {},
73
- // @ts-expect-error ts-migrate(6133) FIXME: 'event' is declared but its value is never read.
74
- onBlur: (event) => {},
75
- // @ts-expect-error ts-migrate(6133) FIXME: 'event' is declared but its value is never read.
76
- onShowOptions: (event) => {},
77
- // @ts-expect-error ts-migrate(6133) FIXME: 'event' is declared but its value is never read.
78
- onHideOptions: (event) => {},
79
- // @ts-expect-error ts-migrate(6133) FIXME: 'node' is declared but its value is never read.
80
- inputRef: (node) => {},
81
- // @ts-expect-error ts-migrate(6133) FIXME: 'node' is declared but its value is never read.
82
- listRef: (node) => {},
83
- renderEmptyOption: '---',
84
- renderBeforeInput: null,
85
- renderAfterInput: null,
86
- children: null
83
+ renderEmptyOption: '---'
87
84
  }
88
85
 
89
- ref: Element | null = null
86
+ ref: Select | null = null
90
87
 
91
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'props' implicitly has an 'any' type.
92
- constructor(props) {
88
+ private readonly _emptyOptionId
89
+
90
+ constructor(props: SimpleSelectProps) {
93
91
  super(props)
94
92
 
95
93
  const option = this.getInitialOption(props)
96
94
 
97
95
  this.state = {
98
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'props' does not exist on type '{}'.
99
96
  inputValue: option ? option.props.children : '',
100
97
  isShowingOptions: false,
101
- highlightedOptionId: null,
102
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'props' does not exist on type '{}'.
103
- selectedOptionId: option ? option.props.id : null
98
+ highlightedOptionId: undefined,
99
+ selectedOptionId: option ? option.props.id : undefined
104
100
  }
105
- }
106
101
 
107
- _emptyOptionId = uid('Select-EmptyOption')
102
+ this._emptyOptionId = uid('Select-EmptyOption')
103
+ }
108
104
 
109
105
  get _select() {
110
106
  console.warn(
@@ -114,18 +110,22 @@ class SimpleSelect extends Component<SimpleSelectProps> {
114
110
  return this.ref
115
111
  }
116
112
 
113
+ get childrenArray() {
114
+ return Children.toArray(this.props.children) as Array<
115
+ OptionChild | GroupChild
116
+ >
117
+ }
118
+
117
119
  focus() {
118
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'ref' does not exist on type 'SimpleS... Remove this comment to see the full error message
119
120
  this.ref && this.ref.focus()
120
121
  }
121
122
 
122
123
  get focused() {
123
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'ref' does not exist on type 'SimpleS... Remove this comment to see the full error message
124
- return this.ref && this.ref.focused
124
+ return this.ref ? this.ref.focused : false
125
125
  }
126
126
 
127
127
  get id() {
128
- return this.ref && this.ref.id
128
+ return this.ref ? this.ref.id : undefined
129
129
  }
130
130
 
131
131
  get isControlled() {
@@ -136,8 +136,7 @@ class SimpleSelect extends Component<SimpleSelectProps> {
136
136
  return getInteraction({ props: this.props })
137
137
  }
138
138
 
139
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'prevProps' implicitly has an 'any' type... Remove this comment to see the full error message
140
- componentDidUpdate(prevProps) {
139
+ componentDidUpdate(prevProps: SimpleSelectProps) {
141
140
  if (this.props.value !== prevProps.value) {
142
141
  let option = this.getOption('value', this.props.value)
143
142
  if (typeof this.props.value === 'undefined') {
@@ -145,16 +144,13 @@ class SimpleSelect extends Component<SimpleSelectProps> {
145
144
  option = this.getOption('value', prevProps.value)
146
145
  }
147
146
  this.setState({
148
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'props' does not exist on type '{}'.
149
147
  inputValue: option ? option.props.children : '',
150
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'props' does not exist on type '{}'.
151
148
  selectedOptionId: option ? option.props.id : ''
152
149
  })
153
150
  }
154
151
  }
155
152
 
156
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'props' implicitly has an 'any' type.
157
- getInitialOption(props) {
153
+ getInitialOption(props: SimpleSelectProps) {
158
154
  const { value, defaultValue } = props
159
155
  const initialValue = value || defaultValue
160
156
 
@@ -163,29 +159,24 @@ class SimpleSelect extends Component<SimpleSelectProps> {
163
159
  return this.getOption('value', initialValue)
164
160
  }
165
161
  // otherwise get the first option
166
- return this.getOptionByIndex(0)
162
+ return this.getFirstOption()
167
163
  }
168
164
 
169
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'id' implicitly has an 'any' type.
170
- getOptionLabelById(id) {
165
+ getOptionLabelById(id: string) {
171
166
  const option = this.getOption('id', id)
172
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'props' does not exist on type '{}'.
173
167
  return option ? option.props.children : ''
174
168
  }
175
169
 
176
- // @ts-expect-error ts-migrate(6133) FIXME: 'index' is declared but its value is never read.
177
- getOptionByIndex(index) {
178
- const children = Children.toArray(this.props.children)
179
- let match = null
170
+ getFirstOption() {
171
+ let match: OptionChild | undefined
180
172
 
181
- for (let i = 0; i < children.length; i++) {
182
- const child = children[i]
183
- if (matchComponentTypes(child, [Option])) {
173
+ for (let i = 0; i < this.childrenArray.length; i++) {
174
+ const child = this.childrenArray[i]
175
+ if (matchComponentTypes<OptionChild>(child, [Option])) {
184
176
  match = child
185
- } else if (matchComponentTypes(child, [Group])) {
177
+ } else if (matchComponentTypes<GroupChild>(child, [Group])) {
186
178
  // first child is a group, not an option, find first child in group
187
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'props' does not exist on type 'string | ... Remove this comment to see the full error message
188
- match = Children.toArray(child.props.children)[0]
179
+ match = (Children.toArray(child.props.children) as OptionChild[])[0]
189
180
  }
190
181
  if (match) {
191
182
  break
@@ -194,24 +185,21 @@ class SimpleSelect extends Component<SimpleSelectProps> {
194
185
  return match
195
186
  }
196
187
 
197
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'field' implicitly has an 'any' type.
198
- getOption(field, value) {
199
- const children = Children.toArray(this.props.children)
200
- let match = null
188
+ getOption: GetOption = (field, value) => {
189
+ let match: OptionChild | undefined
201
190
 
202
- for (let i = 0; i < children.length; ++i) {
203
- const child = children[i]
204
- if (matchComponentTypes(child, [Option])) {
205
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'props' does not exist on type 'string | ... Remove this comment to see the full error message
191
+ for (let i = 0; i < this.childrenArray.length; ++i) {
192
+ const child = this.childrenArray[i]
193
+ if (matchComponentTypes<OptionChild>(child, [Option])) {
206
194
  if (child.props[field] === value) {
207
195
  match = child
208
196
  }
209
- } else if (matchComponentTypes(child, [Group])) {
210
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'props' does not exist on type 'string | ... Remove this comment to see the full error message
211
- const groupChildren = Children.toArray(child.props.children)
197
+ } else if (matchComponentTypes<GroupChild>(child, [Group])) {
198
+ const groupChildren = Children.toArray(
199
+ child.props.children
200
+ ) as OptionChild[]
212
201
  for (let j = 0; j < groupChildren.length; ++j) {
213
202
  const groupChild = groupChildren[j]
214
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'props' does not exist on type 'string | ... Remove this comment to see the full error message
215
203
  if (groupChild.props[field] === value) {
216
204
  match = groupChild
217
205
  break
@@ -223,37 +211,36 @@ class SimpleSelect extends Component<SimpleSelectProps> {
223
211
  return match
224
212
  }
225
213
 
226
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'node' implicitly has an 'any' type.
227
- handleRef = (node) => {
214
+ handleRef = (node: Select) => {
228
215
  this.ref = node
229
216
  }
230
217
 
231
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'event' implicitly has an 'any' type.
232
- handleBlur = (event) => {
233
- this.setState({ highlightedOptionId: null })
234
- // @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
235
- this.props.onBlur(event)
218
+ handleBlur: SelectProps['onBlur'] = (event) => {
219
+ this.setState({ highlightedOptionId: undefined })
220
+ if (typeof this.props.onBlur === 'function') {
221
+ this.props.onBlur(event)
222
+ }
236
223
  }
237
224
 
238
225
  handleShowOptions: SelectProps['onRequestShowOptions'] = (event) => {
239
226
  this.setState({ isShowingOptions: true })
240
- // @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
241
- this.props.onShowOptions(event)
227
+ if (typeof this.props.onShowOptions === 'function') {
228
+ this.props.onShowOptions(event)
229
+ }
242
230
  }
243
231
 
244
232
  handleHideOptions: SelectProps['onRequestHideOptions'] = (event) => {
245
233
  this.setState((state) => {
246
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'selectedOptionId' does not exist on type... Remove this comment to see the full error message
247
234
  const option = this.getOption('id', state.selectedOptionId)
248
235
  return {
249
236
  isShowingOptions: false,
250
- highlightedOptionId: null,
251
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'props' does not exist on type '{}'.
237
+ highlightedOptionId: undefined,
252
238
  inputValue: option ? option.props.children : ''
253
239
  }
254
240
  })
255
- // @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
256
- this.props.onHideOptions(event)
241
+ if (typeof this.props.onHideOptions === 'function') {
242
+ this.props.onHideOptions(event)
243
+ }
257
244
  }
258
245
 
259
246
  handleHighlightOption: SelectProps['onRequestHighlightOption'] = (
@@ -263,9 +250,7 @@ class SimpleSelect extends Component<SimpleSelectProps> {
263
250
  if (id === this._emptyOptionId) return
264
251
 
265
252
  const option = this.getOption('id', id)
266
- // @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
267
- const label = option.props.children
268
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'inputValue' does not exist on type 'Read... Remove this comment to see the full error message
253
+ const label = option?.props.children
269
254
  const inputValue = event.type === 'keydown' ? label : this.state.inputValue
270
255
 
271
256
  this.setState({
@@ -285,7 +270,6 @@ class SimpleSelect extends Component<SimpleSelectProps> {
285
270
  }
286
271
 
287
272
  const option = this.getOption('id', id)
288
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'props' does not exist on type '{}'.
289
273
  const value = option && option.props.value
290
274
 
291
275
  if (this.isControlled) {
@@ -294,24 +278,24 @@ class SimpleSelect extends Component<SimpleSelectProps> {
294
278
  this.setState((state) => ({
295
279
  isShowingOptions: false,
296
280
  selectedOptionId: id,
297
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'props' does not exist on type '{}'.
298
281
  inputValue: option ? option.props.children : state.inputValue
299
282
  }))
300
283
  }
301
284
  // fire onChange if selected option changed
302
- // @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
303
- option && this.props.onChange(event, { value, id })
285
+ if (option && typeof this.props.onChange === 'function') {
286
+ this.props.onChange(event, { value, id })
287
+ }
304
288
  // hide options list whenever selection is made
305
- // @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
306
- this.props.onHideOptions(event)
289
+ if (typeof this.props.onHideOptions === 'function') {
290
+ this.props.onHideOptions(event)
291
+ }
307
292
  }
308
293
 
309
294
  renderChildren() {
310
- let children = Children.toArray(this.props.children)
311
- children = Children.map(children, (child) => {
312
- if (matchComponentTypes(child, [Option])) {
295
+ const children = Children.map(this.childrenArray, (child) => {
296
+ if (matchComponentTypes<OptionChild>(child, [Option])) {
313
297
  return this.renderOption(child)
314
- } else if (matchComponentTypes(child, [Group])) {
298
+ } else if (matchComponentTypes<GroupChild>(child, [Group])) {
315
299
  return this.renderGroup(child)
316
300
  }
317
301
  return null
@@ -334,11 +318,10 @@ class SimpleSelect extends Component<SimpleSelectProps> {
334
318
  >
335
319
  {callRenderProp(this.props.renderEmptyOption)}
336
320
  </Select.Option>
337
- )
321
+ ) as OptionChild
338
322
  }
339
323
 
340
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'option' implicitly has an 'any' type.
341
- renderOption(option) {
324
+ renderOption(option: OptionChild) {
342
325
  const {
343
326
  id,
344
327
  value,
@@ -349,12 +332,10 @@ class SimpleSelect extends Component<SimpleSelectProps> {
349
332
  } = option.props
350
333
 
351
334
  const isDisabled = option.props.isDisabled
352
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'highlightedOptionId' does not exist on t... Remove this comment to see the full error message
353
335
  const isSelected = id === this.state.selectedOptionId
354
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'highlightedOptionId' does not exist on t... Remove this comment to see the full error message
355
336
  const isHighlighted = id === this.state.highlightedOptionId
356
337
 
357
- const getRenderLabel = (renderLabel: any) => {
338
+ const getRenderLabel = (renderLabel: RenderSimpleSelectOptionLabel) => {
358
339
  return typeof renderLabel === 'function'
359
340
  ? renderLabel.bind(null, {
360
341
  id,
@@ -371,9 +352,7 @@ class SimpleSelect extends Component<SimpleSelectProps> {
371
352
  id={id}
372
353
  value={value}
373
354
  key={option.key || id}
374
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'highlightedOptionId' does not exist on t... Remove this comment to see the full error message
375
355
  isHighlighted={id === this.state.highlightedOptionId}
376
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'selectedOptionId' does not exist on type... Remove this comment to see the full error message
377
356
  isSelected={id === this.state.selectedOptionId}
378
357
  isDisabled={option.props.isDisabled}
379
358
  renderBeforeLabel={getRenderLabel(renderBeforeLabel)}
@@ -382,11 +361,10 @@ class SimpleSelect extends Component<SimpleSelectProps> {
382
361
  >
383
362
  {children}
384
363
  </Select.Option>
385
- )
364
+ ) as OptionChild
386
365
  }
387
366
 
388
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'group' implicitly has an 'any' type.
389
- renderGroup(group) {
367
+ renderGroup(group: GroupChild) {
390
368
  const { id, renderLabel, children, ...rest } = group.props
391
369
  return (
392
370
  <Select.Group
@@ -394,9 +372,11 @@ class SimpleSelect extends Component<SimpleSelectProps> {
394
372
  key={group.key || id}
395
373
  {...passthroughProps(rest)}
396
374
  >
397
- {Children.map(children, (child) => this.renderOption(child))}
375
+ {Children.map(children as OptionChild[], (child) =>
376
+ this.renderOption(child)
377
+ )}
398
378
  </Select.Group>
399
- )
379
+ ) as GroupChild
400
380
  }
401
381
 
402
382
  render() {
@@ -434,9 +414,7 @@ class SimpleSelect extends Component<SimpleSelectProps> {
434
414
  return (
435
415
  <Select
436
416
  renderLabel={renderLabel}
437
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'inputValue' does not exist on type 'Read... Remove this comment to see the full error message
438
417
  inputValue={this.state.inputValue}
439
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'isShowingOptions' does not exist on type... Remove this comment to see the full error message
440
418
  isShowingOptions={this.state.isShowingOptions}
441
419
  id={id}
442
420
  size={size}
@@ -465,8 +443,7 @@ class SimpleSelect extends Component<SimpleSelectProps> {
465
443
  onRequestSelectOption={this.handleSelectOption}
466
444
  {...passthroughProps(rest)}
467
445
  >
468
- {/* @ts-expect-error ts-migrate(2554) FIXME: Expected 0 arguments, but got 1. */}
469
- {this.renderChildren(children)}
446
+ {this.renderChildren()}
470
447
  </Select>
471
448
  )
472
449
  }