@@ -74,39 +74,39 @@ export interface TypeaheadProps {
74
74
* If a function is specified, it will be used to determine whether a custom
75
75
* option should be included. The return value should be true or false.
76
76
*/
77
- allowNew : AllowNew ;
77
+ allowNew ? : AllowNew ;
78
78
/**
79
79
* Autofocus the input when the component initially mounts.
80
80
*/
81
- autoFocus : boolean ;
81
+ autoFocus ? : boolean ;
82
82
/**
83
83
* Whether or not filtering should be case-sensitive.
84
84
*/
85
- caseSensitive : boolean ;
85
+ caseSensitive ? : boolean ;
86
86
children ?: TypeaheadChildren ;
87
87
/**
88
88
* The initial value displayed in the text input.
89
89
*/
90
- defaultInputValue : string ;
90
+ defaultInputValue ? : string ;
91
91
/**
92
92
* Whether or not the menu is displayed upon initial render.
93
93
*/
94
- defaultOpen : boolean ;
94
+ defaultOpen ? : boolean ;
95
95
/**
96
96
* Specify any pre-selected options. Use only if you want the component to
97
97
* be uncontrolled.
98
98
*/
99
- defaultSelected : Option [ ] ;
99
+ defaultSelected ? : Option [ ] ;
100
100
/**
101
101
* Either an array of fields in `option` to search, or a custom filtering
102
102
* callback.
103
103
*/
104
- filterBy : string [ ] | FilterByCallback ;
104
+ filterBy ? : string [ ] | FilterByCallback ;
105
105
/**
106
106
* Highlights the menu item if there is only one result and allows selecting
107
107
* that item by hitting enter. Does not work with `allowNew`.
108
108
*/
109
- highlightOnlyResult : boolean ;
109
+ highlightOnlyResult ? : boolean ;
110
110
/**
111
111
* An html id attribute, required for assistive technologies such as screen
112
112
* readers.
@@ -115,57 +115,57 @@ export interface TypeaheadProps {
115
115
/**
116
116
* Whether the filter should ignore accents and other diacritical marks.
117
117
*/
118
- ignoreDiacritics : boolean ;
118
+ ignoreDiacritics ? : boolean ;
119
119
inputProps ?: InputProps ;
120
120
/**
121
121
* Specify the option key to use for display or a function returning the
122
122
* display string. By default, the selector will use the `label` key.
123
123
*/
124
- labelKey : LabelKey ;
124
+ labelKey ? : LabelKey ;
125
125
/**
126
126
* Maximum number of results to display by default. Mostly done for
127
127
* performance reasons so as not to render too many DOM nodes in the case of
128
128
* large data sets.
129
129
*/
130
- maxResults : number ;
130
+ maxResults ? : number ;
131
131
/**
132
132
* Number of input characters that must be entered before showing results.
133
133
*/
134
- minLength : number ;
134
+ minLength ? : number ;
135
135
/**
136
136
* Whether or not multiple selections are allowed.
137
137
*/
138
- multiple : boolean ;
138
+ multiple ? : boolean ;
139
139
/**
140
140
* Invoked when the input is blurred. Receives an event.
141
141
*/
142
- onBlur : FocusEventHandler < HTMLInputElement > ;
142
+ onBlur ? : FocusEventHandler < HTMLInputElement > ;
143
143
/**
144
144
* Invoked whenever items are added or removed. Receives an array of the
145
145
* selected options.
146
146
*/
147
- onChange : ( selected : Option [ ] ) => void ;
147
+ onChange ? : ( selected : Option [ ] ) => void ;
148
148
/**
149
149
* Invoked when the input is focused. Receives an event.
150
150
*/
151
- onFocus : FocusEventHandler < HTMLInputElement > ;
151
+ onFocus ? : FocusEventHandler < HTMLInputElement > ;
152
152
/**
153
153
* Invoked when the input value changes. Receives the string value of the
154
154
* input.
155
155
*/
156
- onInputChange : ( text : string , event : ChangeEvent < HTMLInputElement > ) => void ;
156
+ onInputChange ? : ( text : string , event : ChangeEvent < HTMLInputElement > ) => void ;
157
157
/**
158
158
* Invoked when a key is pressed. Receives an event.
159
159
*/
160
- onKeyDown : KeyboardEventHandler < HTMLInputElement > ;
160
+ onKeyDown ? : KeyboardEventHandler < HTMLInputElement > ;
161
161
/**
162
162
* Invoked when menu visibility changes.
163
163
*/
164
- onMenuToggle : ( isOpen : boolean ) => void ;
164
+ onMenuToggle ? : ( isOpen : boolean ) => void ;
165
165
/**
166
166
* Invoked when the pagination menu item is clicked. Receives an event.
167
167
*/
168
- onPaginate : ( event : SelectEvent < HTMLElement > , shownResults : number ) => void ;
168
+ onPaginate ? : ( event : SelectEvent < HTMLElement > , shownResults : number ) => void ;
169
169
/**
170
170
* Whether or not the menu should be displayed. `undefined` allows the
171
171
* component to control visibility, while `true` and `false` show and hide
@@ -181,7 +181,7 @@ export interface TypeaheadProps {
181
181
* Give user the ability to display additional results if the number of
182
182
* results exceeds `maxResults`.
183
183
*/
184
- paginate : boolean ;
184
+ paginate ? : boolean ;
185
185
/**
186
186
* The selected option(s) displayed in the input. Use this prop if you want
187
187
* to control the component via its parent.
@@ -190,6 +190,18 @@ export interface TypeaheadProps {
190
190
selectHint ?: SelectHint ;
191
191
}
192
192
193
+ type OptionalProps < T , K extends keyof T > = Partial < Pick < T , K > > &
194
+ Required < Omit < T , K > > ;
195
+
196
+ /**
197
+ * Most props used internally become "required" since they're given default
198
+ * values.
199
+ */
200
+ export type InternalProps = OptionalProps <
201
+ Required < Omit < TypeaheadProps , 'onChange' > > ,
202
+ 'children' | 'id' | 'open' | 'selected' | 'selectHint'
203
+ > ;
204
+
193
205
export interface TypeaheadState {
194
206
activeIndex : number ;
195
207
activeItem ?: Option ;
@@ -201,8 +213,7 @@ export interface TypeaheadState {
201
213
text : string ;
202
214
}
203
215
204
- export type TypeaheadPropsAndState = Omit < TypeaheadProps , 'onChange' > &
205
- TypeaheadState ;
216
+ export type TypeaheadPropsAndState = InternalProps & TypeaheadState ;
206
217
207
218
export interface TypeaheadChildProps {
208
219
getInputProps : (
0 commit comments