Skip to content

Commit

Permalink
Don't render the menu when messages return null
Browse files Browse the repository at this point in the history
  • Loading branch information
JedWatson committed Jun 27, 2018
1 parent a0adb34 commit 91a7490
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Select.js
Expand Up @@ -129,7 +129,7 @@ export type Props = {
/* Whether to enable search functionality */
isSearchable: boolean,
/* Async: Text to display when loading options */
loadingMessage: ({ inputValue: string }) => string,
loadingMessage: ({ inputValue: string }) => (string | null),
/* Minimum height of the menu before flipping */
minMenuHeight: number,
/* Maximum height of the menu before scrolling */
Expand All @@ -150,7 +150,7 @@ export type Props = {
/* Name of the HTML Input (optional - without this, no input will be rendered) */
name?: string,
/* Text to display when there are no options */
noOptionsMessage: ({ inputValue: string }) => string,
noOptionsMessage: ({ inputValue: string }) => (string | null),
/* Handle blur events on the control */
onBlur?: FocusEventHandler,
/* Handle change events on the select */
Expand Down Expand Up @@ -1387,15 +1387,19 @@ export default class Select extends Component<Props, State> {
}
});
} else if (isLoading) {
const message = loadingMessage({ inputValue });
if (message === null) return null;
menuUI = (
<LoadingMessage {...commonProps}>
{loadingMessage({ inputValue })}
{message}
</LoadingMessage>
);
} else {
const message = noOptionsMessage({ inputValue });
if (message === null) return null;
menuUI = (
<NoOptionsMessage {...commonProps}>
{noOptionsMessage({ inputValue })}
{message}
</NoOptionsMessage>
);
}
Expand Down

0 comments on commit 91a7490

Please sign in to comment.