Skip to content

Commit a5de25b

Browse files
committed
code review
1 parent bb170c1 commit a5de25b

15 files changed

Lines changed: 56 additions & 73 deletions

src/downshift.types.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
import React from 'react'
2+
import {AnyRef, Environment, GetPropsCommonOptions, Overwrite} from './types'
23

3-
export type Callback = () => void
4-
5-
export type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U
4+
export type {AnyRef, Environment, GetPropsCommonOptions, Overwrite}
65

7-
export interface Environment {
8-
addEventListener: typeof window.addEventListener
9-
removeEventListener: typeof window.removeEventListener
10-
document: Document
11-
Node: typeof window.Node
12-
}
6+
export type Callback = () => void
137

148
export interface DownshiftState<Item> {
159
highlightedIndex: number | null
@@ -182,10 +176,6 @@ export interface GetMenuPropsReturnValue {
182176
id: string
183177
}
184178

185-
export interface GetPropsCommonOptions {
186-
suppressRefError?: boolean
187-
}
188-
189179
export interface GetPropsWithRefKey {
190180
refKey?: string
191181
}

src/hooks/useCombobox/README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,7 @@ how the component interacts with user updates. It gives you the current state
292292
and the state that will be set, and you return the state that you want to set.
293293

294294
- `state`: The full current state of downshift.
295-
- `actionAndChanges`: Object that contains the action `type`, props needed to
296-
return a new state based on that type and the changes suggested by the
297-
Downshift default reducer. About the `type` property you can learn more about
298-
in the [`stateChangeTypes`](#statechangetypes) section.
295+
- `actionAndChanges`: Object that contains the action `type`, the `props` passed to `useCombobox`, the `changes` suggested by the Downshift default reducer, and any action-specific fields (e.g. `altKey`, `key`, `index`). About the `type` property you can learn more about in the [`stateChangeTypes`](#statechangetypes) section.
299296

300297
```javascript
301298
import {useCombobox} from 'downshift'

src/hooks/useCombobox/index.types.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import {
2+
AnyRef,
23
Environment,
34
GetPropsCommonOptions,
45
Overwrite,
5-
} from '../../downshift.types'
6+
} from '../../types'
67

78
export interface UseComboboxState<Item> {
89
highlightedIndex: number
@@ -251,15 +252,13 @@ export interface UseComboboxInputValueChange<
251252

252253
export interface UseComboboxGetMenuPropsOptions extends React.HTMLProps<HTMLElement> {
253254
refKey?: string
254-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- element type unknown at declaration site
255-
ref?: React.Ref<any>
255+
ref?: AnyRef
256256
}
257257

258258
export interface UseComboboxGetMenuPropsReturnValue {
259259
'aria-label': string | undefined
260260
'aria-labelledby': string | undefined
261-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- element type unknown at declaration site
262-
ref?: React.Ref<any>
261+
ref?: AnyRef
263262
role: 'listbox'
264263
id: string
265264
onMouseLeave: React.MouseEventHandler
@@ -273,8 +272,7 @@ export type UseComboboxGetMenuProps = <Options>(
273272
export interface UseComboboxGetToggleButtonPropsOptions extends React.HTMLProps<HTMLElement> {
274273
disabled?: boolean
275274
refKey?: string
276-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- element type unknown at declaration site
277-
ref?: React.Ref<any>
275+
ref?: AnyRef
278276
onPress?: (event: React.BaseSyntheticEvent) => void
279277
}
280278

@@ -284,8 +282,7 @@ export interface UseComboboxGetToggleButtonPropsReturnValue {
284282
id: string
285283
onPress?: (event: React.BaseSyntheticEvent) => void
286284
onClick?: React.MouseEventHandler
287-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- element type unknown at declaration site
288-
ref?: React.Ref<any>
285+
ref?: AnyRef
289286
tabIndex: -1
290287
}
291288

@@ -311,8 +308,7 @@ export interface UseComboboxGetItemPropsOptions<
311308
index?: number
312309
item?: Item
313310
refKey?: string
314-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- element type unknown at declaration site
315-
ref?: React.Ref<any>
311+
ref?: AnyRef
316312
onPress?: (event: React.BaseSyntheticEvent) => void
317313
}
318314

@@ -324,8 +320,7 @@ export interface UseComboboxGetItemPropsReturnValue {
324320
onMouseDown?: React.MouseEventHandler
325321
onMouseMove?: React.MouseEventHandler
326322
onPress?: React.MouseEventHandler
327-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- element type unknown at declaration site
328-
ref?: React.Ref<any>
323+
ref?: AnyRef
329324
role: 'option'
330325
}
331326

@@ -343,8 +338,7 @@ export interface UseComboboxGetInputPropsOptions extends React.HTMLProps<HTMLInp
343338
}
344339

345340
export interface UseComboboxGetInputPropsReturnValue {
346-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- element type unknown at declaration site
347-
ref?: React.Ref<any>
341+
ref?: AnyRef
348342
'aria-activedescendant': string
349343
'aria-autocomplete': 'list'
350344
'aria-controls': string

src/hooks/useMultipleSelection/index.types.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import * as React from 'react'
22
import {
3+
AnyRef,
34
Environment,
45
GetPropsCommonOptions,
56
Overwrite,
6-
} from '../../downshift.types'
7+
} from '../../types'
78

89
export interface UseMultipleSelectionState<Item> {
910
selectedItems: Item[]
@@ -96,15 +97,13 @@ export interface UseMultipleSelectionGetSelectedItemPropsOptions<
9697
Item,
9798
> extends React.HTMLProps<HTMLElement> {
9899
refKey?: string
99-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- element type unknown at declaration site
100-
ref?: React.Ref<any>
100+
ref?: AnyRef
101101
index?: number
102102
selectedItem: Item
103103
}
104104

105105
export interface UseMultipleSelectionGetSelectedItemReturnValue {
106-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- element type unknown at declaration site
107-
ref?: React.Ref<any>
106+
ref?: AnyRef
108107
tabIndex: 0 | -1
109108
onClick: React.MouseEventHandler
110109
onKeyDown: React.KeyboardEventHandler
@@ -113,13 +112,11 @@ export interface UseMultipleSelectionGetSelectedItemReturnValue {
113112
export interface UseMultipleSelectionGetDropdownPropsOptions extends React.HTMLProps<HTMLElement> {
114113
preventKeyAction?: boolean
115114
refKey?: string
116-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- element type unknown at declaration site
117-
ref?: React.Ref<any>
115+
ref?: AnyRef
118116
}
119117

120118
export interface UseMultipleSelectionGetDropdownReturnValue {
121-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- element type unknown at declaration site
122-
ref?: React.Ref<any>
119+
ref?: AnyRef
123120
onClick?: React.MouseEventHandler
124121
onKeyDown?: React.KeyboardEventHandler
125122
}

src/hooks/useSelect/README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,7 @@ how the component interacts with user updates. It gives you the current state
234234
and the state that will be set, and you return the state that you want to set.
235235

236236
- `state`: The full current state of downshift.
237-
- `actionAndChanges`: Object that contains the action `type`, props needed to
238-
return a new state based on that type and the changes suggested by the
239-
Downshift default reducer. About the `type` property you can learn more about
240-
in the [`stateChangeTypes`](#statechangetypes) section.
237+
- `actionAndChanges`: Object that contains the action `type`, the `props` passed to `useSelect`, the `changes` suggested by the Downshift default reducer, and any action-specific fields (e.g. `altKey`, `key`, `index`). About the `type` property you can learn more about in the [`stateChangeTypes`](#statechangetypes) section.
241238

242239
```javascript
243240
import {useSelect} from 'downshift'

src/hooks/useSelect/index.types.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import * as React from 'react'
22
import {
3+
AnyRef,
34
Environment,
45
GetPropsCommonOptions,
56
Overwrite,
6-
} from '../../downshift.types'
7+
} from '../../types'
78

89
export interface UseSelectState<Item> {
910
highlightedIndex: number
@@ -234,16 +235,14 @@ export interface UseSelectIsOpenChange<
234235

235236
export interface UseSelectGetMenuPropsOptions extends React.HTMLProps<HTMLElement> {
236237
refKey?: string
237-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- element type unknown at declaration site
238-
ref?: React.Ref<any>
238+
ref?: AnyRef
239239
}
240240

241241
export interface UseSelectGetMenuPropsReturnValue {
242242
'aria-labelledby': string | undefined
243243
id: string
244244
onMouseLeave: React.MouseEventHandler
245-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- element type unknown at declaration site
246-
ref?: React.Ref<any>
245+
ref?: AnyRef
247246
role: 'listbox'
248247
}
249248

@@ -254,8 +253,7 @@ export type UseSelectGetMenuProps = <Options>(
254253

255254
export interface UseSelectGetToggleButtonPropsOptions extends React.HTMLProps<HTMLElement> {
256255
refKey?: string
257-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- element type unknown at declaration site
258-
ref?: React.Ref<any>
256+
ref?: AnyRef
259257
onPress?: (event: React.BaseSyntheticEvent) => void
260258
}
261259

@@ -270,8 +268,7 @@ export interface UseSelectGetToggleButtonPropsReturnValue {
270268
onClick?: React.MouseEventHandler
271269
onKeyDown?: React.KeyboardEventHandler
272270
onPress?: (event: React.BaseSyntheticEvent) => void
273-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- element type unknown at declaration site
274-
ref?: React.Ref<any>
271+
ref?: AnyRef
275272
role: 'combobox'
276273
tabIndex: 0
277274
}
@@ -300,8 +297,7 @@ export interface UseSelectGetItemPropsOptions<
300297
item?: Item
301298
index?: number
302299
refKey?: string
303-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- element type unknown at declaration site
304-
ref?: React.Ref<any>
300+
ref?: AnyRef
305301
onPress?: (event: React.BaseSyntheticEvent) => void
306302
}
307303

@@ -313,8 +309,7 @@ export interface UseSelectGetItemPropsReturnValue {
313309
onMouseDown?: React.MouseEventHandler
314310
onMouseMove?: React.MouseEventHandler
315311
onPress?: React.MouseEventHandler
316-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- element type unknown at declaration site
317-
ref?: React.Ref<any>
312+
ref?: AnyRef
318313
role: 'option'
319314
}
320315

src/hooks/useTagGroup/index.types.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Environment} from '../../downshift.types'
1+
import {AnyRef, Environment} from '../../types'
22

33
export interface UseTagGroupState<Item> {
44
activeIndex: number
@@ -78,15 +78,13 @@ export interface UseTagGroupReturnValue<Item> {
7878
export interface GetTagPropsOptions extends React.HTMLProps<HTMLElement> {
7979
index: number
8080
refKey?: string
81-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- element type unknown at declaration site
82-
ref?: React.Ref<any>
81+
ref?: AnyRef
8382
}
8483

8584
export interface GetTagPropsReturnValue {
8685
'aria-describedby': string
8786
id: string
88-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- element type unknown at declaration site
89-
ref?: React.Ref<any>
87+
ref?: AnyRef
9088
role: 'option'
9189
onPress?: (event: React.BaseSyntheticEvent) => void
9290
onClick?: React.MouseEventHandler
@@ -107,14 +105,12 @@ export interface GetTagRemovePropsReturnValue {
107105

108106
export interface GetTagGroupPropsOptions extends React.HTMLProps<HTMLElement> {
109107
refKey?: string
110-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- element type unknown at declaration site
111-
ref?: React.Ref<any>
108+
ref?: AnyRef
112109
}
113110

114111
export interface GetTagGroupPropsReturnValue {
115112
id: string
116-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- element type unknown at declaration site
117-
ref?: React.Ref<any>
113+
ref?: AnyRef
118114
role: 'listbox'
119115
'aria-live': 'polite'
120116
'aria-atomic': 'false'

src/hooks/utils/__tests__/useMouseAndTouchTracker.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {renderHook} from '@testing-library/react'
22
import {useMouseAndTouchTracker} from '../useMouseAndTouchTracker'
3-
import {Environment} from '../../../downshift.types'
3+
import {Environment} from '../../../types'
44
import {targetWithinDownshift} from '../../../utils'
55

66
jest.mock('../../../utils', () => ({

src/hooks/utils/isDropdownStateEqual.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type DropdownState<Item> = {
1111
*
1212
* @param prevState The previous dropdown state.
1313
* @param newState The new dropdown state.
14-
* @returns Wheather the states are deeply equal.
14+
* @returns Whether the states are deeply equal.
1515
*/
1616
export function isDropdownStateEqual<Item>(
1717
prevState: DropdownState<Item>,

src/hooks/utils/reducer.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,3 @@ export default function downshiftCommonReducer<Item>(
148148
...changes,
149149
}
150150
}
151-
/* eslint-enable complexity */

0 commit comments

Comments
 (0)