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.

how to style to react select with Styled Component in easy way

See original GitHub issue

Below is the Code… and I want style the Select which is shown in image

`import React, {Component} from ‘react’; import Select from ‘react-select’; import { Box, Text, Link, Flex } from ‘rebass’;

const options = [ { value: ‘chocolate’, label: ‘Chocolate’ }, { value: ‘strawberry’, label: ‘Strawberry’ }, { value: ‘vanilla’, label: ‘Vanilla’ } ]

class Header extends Component { state = { selectedOption: null, } handleChange = (selectedOption) => { this.setState({ selectedOption }); console.log(Option selected:, selectedOption); } render() { const { selectedOption } = this.state; return ( <Flex width={1} px={2} color='000' bg='white' alignItems='center' > <Select value={selectedOption} onChange={this.handleChange} options={options} />
</Flex> ) } }

export default Header;`

  • image

Issue Analytics

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

github_iconTop GitHub Comments

13reactions
c4bo3lcommented, Feb 26, 2019

@aakhan89 In my case, I have to access the class name in Styled Component. To make it easier, use classNamePrefix to distinct with another react select component. For example

const comp = <Select classNamePrefix={‘Select’}>…</Select>; export default styled(comp)` & .Select__control–is-disabled { background-color: ${props => props.theme.background.color2} !important; border-color: ${props => props.theme.borderColor} !important; }

& .Select__control–is-focused { background-color: ${props => props.theme.background.color2} !important; border: 2px solid ${props => props.theme.background.primary} !important; box-sizing: border-box; }

& .Select__input { color: ${props => props.theme.textColor}; visibility: ${props => !props.value || !isArray(props.value) || !props.maxSelectedItems || props.value.length < props.maxSelectedItems ? ‘visible’ : ‘hidden’}; }

& .Select__dropdown-indicator { display: ${props => !props.value || !isArray(props.value) || !props.maxSelectedItems || props.value.length < props.maxSelectedItems ? ‘flex’ : ‘none’}; }

& .Select__loading-indicator { color: ${props => props.theme.textColor}; }

& .Select__control { background-color: ${props => props.theme.background.color2}; border-color: ${props => props.theme.borderColor}; box-sizing: border-box; & .Select__clear-indicator { visibility: hidden; }

:hover {
  & .Select__clear-indicator {
    visibility: visible;
  }
}

} ’

It’s not an issue, you just need to read the source code.

2reactions
cutterblcommented, Mar 6, 2019

What? Which component of the React-Select, exactly, are you trying to style? It really is not clear above, or I wouldn’t ask.

React-Select uses EmotionJs, under the hood, and you can apply additional styling to any of it’s internal components through the API. There is documentation for this on the site, it just a matter of figuring out which ‘component’ you’re trying to style, and providing the method for it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Styling react-select with styled-components - Stack Overflow
General solution is to make sure to add in the class names with the prop classNamePrefix , then use styled around ReactSelect and...
Read more >
How to style react-select with styled-components or emotion
Styling react -select can be annoying. Here's a quick guide on how to do it with popular CSS-in-JS libraries.
Read more >
Styles - React Select
The recommended way to provide custom styles to react-select is to use the styles ... In the end configuring your custom component with...
Read more >
react-select-styled - CodeSandbox
React from "react"; · ReactDOM from "react-dom"; · styled from "styled-components"; · Select from "react-select"; · "./styles.css"; · options = [ · {...
Read more >
Custom Select Component in React and Styled Components
Create a components directory inside the src folder. And go ahead and create a subfolder inside that named Select. Create an index.js file...
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