@@ -9,12 +9,12 @@ import type {Props as IndicatorProps} from './Indicator';
9
9
import Item from './Item' ;
10
10
import type { Props as ItemProps } from './Item' ;
11
11
12
- interface Props {
12
+ interface Props < V > {
13
13
/**
14
14
* Items to display in a list. Each item must be an object and have `label` and `value` props, it may also optionally have a `key` prop.
15
15
* If no `key` prop is provided, `value` will be used as the item key.
16
16
*/
17
- items ?: Item [ ] ;
17
+ items ?: Array < Item < V > > ;
18
18
19
19
/**
20
20
* Listen to user's input. Useful in case there are multiple input components at the same time and input must be "routed" to a specific component.
@@ -48,21 +48,22 @@ interface Props {
48
48
/**
49
49
* Function to call when user selects an item. Item object is passed to that function as an argument.
50
50
*/
51
- onSelect ?: ( item : Item ) => void ;
51
+ onSelect ?: ( item : Item < V > ) => void ;
52
52
53
53
/**
54
54
* Function to call when user highlights an item. Item object is passed to that function as an argument.
55
55
*/
56
- onHighlight ?: ( item : Item ) => void ;
56
+ onHighlight ?: ( item : Item < V > ) => void ;
57
57
}
58
58
59
- export interface Item {
59
+ export interface Item < V > {
60
60
key ?: string ;
61
61
label : string ;
62
- value : unknown ;
62
+ value : V ;
63
63
}
64
64
65
- const SelectInput : FC < Props > = ( {
65
+ // eslint-disable-next-line react/function-component-definition
66
+ function SelectInput < V > ( {
66
67
items = [ ] ,
67
68
isFocused = true ,
68
69
initialIndex = 0 ,
@@ -71,14 +72,14 @@ const SelectInput: FC<Props> = ({
71
72
limit : customLimit ,
72
73
onSelect,
73
74
onHighlight
74
- } ) => {
75
+ } : Props < V > ) : JSX . Element {
75
76
const [ rotateIndex , setRotateIndex ] = useState ( 0 ) ;
76
77
const [ selectedIndex , setSelectedIndex ] = useState ( initialIndex ) ;
77
78
const hasLimit =
78
79
typeof customLimit === 'number' && items . length > customLimit ;
79
80
const limit = hasLimit ? Math . min ( customLimit ! , items . length ) : items . length ;
80
81
81
- const previousItems = useRef < Item [ ] > ( items ) ;
82
+ const previousItems = useRef < Array < Item < V > >( items ) ;
82
83
83
84
useEffect ( ( ) => {
84
85
if ( ! isEqual ( previousItems . current , items ) ) {
@@ -173,6 +174,6 @@ const SelectInput: FC<Props> = ({
173
174
} ) }
174
175
</ Box >
175
176
) ;
176
- } ;
177
+ }
177
178
178
179
export default SelectInput ;
0 commit comments