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.

Ability to set style for each item?

See original GitHub issue

This is a feature request.

I’m trying to create a fontFamily dropdown, something like this (https://nardeas.github.io/react-font-picker/).

react-font-picker 2018-01-18 10-02-42

As you can see, the font family of each item is different, so the user could be able to see each font’s style. But I cannot find a way to achieve this in react-select. Is it possible to set each item’s style? Something like this.

<Select
  name="form-field-name"
  value={value}
  onChange={this.handleChange}
  options={[
    { value: 'one', label: 'One', style={fontFamily: 'Arial'} },
    { value: 'two', label: 'Two', style={fontFamily: 'Times New Roman'} },
  ]}
/>

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
Dror-Barcommented, Jul 7, 2020

It’s a bit tricky, but the documentation covers it in “styles” section. I did it like this:

<Select
styles={{ option: (provided, state) => ({ ...provided, fontFamily: state.value })}}
  name="form-field-name"
  value={value}
  onChange={this.handleChange}
  options={[
    { value: 'Arial', label: 'Arial' },
    { value: 'Times New Roman', label: 'Times New Roman' },
  ]}
/>
0reactions
Dror-Barcommented, Jul 7, 2020

@searene are you sure? because object cannot have a property set with ‘=’, you have to use ‘:’ but even setting it like that did not work for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Applying CSS styles to all elements inside a DIV
This code will apply styles all elements inside .yourWrapperClass. Share.
Read more >
Specificity - CSS: Cascading Style Sheets - MDN Web Docs
Specificity is an algorithm that calculates the weight that is applied to a given CSS declaration. The weight is determined by the number...
Read more >
Style Sheets in HTML documents - W3C
To specify an alternate style sheet, set the rel attribute to "alternate stylesheet" and name the style sheet with the title attribute.
Read more >
Lesson 1: Understanding ID and Class in CSS
Lesson 1: Understanding ID and Class in CSS. Overview. So far you have added style to various elements in your portfolio page, but...
Read more >
Solved with CSS! Logical Styling Based on the Number of ...
You don't have to set all of your logic-based styling rules in JavaScript, ... This post is the third in a series about...
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