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.

A more flexible approach to styling react-select ?

See original GitHub issue

Hi !

I like using react-select, but I am less comfortable with the given possibilities to style the component.

We are supposed to include a css stylesheet to make it work. Which leaves us few choices if we want to deeply customize the component :

  • Either overriding stylesheet classes
  • Or setting inline style props on the component

It looks ok for most of the cases, but when we want to customize the component more seriously, things become messy real quick.

What if for instance, we want the component to have a variable width and behave like an autosize input ? (If we set width: auto; to the component, it kind of works but doesn’t make the component fit the whole width of the selected value. – But it might be an other issue on the component styles.

What would be awesome would be to use a BEM approach to define a set of classes respectful to the DOM hierarchy of the component -> Which would be possibly overridden with a “theme” prop.

That would have the good benefit to let users extend styles of the component with css modules, or just using a more clear structure like BEM if he wants to stick with css.

I really like the way react-autowhatever deals with the issue, see : https://github.com/moroshko/react-autosuggest#theme-optional Possibly a good source of inspiration.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:49
  • Comments:33 (6 by maintainers)

github_iconTop GitHub Comments

99reactions
ebrentnelsoncommented, Jun 7, 2017

styled-components with theming please.

87reactions
jole78commented, Jun 8, 2017

It’s already “relative” easy to change the styling by using styled-components as an example.

import React from "react";
import ReactSelect from "react-select";
import styled from 'styled-components';

const MultiSelect = styled(ReactSelect)`
	&.Select--multi  {

		.Select-value {
			display: inline-flex;
			align-items: center;
		}		
	}

	& .Select-placeholder {
		font-size: smaller;
	}
`

export (props) => <MultiSelect multi {...props} />
Read more comments on GitHub >

github_iconTop Results From Across the Web

Styles - React Select
A flexible and beautiful Select Input control for ReactJS with multiselect, autocomplete and ajax support.
Read more >
react-select - npm
Flexible approach to data, with customisable functions; Extensible styling API with emotion; Component Injection API for complete control ...
Read more >
Integrating with Other Libraries - React
This guide will examine some of the more common use cases, focusing on ... If you call it on a <select> DOM node,...
Read more >
How to style react-select component - Stack Overflow
Okay, I got react-select to pick up styling by doing this in form.jsx : import '!style-loader!css-loader!react-select/dist/react-select.css'.
Read more >
react-select-emotionless - npm package - Snyk
Flexible approach to data, with customisable functions; Extensible styling API with emotion; Component Injection API for complete control over the UI behaviour ...
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