@instructure/ui-popover 8.12.1-snapshot.51 → 8.13.0

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.
@@ -39,16 +39,20 @@ import {
39
39
  requestAnimationFrame,
40
40
  handleMouseOverOut
41
41
  } from '@instructure/ui-dom-utils'
42
- import type { RequestAnimationFrameType } from '@instructure/ui-dom-utils'
43
42
 
44
43
  import { safeCloneElement, callRenderProp } from '@instructure/ui-react-utils'
45
44
  import { createChainedFunction, shallowEqual, px } from '@instructure/ui-utils'
46
45
  import { logError as error } from '@instructure/console'
47
46
  import { uid } from '@instructure/uid'
48
47
  import { testable } from '@instructure/ui-testable'
49
-
50
48
  import { FocusRegion } from '@instructure/ui-a11y-utils'
51
- import type { PopoverProps } from './props'
49
+
50
+ import type { RequestAnimationFrameType } from '@instructure/ui-dom-utils'
51
+ import type { ViewProps, ContextViewProps } from '@instructure/ui-view'
52
+ import type { PositionProps } from '@instructure/ui-position'
53
+ import type { DialogProps } from '@instructure/ui-dialog'
54
+
55
+ import type { PopoverProps, PopoverState } from './props'
52
56
  import { allowedProps, propTypes } from './props'
53
57
 
54
58
  /**
@@ -56,10 +60,11 @@ import { allowedProps, propTypes } from './props'
56
60
  category: components
57
61
  tags: overlay, portal, dialog
58
62
  ---
63
+ @tsProps
59
64
  **/
60
65
  @textDirectionContextConsumer()
61
66
  @testable()
62
- class Popover extends Component<PopoverProps> {
67
+ class Popover extends Component<PopoverProps, PopoverState> {
63
68
  static readonly componentId = 'Popover'
64
69
 
65
70
  static allowedProps = allowedProps
@@ -74,8 +79,6 @@ class Popover extends Component<PopoverProps> {
74
79
  offsetY: 0,
75
80
  color: 'primary',
76
81
  on: ['hover', 'focus'],
77
- // @ts-expect-error ts-migrate(6133) FIXME: 'el' is declared but its value is never read.
78
- contentRef: (el) => {},
79
82
  withArrow: true,
80
83
  constrain: 'window',
81
84
  insertAt: 'bottom',
@@ -86,72 +89,49 @@ class Popover extends Component<PopoverProps> {
86
89
  shouldReturnFocus: true,
87
90
  shouldCloseOnDocumentClick: true,
88
91
  shouldFocusContentOnTriggerBlur: false,
89
- shouldCloseOnEscape: true,
90
- // @ts-expect-error ts-migrate(6133) FIXME: 'event' is declared but its value is never read.
91
- onShowContent: (event) => {},
92
- // @ts-expect-error ts-migrate(6133) FIXME: 'event' is declared but its value is never read.
93
- onHideContent: (event, { documentClick }) => {},
94
- // @ts-expect-error ts-migrate(6133) FIXME: 'event' is declared but its value is never read.
95
- onClick: (event) => {},
96
- // @ts-expect-error ts-migrate(6133) FIXME: 'event' is declared but its value is never read.
97
- onFocus: (event) => {},
98
- // @ts-expect-error ts-migrate(6133) FIXME: 'event' is declared but its value is never read.
99
- onBlur: (event) => {},
100
- // @ts-expect-error ts-migrate(6133) FIXME: 'event' is declared but its value is never read.
101
- onMouseOver: (event) => {},
102
- // @ts-expect-error ts-migrate(6133) FIXME: 'event' is declared but its value is never read.
103
- onMouseOut: (event) => {},
104
- // @ts-expect-error ts-migrate(6133) FIXME: 'event' is declared but its value is never read.
105
- onKeyDown: (event) => {},
106
- // @ts-expect-error ts-migrate(6133) FIXME: 'event' is declared but its value is never read.
107
- onKeyUp: (event) => {},
108
- // @ts-expect-error ts-migrate(6133) FIXME: 'position' is declared but its value is never read... Remove this comment to see the full error message
109
- onPositioned: (position) => {},
110
- // @ts-expect-error ts-migrate(6133) FIXME: 'position' is declared but its value is never read... Remove this comment to see the full error message
111
- onPositionChanged: (position) => {},
112
- renderTrigger: null,
113
- children: null
92
+ shouldCloseOnEscape: true
114
93
  }
115
94
 
116
- _handleMouseOver: (...args: any[]) => any | undefined
117
- _handleMouseOut: (...args: any[]) => any | undefined
118
-
119
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'props' implicitly has an 'any' type.
120
- constructor(props) {
95
+ constructor(props: PopoverProps) {
121
96
  super(props)
122
97
 
123
98
  this.state = {
124
99
  placement: props.placement,
125
100
  offsetX: props.offsetX,
126
- offsetY: props.offsetY
127
- }
128
-
129
- if (typeof props.isShowingContent === 'undefined') {
130
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'isShowingContent' does not exist on type... Remove this comment to see the full error message
131
- this.state.isShowingContent = props.defaultIsShowingContent
101
+ offsetY: props.offsetY,
102
+ isShowingContent:
103
+ typeof props.isShowingContent === 'undefined'
104
+ ? props.defaultIsShowingContent
105
+ : undefined
132
106
  }
133
107
 
134
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_id' does not exist on type 'Popover'.
135
108
  this._id = this.props.id || uid('Popover')
136
109
  this._raf = []
137
110
 
138
111
  this._handleMouseOver = handleMouseOverOut.bind(null, (event) => {
139
112
  this.show(event)
140
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'mouseOutTimeout' does not exist on type ... Remove this comment to see the full error message
141
- clearTimeout(this.mouseOutTimeout)
113
+ clearTimeout(this.mouseOutTimeout!)
142
114
  })
143
115
  this._handleMouseOut = handleMouseOverOut.bind(null, (event) => {
144
116
  // this is needed bc the trigger mouseOut fires before tooltip mouseOver
145
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'mouseOutTimeout' does not exist on type ... Remove this comment to see the full error message
146
117
  this.mouseOutTimeout = setTimeout(() => {
147
118
  this.hide(event)
148
119
  }, 1)
149
120
  })
150
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'mouseOutTimeout' does not exist on type ... Remove this comment to see the full error message
151
- this.mouseOutTimeout = undefined
152
121
  }
153
122
 
154
- _raf: RequestAnimationFrameType[] = []
123
+ private _handleMouseOver: React.MouseEventHandler
124
+ private _handleMouseOut: React.MouseEventHandler
125
+
126
+ private _id: string
127
+ private _raf: RequestAnimationFrameType[] = []
128
+ private _trigger?: React.ReactElement
129
+ private _view: View | ContextView | null = null
130
+ private _dialog: Dialog | null = null
131
+ private _contentElement: Element | null = null
132
+ private _focusRegion?: FocusRegion
133
+
134
+ private mouseOutTimeout?: ReturnType<typeof setTimeout>
155
135
 
156
136
  ref: Element | null = null
157
137
 
@@ -179,7 +159,6 @@ class Popover extends Component<PopoverProps> {
179
159
  // if popover is being used as a tooltip with no focusable content
180
160
  // manage its FocusRegion internally rather than registering it with
181
161
  // the FocusRegionManager via Dialog
182
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_focusRegion' does not exist on type 'Po... Remove this comment to see the full error message
183
162
  this._focusRegion = new FocusRegion(this._contentElement, {
184
163
  shouldCloseOnEscape: false,
185
164
  shouldCloseOnDocumentClick: true,
@@ -187,7 +166,6 @@ class Popover extends Component<PopoverProps> {
187
166
  })
188
167
 
189
168
  if (this.shown) {
190
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_focusRegion' does not exist on type 'Po... Remove this comment to see the full error message
191
169
  this._focusRegion.activate()
192
170
  }
193
171
  }
@@ -197,48 +175,37 @@ class Popover extends Component<PopoverProps> {
197
175
  this._raf.forEach((request) => request.cancel())
198
176
  this._raf = []
199
177
 
200
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_focusRegion' does not exist on type 'Po... Remove this comment to see the full error message
201
178
  if (this._focusRegion) {
202
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_focusRegion' does not exist on type 'Po... Remove this comment to see the full error message
203
179
  this._focusRegion.deactivate()
204
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_focusRegion' does not exist on type 'Po... Remove this comment to see the full error message
205
180
  this._focusRegion.blur()
206
181
  }
207
182
  }
208
183
 
209
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'nextProps' implicitly has an 'any' type... Remove this comment to see the full error message
210
- shouldComponentUpdate(nextProps, nextState, nextContext) {
184
+ shouldComponentUpdate(nextProps: PopoverProps, nextState: PopoverState) {
211
185
  return (
212
186
  !shallowEqual(this.props, nextProps) ||
213
187
  !shallowEqual(this.state, nextState)
214
188
  )
215
189
  }
216
190
 
217
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'prevProps' implicitly has an 'any' type... Remove this comment to see the full error message
218
- componentDidUpdate(prevProps, prevState, snapShot) {
219
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_focusRegion' does not exist on type 'Po... Remove this comment to see the full error message
191
+ componentDidUpdate(prevProps: PopoverProps, prevState: PopoverState) {
220
192
  if (this._focusRegion && this.isTooltip) {
221
193
  // if focus region exists, popover is acting as a tooltip
222
194
  // so we manually activate and deactivate the region when showing/hiding
223
195
  if (
224
196
  (!prevProps.isShowingContent && this.props.isShowingContent) ||
225
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'isShowingContent' does not exist on type... Remove this comment to see the full error message
226
197
  (!prevState.isShowingContent && this.state.isShowingContent)
227
198
  ) {
228
199
  // changed from hiding to showing
229
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_focusRegion' does not exist on type 'Po... Remove this comment to see the full error message
230
200
  this._focusRegion.activate()
231
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_focusRegion' does not exist on type 'Po... Remove this comment to see the full error message
232
201
  this._focusRegion.focus()
233
202
  }
234
203
 
235
204
  if (
236
205
  (prevProps.isShowingContent && !this.props.isShowingContent) ||
237
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'isShowingContent' does not exist on type... Remove this comment to see the full error message
238
206
  (prevState.isShowingContent && !this.state.isShowingContent)
239
207
  ) {
240
208
  // changed from showing to hiding
241
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_focusRegion' does not exist on type 'Po... Remove this comment to see the full error message
242
209
  this._focusRegion.deactivate()
243
210
  }
244
211
  }
@@ -259,18 +226,16 @@ class Popover extends Component<PopoverProps> {
259
226
  }
260
227
  }
261
228
 
262
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'placement' implicitly has an 'any' type... Remove this comment to see the full error message
263
- computeOffsets(placement) {
229
+ computeOffsets(placement: PopoverProps['placement']) {
264
230
  let { offsetX, offsetY } = this.props
265
231
 
266
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_view' does not exist on type 'Popover'.
267
232
  if (this.props.shouldAlignArrow && this._view) {
268
- const secondaryPlacement = parsePlacement(placement)[1]
233
+ const secondaryPlacement = parsePlacement(placement!)[1]
269
234
 
270
235
  // arrowSize and arrowBorderWidth are component theme variables
271
236
  // declared in ContextView's styles.js
272
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_view' does not exist on type 'Popover'.
273
- const { arrowSize = 0, arrowBorderWidth = 0 } = this._view.props.styles
237
+ const { arrowSize = 0, arrowBorderWidth = 0 } = (this
238
+ ._view as ContextView).props.styles!
274
239
 
275
240
  const offsetAmount = (px(arrowSize) + px(arrowBorderWidth)) * 2
276
241
 
@@ -288,12 +253,12 @@ class Popover extends Component<PopoverProps> {
288
253
  return { offsetX, offsetY }
289
254
  }
290
255
 
291
- get placement() {
256
+ get placement(): PopoverProps['placement'] {
292
257
  let { placement } = this.props
293
258
  const { dir } = this.props
294
259
  const isRtl = dir === textDirectionContextConsumer.DIRECTION.rtl
295
260
  if (isRtl) {
296
- placement = mirrorHorizontalPlacement(placement, ' ')
261
+ placement = mirrorHorizontalPlacement(placement!, ' ')
297
262
  }
298
263
 
299
264
  return !this.shown && this.props.shouldRenderOffscreen
@@ -301,11 +266,9 @@ class Popover extends Component<PopoverProps> {
301
266
  : placement
302
267
  }
303
268
 
304
- get positionProps() {
269
+ get positionProps(): Partial<PositionProps> {
305
270
  return {
306
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'offsetX' does not exist on type 'Readonl... Remove this comment to see the full error message
307
271
  offsetX: this.state.offsetX,
308
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'offsetY' does not exist on type 'Readonl... Remove this comment to see the full error message
309
272
  offsetY: this.state.offsetY,
310
273
  shouldTrackPosition: this.props.shouldTrackPosition && this.shown,
311
274
  insertAt: this.props.insertAt,
@@ -315,15 +278,13 @@ class Popover extends Component<PopoverProps> {
315
278
  onPositionChanged: this.handlePositionChanged,
316
279
  target: this.props.positionTarget,
317
280
  mountNode: this.props.mountNode,
318
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_id' does not exist on type 'Popover'.
319
281
  id: this._id
320
282
  }
321
283
  }
322
284
 
323
285
  get shown() {
324
286
  return typeof this.props.isShowingContent === 'undefined'
325
- ? // @ts-expect-error ts-migrate(2339) FIXME: Property 'isShowingContent' does not exist on type... Remove this comment to see the full error message
326
- this.state.isShowingContent
287
+ ? this.state.isShowingContent
327
288
  : this.props.isShowingContent
328
289
  }
329
290
 
@@ -331,38 +292,31 @@ class Popover extends Component<PopoverProps> {
331
292
  return this.props.defaultFocusElement
332
293
  }
333
294
 
334
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'event' implicitly has an 'any' type.
335
- show = (event) => {
295
+ show = (event: Event) => {
336
296
  if (typeof this.props.isShowingContent === 'undefined') {
337
297
  this.setState({ isShowingContent: true })
338
298
  }
339
- // @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
340
- this.props.onShowContent(event)
299
+ this.props.onShowContent?.(event)
341
300
  }
342
301
 
343
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'event' implicitly has an 'any' type.
344
- hide = (event, documentClick = false) => {
302
+ hide = (event: Event, documentClick = false) => {
345
303
  const { onHideContent, isShowingContent } = this.props
346
304
 
347
305
  if (typeof isShowingContent === 'undefined') {
348
306
  // uncontrolled, set state, fire callbacks
349
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'isShowingContent' does not exist on type... Remove this comment to see the full error message
350
307
  this.setState(({ isShowingContent }) => {
351
308
  if (isShowingContent) {
352
- // @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
353
- onHideContent(event, { documentClick })
309
+ onHideContent?.(event, { documentClick })
354
310
  }
355
311
  return { isShowingContent: false }
356
312
  })
357
313
  } else if (isShowingContent) {
358
314
  // controlled, fire callback
359
- // @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
360
- onHideContent(event, { documentClick })
315
+ onHideContent?.(event, { documentClick })
361
316
  }
362
317
  }
363
318
 
364
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'event' implicitly has an 'any' type.
365
- toggle = (event) => {
319
+ toggle = (event: Event) => {
366
320
  if (this.shown) {
367
321
  this.hide(event)
368
322
  } else {
@@ -370,28 +324,24 @@ class Popover extends Component<PopoverProps> {
370
324
  }
371
325
  }
372
326
 
373
- // @ts-expect-error ts-migrate(7019) FIXME: Rest parameter 'args' implicitly has an 'any[]' ty... Remove this comment to see the full error message
374
- handleDialogDismiss = (...args) => {
327
+ handleDialogDismiss: DialogProps['onDismiss'] = (event, documentClick) => {
375
328
  if (
376
329
  !this.props.shouldReturnFocus &&
377
330
  this.props.shouldFocusContentOnTriggerBlur
378
331
  ) {
379
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_trigger' does not exist on type 'Popove... Remove this comment to see the full error message
380
- const trigger = findDOMNode(this._trigger) as any
332
+ const trigger = findDOMNode(this._trigger)
381
333
 
382
- if (trigger && typeof trigger.focus === 'function') {
383
- trigger.focus()
334
+ if (trigger && typeof (trigger as HTMLElement).focus === 'function') {
335
+ ;(trigger as HTMLElement).focus()
384
336
  }
385
337
  }
386
- // @ts-expect-error ts-migrate(2556) FIXME: Expected 1-2 arguments, but got 0 or more.
387
- this.hide(...args)
338
+ this.hide(event, documentClick)
388
339
  }
389
340
 
390
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'event' implicitly has an 'any' type.
391
- handleDialogBlur = (event) => {
341
+ handleDialogBlur = (event: Event) => {
392
342
  if (
393
- event.keyCode === keycode.codes.tab &&
394
- event.shiftKey &&
343
+ (event as KeyboardEvent).keyCode === keycode.codes.tab &&
344
+ (event as KeyboardEvent).shiftKey &&
395
345
  this.props.shouldFocusContentOnTriggerBlur
396
346
  ) {
397
347
  return
@@ -399,8 +349,7 @@ class Popover extends Component<PopoverProps> {
399
349
  this.hide(event)
400
350
  }
401
351
 
402
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'event' implicitly has an 'any' type.
403
- handleTriggerKeyDown = (event) => {
352
+ handleTriggerKeyDown = (event: KeyboardEvent) => {
404
353
  if (!this.props.shouldFocusContentOnTriggerBlur) {
405
354
  return
406
355
  }
@@ -409,15 +358,13 @@ class Popover extends Component<PopoverProps> {
409
358
  event.preventDefault()
410
359
  this._raf.push(
411
360
  requestAnimationFrame(() => {
412
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_dialog' does not exist on type 'Popover... Remove this comment to see the full error message
413
361
  this._dialog && this._dialog.focus()
414
362
  })
415
363
  )
416
364
  }
417
365
  }
418
366
 
419
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'event' implicitly has an 'any' type.
420
- handleTriggerKeyUp = (event) => {
367
+ handleTriggerKeyUp = (event: KeyboardEvent) => {
421
368
  if (event.keyCode === keycode.codes.esc && this.shown && this.isTooltip) {
422
369
  // if popover is tooltip, it is managing its own focus region so we need
423
370
  // to prevent esc keyup event from reaching FocusRegionManager
@@ -426,13 +373,12 @@ class Popover extends Component<PopoverProps> {
426
373
  }
427
374
  }
428
375
 
429
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'event' implicitly has an 'any' type.
430
- handleTriggerBlur = (event) => {
431
- // @ts-expect-error ts-migrate(2532) FIXME: Object is possibly 'undefined'.
432
- if (this.props.on.indexOf('focus') > -1) {
376
+ handleTriggerBlur = (event: Event) => {
377
+ const { on } = this.props
378
+
379
+ if (on && on.indexOf('focus') > -1) {
433
380
  this._raf.push(
434
381
  requestAnimationFrame(() => {
435
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_view' does not exist on type 'Popover'.
436
382
  if (!containsActiveElement(this._view)) {
437
383
  this.hide(event)
438
384
  }
@@ -441,49 +387,43 @@ class Popover extends Component<PopoverProps> {
441
387
  }
442
388
  }
443
389
 
444
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'position' implicitly has an 'any' type.
445
- handlePositioned = (position) => {
390
+ handlePositioned: PositionProps['onPositioned'] = (position) => {
446
391
  const placement = position.placement
447
392
  this.setState({
448
393
  placement,
449
394
  ...this.computeOffsets(placement)
450
395
  })
451
- // @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
452
- this.props.onPositioned(position)
396
+ this.props.onPositioned?.(position)
453
397
  }
454
398
 
455
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'position' implicitly has an 'any' type.
456
- handlePositionChanged = (position) => {
399
+ handlePositionChanged: PositionProps['onPositionChanged'] = (position) => {
457
400
  const placement = position.placement
458
401
  this.setState({
459
402
  placement,
460
403
  ...this.computeOffsets(placement)
461
404
  })
462
- // @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
463
- this.props.onPositionChanged(position)
405
+ this.props.onPositionChanged?.(position)
464
406
  }
465
407
 
466
408
  renderTrigger() {
467
- let trigger = callRenderProp(this.props.renderTrigger)
409
+ let trigger: React.ReactElement = callRenderProp(this.props.renderTrigger)
468
410
 
469
411
  if (trigger) {
470
412
  const { on, shouldContainFocus } = this.props
471
- let onClick
472
- let onFocus
473
- let onMouseOut
474
- let onMouseOver
475
- let expanded
476
-
477
- // @ts-expect-error ts-migrate(2532) FIXME: Object is possibly 'undefined'.
478
- if (on.indexOf('click') > -1) {
479
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'event' implicitly has an 'any' type.
480
- onClick = (event) => {
413
+
414
+ let onClick: ((event: Event) => void) | undefined = undefined
415
+ let onFocus: ((event: Event) => void) | undefined = undefined
416
+ let onMouseOut: React.MouseEventHandler | undefined = undefined
417
+ let onMouseOver: React.MouseEventHandler | undefined = undefined
418
+ let expanded: string | undefined
419
+
420
+ if (on && on.indexOf('click') > -1) {
421
+ onClick = (event: Event) => {
481
422
  this.toggle(event)
482
423
  }
483
424
  }
484
425
 
485
- // @ts-expect-error ts-migrate(2532) FIXME: Object is possibly 'undefined'.
486
- if (on.indexOf('hover') > -1) {
426
+ if (on && on.indexOf('hover') > -1) {
487
427
  error(
488
428
  !(on === 'hover'),
489
429
  '[Popover] Specifying only the `"hover"` trigger limits the visibility' +
@@ -494,10 +434,8 @@ class Popover extends Component<PopoverProps> {
494
434
  onMouseOut = this._handleMouseOut
495
435
  }
496
436
 
497
- // @ts-expect-error ts-migrate(2532) FIXME: Object is possibly 'undefined'.
498
- if (on.indexOf('focus') > -1) {
499
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'event' implicitly has an 'any' type.
500
- onFocus = (event) => {
437
+ if (on && on.indexOf('focus') > -1) {
438
+ onFocus = (event: Event) => {
501
439
  this.show(event)
502
440
  }
503
441
  }
@@ -506,12 +444,13 @@ class Popover extends Component<PopoverProps> {
506
444
  // only set aria-expanded if popover can contain focus
507
445
  expanded = this.shown ? 'true' : 'false'
508
446
  } else {
509
- expanded = null
447
+ expanded = undefined
510
448
  }
511
449
 
512
450
  trigger = safeCloneElement(trigger, {
513
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'el' implicitly has an 'any' type.
514
- ref: (el) => (this._trigger = el),
451
+ ref: (el: React.ReactElement) => {
452
+ this._trigger = el
453
+ },
515
454
  'aria-expanded': expanded,
516
455
  'data-popover-trigger': true,
517
456
  onKeyDown: createChainedFunction(
@@ -546,7 +485,6 @@ class Popover extends Component<PopoverProps> {
546
485
  <Dialog
547
486
  open={this.shown}
548
487
  label={this.props.screenReaderLabel}
549
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_dialog' does not exist on type 'Popover... Remove this comment to see the full error message
550
488
  ref={(el) => (this._dialog = el)}
551
489
  display="block"
552
490
  onBlur={this.handleDialogBlur}
@@ -565,18 +503,16 @@ class Popover extends Component<PopoverProps> {
565
503
  }
566
504
 
567
505
  if (this.shown || this.props.shouldRenderOffscreen) {
568
- let ViewElement
569
506
  const color = this.props.color
570
507
 
571
- let viewProps = {
572
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'c' implicitly has an 'any' type.
573
- ref: (c) => (this._view = c),
574
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'el' implicitly has an 'any' type.
575
- elementRef: (el) => {
576
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_contentElement' does not exist on type ... Remove this comment to see the full error message
508
+ let viewProps: (Partial<ViewProps> | Partial<ContextViewProps>) & {
509
+ ref: any
510
+ } = {
511
+ // TODO: try to type `ref` better, LegacyRef<T> was not compatible
512
+ ref: (c: View | ContextView | null) => (this._view = c),
513
+ elementRef: (el: Element | null) => {
577
514
  this._contentElement = el
578
- // @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
579
- this.props.contentRef(el)
515
+ this.props.contentRef?.(el)
580
516
  },
581
517
  background: color,
582
518
  stacking: this.props.stacking,
@@ -584,43 +520,39 @@ class Popover extends Component<PopoverProps> {
584
520
  display: 'block'
585
521
  }
586
522
 
587
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'placement' does not exist on type 'Reado... Remove this comment to see the full error message
523
+ if (this.isTooltip) {
524
+ viewProps = {
525
+ ...viewProps,
526
+ // Because of a11y reasons popovers should not be hidden when hovered over
527
+ onMouseOver: this._handleMouseOver as any,
528
+ onMouseOut: this._handleMouseOut as any
529
+ }
530
+ }
531
+
588
532
  const { placement } = this.state
589
533
 
590
534
  if (this.props.withArrow) {
591
- ViewElement = ContextView
592
535
  viewProps = {
593
536
  ...viewProps,
594
537
  // TODO: remove background override after contextview is updated
595
- // @ts-expect-error ts-migrate(2322) FIXME: Type '"default" | "inverse"' is not assignable to ... Remove this comment to see the full error message
596
538
  background: color === 'primary' ? 'default' : 'inverse',
597
539
  placement:
598
540
  this.props.dir === textDirectionContextConsumer.DIRECTION.rtl
599
- ? mirrorHorizontalPlacement(placement, ' ')
541
+ ? mirrorHorizontalPlacement(placement!, ' ')
600
542
  : placement
601
- }
543
+ } as Partial<ContextViewProps> & { ref: any }
544
+
545
+ return <ContextView {...viewProps}>{content}</ContextView>
602
546
  } else {
603
- ViewElement = View
604
547
  viewProps = {
605
548
  ...viewProps,
606
- // @ts-expect-error ts-migrate(2322) FIXME: Type '{ borderWidth: string; borderRadius: string;... Remove this comment to see the full error message
607
549
  borderWidth: 'small',
608
550
  borderRadius: 'medium',
609
551
  ...(color === 'primary-inverse' && { borderColor: 'transparent' })
610
- }
611
- }
552
+ } as Partial<ViewProps> & { ref: any }
612
553
 
613
- if (this.isTooltip) {
614
- viewProps = {
615
- ...viewProps,
616
- // Because of a11y reasons popovers should not be hidden when hovered over
617
- // @ts-expect-error ts-migrate(2322) FIXME: Type '{ onMouseOver: any; onMouseOut: any; ref: (c... Remove this comment to see the full error message
618
- onMouseOver: this._handleMouseOver,
619
- onMouseOut: this._handleMouseOut
620
- }
554
+ return <View {...viewProps}>{content}</View>
621
555
  }
622
- // @ts-expect-error ts-migrate(2769) FIXME: No overload matches this call.
623
- return <ViewElement {...viewProps}>{content}</ViewElement>
624
556
  } else {
625
557
  return null
626
558
  }