[Option] [v2] Adding `data` as an attribute of type `OptionProps`
See original GitHub issueHi, thanks for the great library.
I use react-select
on couple of projects at work and all of our team member love it.
Recently, I ran into a problem when I try to use customising components with react-select
. When I customise / extend Option
component, there is a type error complaining that data
attribute is not available.
For example:
const customComponents = {
Option: props =>
components.Option && (
<components.Option {...props}>
<CustomOption option={props.data} />
</components.Option>
)
};
As I check the type definition for Option
component, I found out the data attribute is not available here:
export type OptionProps = PropsWithStyles &
CommonProps &
State & {
/** The children to be rendered. */
children: Node,
/** Inner ref to DOM Node */
innerRef: InnerRef,
/** props passed to the wrapping element for the group. */
innerProps: InnerProps,
/* Text to be displayed representing the option. */
label: string,
/* Type is used by the menu to determine whether this is an option or a group.
In the case of option this is always `option`. */
type: 'option',
};
I believe the data
attribute should be there, as it’s passed to the Option
component in the implementation here:
return (
<Option {...commonProps} {...props} isFocused={isFocused}>
{this.formatOptionLabel(props.data, 'menu')}
</Option>
);
I reckon we can add the data
attribute to the flow type definition. I am happy to make a PR if required. Once it’s done, I also believe that we can update the Typescript definition in DefintelyTyped here as well.
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (5 by maintainers)
Top GitHub Comments
@sahibjotsaggu, I created one.
I believe this was fixed in https://github.com/JedWatson/react-select/pull/3154, would someone mind closing the issue if so?