new initialValue prop added and it defaults to empty string.
when value prop is present and it has a string value, this means that TypeaheadInput's value is held as a state in the parent and should be controlled by the parent as well. So whenever value changes and it has a string value then we update the TypeaheadInput's state. TypeaheadInput still controls its own state as it has to deal with debouncing.
Removes shouldResetValue prop.
TypeaheadSelect component
typeaheadProps prop is updated to have the following type: Pick<TypeaheadInputProps, "id" | "placeholder" | "name" | "onFocus">. Note how you cannot pass value under this object any longer.
new initialKeyword prop added and it defaults to empty string.
TypeaheadSelect now resets the input value by the default when an option is selected.
new controlledKeyword prop is added. When this prop is present and it has a non-undefined value it means that the keyword is held as a state in the parent and therefore should be controlled by the parent. When this prop is present, TypeaheadSelect never updates its keyword state (a good example of inversion of control).
Stories
Updated Typeahead stories so that each typeahead example holds its own state and not affected by the changes on other typeaheads within the page.
Added an example story about how one can use controlledKeyword.
Changes
TypeaheadInput
componentinitialValue
prop added and it defaults to empty string.value
prop is present and it has a string value, this means that TypeaheadInput's value is held as a state in the parent and should be controlled by the parent as well. So whenever value changes and it has a string value then we update the TypeaheadInput's state. TypeaheadInput still controls its own state as it has to deal with debouncing.shouldResetValue
prop.TypeaheadSelect
componenttypeaheadProps
prop is updated to have the following type:Pick<TypeaheadInputProps, "id" | "placeholder" | "name" | "onFocus">
. Note how you cannot passvalue
under this object any longer.initialKeyword
prop added and it defaults to empty string.controlledKeyword
prop is added. When this prop is present and it has a non-undefined value it means that the keyword is held as a state in the parent and therefore should be controlled by the parent. When this prop is present,TypeaheadSelect
never updates itskeyword
state (a good example of inversion of control).Stories
controlledKeyword
.