question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Option] [v2] Adding `data` as an attribute of type `OptionProps`

See original GitHub issue

Hi, 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:closed
  • Created 5 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
t49trancommented, Sep 17, 2018

@sahibjotsaggu, I created one.

1reaction
IanVScommented, Apr 6, 2019

I believe this was fixed in https://github.com/JedWatson/react-select/pull/3154, would someone mind closing the issue if so?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add custom data- attribute to Option component react-select
It is impossible to add custom attribute data-testid directly to the Option component as i did for Input component. I need to extend...
Read more >
API - React Select
A flexible and beautiful Select Input control for ReactJS with multiselect, autocomplete and ajax support.
Read more >
The HTML Option element - MDN Web Docs - Mozilla
This attribute is text for the label indicating the meaning of the option. If the label attribute isn't defined, its value is that...
Read more >
Forms - React
An input form element whose value is controlled by React in this way is called a “controlled component”. For example, if we want...
Read more >
useListBox – React Aria - React Spectrum Libraries
Label Option 1 Option 2 Option Label Option label Description Description Option 3 Description ... optionProps, DOMAttributes, Props for the option element.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found