Skip to content

Flow updates #3537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silent-jokes-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-select": patch
---

Fix Flow issues. Refer to the linked PR for more details on the specific issues.
16 changes: 10 additions & 6 deletions packages/react-select/src/Async.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import React, {
Component,
type Config,
type ElementConfig,
type AbstractComponent,
type ElementRef,
Expand All @@ -11,17 +12,20 @@ import { handleInputChange } from './utils';
import manageState from './stateManager';
import type { OptionsType, InputActionMeta } from './types';

export type AsyncProps = {
type DefaultAsyncProps = {|
/* The default set of options to show before the user starts searching. When
set to `true`, the results for loadOptions('') will be autoloaded. */
defaultOptions: OptionsType | boolean,
/* If cacheOptions is truthy, then the loaded data will be cached. The cache
will remain until `cacheOptions` changes value. */
cacheOptions: any,
|};
export type AsyncProps = {
...DefaultAsyncProps,
/* Function that returns a promise, which is the set of options to be used
once the promise resolves. */
loadOptions: (string, (OptionsType) => void) => Promise<*> | void,
/* If cacheOptions is truthy, then the loaded data will be cached. The cache
will remain until `cacheOptions` changes value. */
cacheOptions: any,
onInputChange: (string, InputActionMeta) => void,
onInputChange?: (string, InputActionMeta) => void,
inputValue?: string,
isLoading: boolean
};
Expand All @@ -46,7 +50,7 @@ type State = {

export const makeAsyncSelect = <C: {}>(
SelectComponent: AbstractComponent<C>
): AbstractComponent<C & AsyncProps> =>
): AbstractComponent<C & Config<AsyncProps, DefaultAsyncProps>> =>
class Async extends Component<C & AsyncProps, State> {
static defaultProps = defaultProps;
select: ElementRef<*>;
Expand Down
14 changes: 10 additions & 4 deletions packages/react-select/src/Creatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import React, {
Component,
type Config,
type Node,
type AbstractComponent,
type ElementRef,
Expand All @@ -12,11 +13,13 @@ import type { OptionType, OptionsType, ValueType, ActionMeta } from './types';
import { cleanValue } from './utils';
import manageState from './stateManager';

export type CreatableProps = {|
export type DefaultCreatableProps = {|
/* Allow options to be created while the `isLoading` prop is true. Useful to
prevent the "create new ..." option being displayed while async results are
still being loaded. */
allowCreateWhileLoading: boolean,
/* Sets the position of the createOption element in your options list. Defaults to 'last' */
createOptionPosition: 'first' | 'last',
/* Gets the label for the "create new ..." option in the menu. Is given the
current input value. */
formatCreateLabel: string => Node,
Expand All @@ -26,6 +29,9 @@ export type CreatableProps = {|
/* Returns the data for the new option when it is created. Used to display the
value, and is passed to `onChange`. */
getNewOptionData: (string, Node) => OptionType,
|};
export type CreatableProps = {
...DefaultCreatableProps,
/* If provided, this will be called with the input value when a new option is
created, and `onChange` will **not** be called. Use this when you need more
control over what happens when new options are created. */
Expand All @@ -40,7 +46,7 @@ export type CreatableProps = {|
isLoading?: boolean,
isMulti?: boolean,
onChange: (ValueType, ActionMeta) => void,
|};
};

export type Props = SelectProps & CreatableProps;

Expand Down Expand Up @@ -70,7 +76,7 @@ const builtins = {
}),
};

export const defaultProps = {
export const defaultProps: DefaultCreatableProps = {
allowCreateWhileLoading: false,
createOptionPosition: 'last',
...builtins,
Expand All @@ -83,7 +89,7 @@ type State = {

export const makeCreatableSelect = <C: {}>(
SelectComponent: AbstractComponent<C>
): AbstractComponent<CreatableProps & C> =>
): AbstractComponent<C & Config<CreatableProps, DefaultCreatableProps>> =>
class Creatable extends Component<CreatableProps & C, State> {
static defaultProps = defaultProps;
select: ElementRef<*>;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-select/src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,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 | null,
noOptionsMessage: ({ inputValue: string }) => Node | null,
/* Handle blur events on the control */
onBlur?: FocusEventHandler,
/* Handle change events on the select */
Expand Down
2 changes: 1 addition & 1 deletion packages/react-select/src/components/SingleValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type State = {
};
type ValueProps = {
/** The children to be rendered. */
children: string,
children: React$Node,
/* The data of the selected option rendered in the Single Value component. */
data: any,
/** Props passed to the wrapping element for the group. */
Expand Down