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.

Add class to default value component

See original GitHub issue

Hello recently i been working with multi select and needed to highlight the value that had been clicked. I accomplished it by using default Value component as valueComponent and adding class to it. But only way to add class it to mutate props.value. Is there better way to add class to default value component?

Here my code.

import Value from 'react-select/src/Value';

  ValueComponent(props){
    if (props.value.value === this.props.highlighted){
      props.value.className = 'Select-value-highlighted';
    }
    return (<Value {...props}/>);
  }
      <Select
        ...
        valueComponent = {this.ValueComponent}
        />

One other way is to wrap component with div that have class, but this div will be redundant and css will look not so clean.

Also will it be bette if you expose Value directly, so it can be imported like following? `import {Value} from ‘react-select’;``

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
SeanSilkecommented, Sep 13, 2017

@dspoonia7 No I didn’t. I end up with modifying props.value.className as mentioned earlier.

0reactions
bladeycommented, May 27, 2020

Hello -

In an effort to sustain the react-select project going forward, we’re closing old issues / pull requests.

We understand this might be inconvenient but in the best interest of supporting the broader community we have to direct our limited efforts to maintain the latest version.

If you feel this issue / pull request is still relevant and you’d like us to review it, please leave a comment and we’ll do our best to get back to you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

setting default value for react class component state in typescript
There is no way to set a "default value" directly on an interface, you have to do it in the initialization of the...
Read more >
DefaultValueAttribute Class (System.ComponentModel)
You can create a DefaultValueAttribute with any value. A member's default value is typically its initial value. A visual designer can use the...
Read more >
A complete guide to React default props - LogRocket Blog
Cover three ways to implement default props in React and provide default values for props that are not required by the component.
Read more >
Classes - JavaScript - MDN Web Docs
As seen above, the fields can be declared with or without a default value. See public class fields for more information. Private field ......
Read more >
Component field default value | Acquia Cohesion Docs
You can set a default value on your component form element, this is optional. The default value will be used when the Component...
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