@instructure/ui-simple-select 8.14.1-snapshot.19 → 8.14.1-snapshot.28

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 (34) 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 +92 -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/index.d.ts +45 -61
  32. package/types/SimpleSelect/index.d.ts.map +1 -1
  33. package/types/SimpleSelect/props.d.ts +127 -16
  34. 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,28 @@ 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]
173
+ for (let i = 0; i < this.childrenArray.length; i++) {
174
+ const child = this.childrenArray[i]
183
175
  if (matchComponentTypes(child, [Option])) {
184
- match = child
176
+ match = child as OptionChild
185
177
  } else if (matchComponentTypes(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 = (
180
+ Children.toArray(
181
+ (child as GroupChild).props.children
182
+ ) as OptionChild[]
183
+ )[0]
189
184
  }
190
185
  if (match) {
191
186
  break
@@ -194,24 +189,21 @@ class SimpleSelect extends Component<SimpleSelectProps> {
194
189
  return match
195
190
  }
196
191
 
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
192
+ getOption: GetOption = (field, value) => {
193
+ let match: OptionChild | undefined
201
194
 
202
- for (let i = 0; i < children.length; ++i) {
203
- const child = children[i]
195
+ for (let i = 0; i < this.childrenArray.length; ++i) {
196
+ const child = this.childrenArray[i]
204
197
  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
206
- if (child.props[field] === value) {
207
- match = child
198
+ if ((child as OptionChild).props[field] === value) {
199
+ match = child as OptionChild
208
200
  }
209
201
  } 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)
202
+ const groupChildren = Children.toArray(
203
+ (child as GroupChild).props.children
204
+ ) as OptionChild[]
212
205
  for (let j = 0; j < groupChildren.length; ++j) {
213
206
  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
207
  if (groupChild.props[field] === value) {
216
208
  match = groupChild
217
209
  break
@@ -223,37 +215,36 @@ class SimpleSelect extends Component<SimpleSelectProps> {
223
215
  return match
224
216
  }
225
217
 
226
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'node' implicitly has an 'any' type.
227
- handleRef = (node) => {
218
+ handleRef = (node: Select) => {
228
219
  this.ref = node
229
220
  }
230
221
 
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)
222
+ handleBlur: SelectProps['onBlur'] = (event) => {
223
+ this.setState({ highlightedOptionId: undefined })
224
+ if (typeof this.props.onBlur === 'function') {
225
+ this.props.onBlur(event)
226
+ }
236
227
  }
237
228
 
238
229
  handleShowOptions: SelectProps['onRequestShowOptions'] = (event) => {
239
230
  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)
231
+ if (typeof this.props.onShowOptions === 'function') {
232
+ this.props.onShowOptions(event)
233
+ }
242
234
  }
243
235
 
244
236
  handleHideOptions: SelectProps['onRequestHideOptions'] = (event) => {
245
237
  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
238
  const option = this.getOption('id', state.selectedOptionId)
248
239
  return {
249
240
  isShowingOptions: false,
250
- highlightedOptionId: null,
251
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'props' does not exist on type '{}'.
241
+ highlightedOptionId: undefined,
252
242
  inputValue: option ? option.props.children : ''
253
243
  }
254
244
  })
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)
245
+ if (typeof this.props.onHideOptions === 'function') {
246
+ this.props.onHideOptions(event)
247
+ }
257
248
  }
258
249
 
259
250
  handleHighlightOption: SelectProps['onRequestHighlightOption'] = (
@@ -263,9 +254,7 @@ class SimpleSelect extends Component<SimpleSelectProps> {
263
254
  if (id === this._emptyOptionId) return
264
255
 
265
256
  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
257
+ const label = option?.props.children
269
258
  const inputValue = event.type === 'keydown' ? label : this.state.inputValue
270
259
 
271
260
  this.setState({
@@ -285,7 +274,6 @@ class SimpleSelect extends Component<SimpleSelectProps> {
285
274
  }
286
275
 
287
276
  const option = this.getOption('id', id)
288
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'props' does not exist on type '{}'.
289
277
  const value = option && option.props.value
290
278
 
291
279
  if (this.isControlled) {
@@ -294,28 +282,28 @@ class SimpleSelect extends Component<SimpleSelectProps> {
294
282
  this.setState((state) => ({
295
283
  isShowingOptions: false,
296
284
  selectedOptionId: id,
297
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'props' does not exist on type '{}'.
298
285
  inputValue: option ? option.props.children : state.inputValue
299
286
  }))
300
287
  }
301
288
  // 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 })
289
+ if (option && typeof this.props.onChange === 'function') {
290
+ this.props.onChange(event, { value, id })
291
+ }
304
292
  // 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)
293
+ if (typeof this.props.onHideOptions === 'function') {
294
+ this.props.onHideOptions(event)
295
+ }
307
296
  }
308
297
 
309
298
  renderChildren() {
310
- let children = Children.toArray(this.props.children)
311
- children = Children.map(children, (child) => {
299
+ const children = Children.map(this.childrenArray, (child) => {
312
300
  if (matchComponentTypes(child, [Option])) {
313
- return this.renderOption(child)
301
+ return this.renderOption(child as OptionChild)
314
302
  } else if (matchComponentTypes(child, [Group])) {
315
- return this.renderGroup(child)
303
+ return this.renderGroup(child as GroupChild)
316
304
  }
317
305
  return null
318
- }).filter((child) => !!child)
306
+ }).filter((child: any) => !!child)
319
307
 
320
308
  if (children.length === 0) {
321
309
  // no valid children, render empty option
@@ -334,11 +322,10 @@ class SimpleSelect extends Component<SimpleSelectProps> {
334
322
  >
335
323
  {callRenderProp(this.props.renderEmptyOption)}
336
324
  </Select.Option>
337
- )
325
+ ) as OptionChild
338
326
  }
339
327
 
340
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'option' implicitly has an 'any' type.
341
- renderOption(option) {
328
+ renderOption(option: OptionChild) {
342
329
  const {
343
330
  id,
344
331
  value,
@@ -349,12 +336,10 @@ class SimpleSelect extends Component<SimpleSelectProps> {
349
336
  } = option.props
350
337
 
351
338
  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
339
  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
340
  const isHighlighted = id === this.state.highlightedOptionId
356
341
 
357
- const getRenderLabel = (renderLabel: any) => {
342
+ const getRenderLabel = (renderLabel: RenderSimpleSelectOptionLabel) => {
358
343
  return typeof renderLabel === 'function'
359
344
  ? renderLabel.bind(null, {
360
345
  id,
@@ -371,9 +356,7 @@ class SimpleSelect extends Component<SimpleSelectProps> {
371
356
  id={id}
372
357
  value={value}
373
358
  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
359
  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
360
  isSelected={id === this.state.selectedOptionId}
378
361
  isDisabled={option.props.isDisabled}
379
362
  renderBeforeLabel={getRenderLabel(renderBeforeLabel)}
@@ -382,11 +365,10 @@ class SimpleSelect extends Component<SimpleSelectProps> {
382
365
  >
383
366
  {children}
384
367
  </Select.Option>
385
- )
368
+ ) as OptionChild
386
369
  }
387
370
 
388
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'group' implicitly has an 'any' type.
389
- renderGroup(group) {
371
+ renderGroup(group: GroupChild) {
390
372
  const { id, renderLabel, children, ...rest } = group.props
391
373
  return (
392
374
  <Select.Group
@@ -394,9 +376,11 @@ class SimpleSelect extends Component<SimpleSelectProps> {
394
376
  key={group.key || id}
395
377
  {...passthroughProps(rest)}
396
378
  >
397
- {Children.map(children, (child) => this.renderOption(child))}
379
+ {Children.map(children as OptionChild[], (child) =>
380
+ this.renderOption(child)
381
+ )}
398
382
  </Select.Group>
399
- )
383
+ ) as GroupChild
400
384
  }
401
385
 
402
386
  render() {
@@ -434,9 +418,7 @@ class SimpleSelect extends Component<SimpleSelectProps> {
434
418
  return (
435
419
  <Select
436
420
  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
421
  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
422
  isShowingOptions={this.state.isShowingOptions}
441
423
  id={id}
442
424
  size={size}
@@ -465,8 +447,7 @@ class SimpleSelect extends Component<SimpleSelectProps> {
465
447
  onRequestSelectOption={this.handleSelectOption}
466
448
  {...passthroughProps(rest)}
467
449
  >
468
- {/* @ts-expect-error ts-migrate(2554) FIXME: Expected 0 arguments, but got 1. */}
469
- {this.renderChildren(children)}
450
+ {this.renderChildren()}
470
451
  </Select>
471
452
  )
472
453
  }