Skip to content
This repository has been archived by the owner on Jun 11, 2021. It is now read-only.

Commit

Permalink
feat(core): rename shouldDropdownOpen to shouldDropdownShow
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed Feb 14, 2020
1 parent e035d2c commit f2c3eb2
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,9 @@ Called when the input changes.

This turns experience is "controlled" mode. You'll be in charge of updating the state with the [top-level API](#autocomplete).

#### `shouldDropdownOpen`
#### `shouldDropdownShow`

> `(options: { state: AutocompleteState }) => boolean` | defaults to `({ state }) => state.results.some(result => result.suggestions.length > 0)`
> `(options: { state: AutocompleteState }) => boolean` | defaults to `({ state }) => state.suggestions.some(suggestion => suggestion.items.length > 0)`
Called to check whether the dropdown should open based on the Autocomplete state.

Expand Down
2 changes: 1 addition & 1 deletion packages/autocomplete-core/defaultProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function getDefaultProps<TItem>(
showCompletion: false,
stallThreshold: 300,
environment,
shouldDropdownOpen: ({ state }) => getItemsCount(state) > 0,
shouldDropdownShow: ({ state }) => getItemsCount(state) > 0,
onStateChange: noop,
onSubmit: noop,
...props,
Expand Down
4 changes: 2 additions & 2 deletions packages/autocomplete-core/onInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function onInput<TItem>({
}))
);
setIsOpen(
nextState.isOpen ?? props.shouldDropdownOpen({ state: store.getState() })
nextState.isOpen ?? props.shouldDropdownShow({ state: store.getState() })
);

return;
Expand Down Expand Up @@ -103,7 +103,7 @@ export function onInput<TItem>({
setIsOpen(
nextState.isOpen ??
(query.length >= props.minLength &&
props.shouldDropdownOpen({ state: store.getState() }))
props.shouldDropdownShow({ state: store.getState() }))
);
})
.catch(error => {
Expand Down
4 changes: 2 additions & 2 deletions packages/autocomplete-core/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export interface PublicAutocompleteOptions<TItem> {
/**
* The function called to determine whether the dropdown should open.
*/
shouldDropdownOpen?(options: { state: AutocompleteState<TItem> }): boolean;
shouldDropdownShow?(options: { state: AutocompleteState<TItem> }): boolean;
/**
* The function called when the autocomplete form is submitted.
*/
Expand All @@ -202,6 +202,6 @@ export interface AutocompleteOptions<TItem> {
getSources: GetSources<TItem>;
environment: Environment;
navigator: Navigator<TItem>;
shouldDropdownOpen(options: { state: AutocompleteState<TItem> }): boolean;
shouldDropdownShow(options: { state: AutocompleteState<TItem> }): boolean;
onSubmit(params: EventHandlerParams<TItem>): void;
}

0 comments on commit f2c3eb2

Please sign in to comment.