/
useAutocomplete.d.ts
181 lines (175 loc) · 5.19 KB
/
useAutocomplete.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import * as React from 'react';
export interface CreateFilterOptionsConfig {
ignoreAccents?: boolean;
ignoreCase?: boolean;
matchFrom?: 'any' | 'start';
stringify?: (option: any) => string;
trim?: boolean;
}
export interface FilterOptionsState {
inputValue: string;
}
export type CreateFilterOptions = (
config: CreateFilterOptionsConfig,
) => (option: any, state: FilterOptionsState) => any[];
export const createFilterOptions: CreateFilterOptions;
export interface UseAutocompleteProps {
/**
* If `true`, the portion of the selected suggestion that has not been typed by the user,
* known as the completion string, appears inline after the input cursor in the textbox.
* The inline completion string is visually highlighted and has a selected state.
*/
autoComplete?: boolean;
/**
* If `true`, the first option is automatically highlighted.
*/
autoHighlight?: boolean;
/**
* If `true`, the selected option becomes the value of the input
* when the Autocomplete loses focus unless the user chooses
* a different option or changes the character string in the input.
*/
autoSelect?: boolean;
/**
* If `true`, clear all values when the user presses escape and the popup is closed.
*/
clearOnEscape?: boolean;
/**
* If `true`, the popup will ignore the blur event if the input if filled.
* You can inspect the popup markup with your browser tools.
* Consider this option when you need to customize the component.
*/
debug?: boolean;
/**
* The default input value. Use when the component is not controlled.
*/
defaultValue?: any;
/**
* If `true`, the input can't be cleared.
*/
disableClearable?: boolean;
/**
* If `true`, the popup won't close when a value is selected.
*/
disableCloseOnSelect?: boolean;
/**
* If `true`, the list box in the popup will not wrap focus.
*/
disableListWrap?: boolean;
/**
* If `true`, the popup won't open on input focus.
*/
disableOpenOnFocus?: boolean;
/**
* A filter function that determines the options that are eligible.
*
* @param {any[]} options The options to render.
* @param {object} state The state of the component.
* @returns {any[]}
*/
filterOptions?: (options: any[], state: FilterOptionsState) => any[];
/**
* If `true`, hide the selected options from the list box.
*/
filterSelectedOptions?: boolean;
/**
* If `true`, the Autocomplete is free solo, meaning that the user input is not bound to provided options.
*/
freeSolo?: boolean;
/**
* Used to determine the disabled state for a given option.
*/
getOptionDisabled?: (option: any) => boolean;
/**
* Used to determine the string value for a given option.
* It's used to fill the input (and the list box options if `renderOption` is not provided).
*/
getOptionLabel?: (option: any) => string;
/**
* If provided, the options will be grouped under the returned string.
* The groupBy value is also used as the text for group headings when `renderGroup` is not provided.
*
* @param {any} options The option to group.
* @returns {string}
*/
groupBy?: (option: any) => string;
/**
* This prop is used to help implement the accessibility logic.
* If you don't provide this prop. It falls back to a randomly generated id.
*/
id?: string;
/**
* If `true`, the highlight can move to the input.
*/
includeInputInList?: boolean;
/**
* The input value.
*/
inputValue?: string;
/**
* If true, `value` must be an array and the menu will support multiple selections.
*/
multiple?: boolean;
/**
* Callback fired when the value changes.
*
* @param {object} event The event source of the callback
* @param {any} value
*/
onChange?: (event: React.ChangeEvent<{}>, value: any) => void;
/**
* Callback fired when the popup requests to be closed.
* Use in controlled mode (see open).
*
* @param {object} event The event source of the callback.
*/
onClose?: (event: React.ChangeEvent<{}>) => void;
/**
* Callback fired when the input value changes.
*
* @param {object} event The event source of the callback.
* @param {string} value
*/
onInputChange?: (event: React.ChangeEvent<{}>, value: any) => void;
/**
* Callback fired when the popup requests to be opened.
* Use in controlled mode (see open).
*
* @param {object} event The event source of the callback.
*/
onOpen?: (event: React.ChangeEvent<{}>) => void;
/**
* Control the popup` open state.
*/
open?: boolean;
/**
* Array of options.
*/
options?: any[];
/**
* The value of the autocomplete.
*/
value?: any;
}
export default function useAutocomplete(
props: UseAutocompleteProps,
): {
getRootProps: () => {};
getInputProps: () => {};
getInputLabelProps: () => {};
getClearProps: () => {};
getPopupIndicatorProps: () => {};
getTagProps: ({ index }: { index: number }) => {};
getListboxProps: () => {};
getOptionProps: ({ option, index }: { option: any; index: number }) => {};
id: string;
inputValue: string;
value: any;
dirty: boolean;
popupOpen: boolean;
focused: boolean;
anchorEl: null | HTMLElement;
setAnchorEl: () => void;
focusedTag: number;
groupedOptions: any[];
};