@@ -74,39 +74,39 @@ export interface TypeaheadProps {
7474 * If a function is specified, it will be used to determine whether a custom
7575 * option should be included. The return value should be true or false.
7676 */
77- allowNew : AllowNew ;
77+ allowNew ? : AllowNew ;
7878 /**
7979 * Autofocus the input when the component initially mounts.
8080 */
81- autoFocus : boolean ;
81+ autoFocus ? : boolean ;
8282 /**
8383 * Whether or not filtering should be case-sensitive.
8484 */
85- caseSensitive : boolean ;
85+ caseSensitive ? : boolean ;
8686 children ?: TypeaheadChildren ;
8787 /**
8888 * The initial value displayed in the text input.
8989 */
90- defaultInputValue : string ;
90+ defaultInputValue ? : string ;
9191 /**
9292 * Whether or not the menu is displayed upon initial render.
9393 */
94- defaultOpen : boolean ;
94+ defaultOpen ? : boolean ;
9595 /**
9696 * Specify any pre-selected options. Use only if you want the component to
9797 * be uncontrolled.
9898 */
99- defaultSelected : Option [ ] ;
99+ defaultSelected ? : Option [ ] ;
100100 /**
101101 * Either an array of fields in `option` to search, or a custom filtering
102102 * callback.
103103 */
104- filterBy : string [ ] | FilterByCallback ;
104+ filterBy ? : string [ ] | FilterByCallback ;
105105 /**
106106 * Highlights the menu item if there is only one result and allows selecting
107107 * that item by hitting enter. Does not work with `allowNew`.
108108 */
109- highlightOnlyResult : boolean ;
109+ highlightOnlyResult ? : boolean ;
110110 /**
111111 * An html id attribute, required for assistive technologies such as screen
112112 * readers.
@@ -115,57 +115,57 @@ export interface TypeaheadProps {
115115 /**
116116 * Whether the filter should ignore accents and other diacritical marks.
117117 */
118- ignoreDiacritics : boolean ;
118+ ignoreDiacritics ? : boolean ;
119119 inputProps ?: InputProps ;
120120 /**
121121 * Specify the option key to use for display or a function returning the
122122 * display string. By default, the selector will use the `label` key.
123123 */
124- labelKey : LabelKey ;
124+ labelKey ? : LabelKey ;
125125 /**
126126 * Maximum number of results to display by default. Mostly done for
127127 * performance reasons so as not to render too many DOM nodes in the case of
128128 * large data sets.
129129 */
130- maxResults : number ;
130+ maxResults ? : number ;
131131 /**
132132 * Number of input characters that must be entered before showing results.
133133 */
134- minLength : number ;
134+ minLength ? : number ;
135135 /**
136136 * Whether or not multiple selections are allowed.
137137 */
138- multiple : boolean ;
138+ multiple ? : boolean ;
139139 /**
140140 * Invoked when the input is blurred. Receives an event.
141141 */
142- onBlur : FocusEventHandler < HTMLInputElement > ;
142+ onBlur ? : FocusEventHandler < HTMLInputElement > ;
143143 /**
144144 * Invoked whenever items are added or removed. Receives an array of the
145145 * selected options.
146146 */
147- onChange : ( selected : Option [ ] ) => void ;
147+ onChange ? : ( selected : Option [ ] ) => void ;
148148 /**
149149 * Invoked when the input is focused. Receives an event.
150150 */
151- onFocus : FocusEventHandler < HTMLInputElement > ;
151+ onFocus ? : FocusEventHandler < HTMLInputElement > ;
152152 /**
153153 * Invoked when the input value changes. Receives the string value of the
154154 * input.
155155 */
156- onInputChange : ( text : string , event : ChangeEvent < HTMLInputElement > ) => void ;
156+ onInputChange ? : ( text : string , event : ChangeEvent < HTMLInputElement > ) => void ;
157157 /**
158158 * Invoked when a key is pressed. Receives an event.
159159 */
160- onKeyDown : KeyboardEventHandler < HTMLInputElement > ;
160+ onKeyDown ? : KeyboardEventHandler < HTMLInputElement > ;
161161 /**
162162 * Invoked when menu visibility changes.
163163 */
164- onMenuToggle : ( isOpen : boolean ) => void ;
164+ onMenuToggle ? : ( isOpen : boolean ) => void ;
165165 /**
166166 * Invoked when the pagination menu item is clicked. Receives an event.
167167 */
168- onPaginate : ( event : SelectEvent < HTMLElement > , shownResults : number ) => void ;
168+ onPaginate ? : ( event : SelectEvent < HTMLElement > , shownResults : number ) => void ;
169169 /**
170170 * Whether or not the menu should be displayed. `undefined` allows the
171171 * component to control visibility, while `true` and `false` show and hide
@@ -181,7 +181,7 @@ export interface TypeaheadProps {
181181 * Give user the ability to display additional results if the number of
182182 * results exceeds `maxResults`.
183183 */
184- paginate : boolean ;
184+ paginate ? : boolean ;
185185 /**
186186 * The selected option(s) displayed in the input. Use this prop if you want
187187 * to control the component via its parent.
@@ -190,6 +190,18 @@ export interface TypeaheadProps {
190190 selectHint ?: SelectHint ;
191191}
192192
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+
193205export interface TypeaheadState {
194206 activeIndex : number ;
195207 activeItem ?: Option ;
@@ -201,8 +213,7 @@ export interface TypeaheadState {
201213 text : string ;
202214}
203215
204- export type TypeaheadPropsAndState = Omit < TypeaheadProps , 'onChange' > &
205- TypeaheadState ;
216+ export type TypeaheadPropsAndState = InternalProps & TypeaheadState ;
206217
207218export interface TypeaheadChildProps {
208219 getInputProps : (
0 commit comments