hi how to change color of arrow icon in react-select
in mouse over in google chrome, I find CSS variable but I cant change color.
this value of CSS css-tlfecz-indicatorContainer.
in my customStyles I wrote this line but not working:
indicatorContainer:base =>({
...base,
color:'#000000'
}),
UPDATE
this is my component I use react-select
import React from 'react';
import Select from 'react-select';
export default function DropDown(props) {
const customStyles = {
control: (base, state) => ({
...base,
background: "#59c5b8",
borderRadius: 0,
}),
menu: base => ({
...base,
// override border radius to match the box
borderRadius: 20,
// kill the gap
marginTop: 0,
}),
menuList: base => ({
...base,
// kill the white space on first and last option
padding: 0
}),
indicatorSeparator: base => ({
...base,
display: 'none'
}),
myDropDown__indicator: base => ({
...base,
'&.myDropDown__dropdown-indicator': {
'&.indicatorContainer': {
color: '#000000'
}
}
}),
'&.indicatorContainer': {
color: '#000000'
}
};
const [selectedOption, setSelectedOption] = React.useState(0);
const handleChange = selectedOption => {
setSelectedOption(selectedOption)
props.parentCallBack(selectedOption)
};
return (
<Select
isSearchable={false}
styles={customStyles}
isOptionDisabled={true}
defaultValue={props.options[0]}
isRtl={true}
onChange={handleChange}
options={props.options}
classNamePrefix='myDropDown'
/>
);
}
Just use customStyles and declare a new colour for dropdownIndicator element:
const customStyles = {
dropdownIndicator: base => ({
...base,
color: "red" // Custom colour
})
};
Here you can find the list of all the elements and here a live example.
Here is how I did it in version 4.3.1
const style = {
dropdownIndicator: (provided) => ({
...provided,
"svg": {
fill: "red"
}
}),
}
return (
<Select options={renderOptions()} styles={style} />
);
This should help:
import React from 'react';
import Select from 'react-select';
export default function DropDown(props) {
const customStyles = {
indicatorsContainer: () => ({
'.myDropDown': {
'&__dropdown-indicator': {
color: 'red' // <--- Color of your choice
}
}
})
};
return (
<Select
styles={customStyles}
classNamePrefix='myDropDown'
/>
);
}
PS Removed non-related code for better understanding. :)
Related
I'm kind of new to React-Select, and after changing its styles the arrow broke, I've spent 3 hours searching for the arrow placement controls to no avail, I've found how to replace it but it doesn't solve the issue, I'm deciding if I should abandon the lib approach and make the dropdown from scratch since the code looks horrendous, I apologize
This is how it currently looks like:
This is how I'm trying to make it behave like:
import Select from "react-select";
interface DropdownV2 {
color?: string[];
options: string[];
name: string;
}
export const DropdownV2: React.FC<DropdownV2> = ({ color, options, name }) => {
let optionsList: any[] = [];
let counter = 0;
options.map((option) => {
if (color) {
optionsList.push({ label: option, value: option });
} else {
optionsList.push({ label: option, value: option });
}
});
return (
<Select
defaultValue={options[0]}
isMulti={false}
placeholder={"Choose " + name}
styles={customStyles}
options={optionsList}
/>
);
};
const customStyles = {
option: (provided: any, state: { isSelected: any }) => ({
...provided,
borderBottom: "1px solid #e9e9e2",
borderLeft: "1px solid #e9e9e2",
borderRight: "1px solid #e9e9e2",
borderRadius: "4px",
color: state.isSelected ? "#290363" : "#150132",
backgroundColor: state.isSelected ? "#e9e9e2" : "white",
cursor: "pointer",
padding: 20,
}),
control: () => ({
// none of react-select's styles are passed to <Control />
width: 200,
}),
menu: (provided: any) => ({
...provided,
border: "1px solid #e9e9e2",
}),
placeholder: (base: any) => ({
...base,
color: "#150132",
fontFamily: "inter",
fontStyle: "normal",
fontWeight: "400",
fontSize: "14px",
lineHeight: "24px",
boxSizing: "border-box",
border: "1px solid #150132",
borderRadius: "4px",
padding: "12px 18px",
gap: "10px",
}),
singleValue: (provided: any, state: { isDisabled: any }) => {
const opacity = state.isDisabled ? 0.5 : 1;
const transition = "opacity 300ms";
const width = "100%";
const height = "50px";
const textAlign = "left";
const fontFamily = "inter";
const fontStyle = "normal";
const fontWeight = "400";
const fontSize = "14px";
const lineHeight = "24px";
const boxSizing = "border-box";
const display = "block";
const flexDirection = "row";
const justifyContent = "space-between";
const alignItems = "center";
const padding = "12px 18px";
const gap = "10px";
const border = "1px solid #150132";
const borderRadius = "4px";
const flex = "none";
const order = "0";
const alignSelf = "stretch";
const flexGrow = "0";
const backgroundPositionX = "244px";
const marginBottom = "10px";
return {
...provided,
opacity,
transition,
border,
width,
height,
textAlign,
padding,
fontFamily,
fontStyle,
fontWeight,
fontSize,
lineHeight,
boxSizing,
display,
flexDirection,
justifyContent,
alignItems,
gap,
borderRadius,
flex,
order,
alignSelf,
flexGrow,
backgroundPositionX,
marginBottom,
};
},
};
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
I provide a custom DropdownIndicator to my react-select.
import React from 'react';
import { components } from 'react-select';
import classnames from 'classnames';
import Icon from '../../../../components/Icon.component';
import styles from '../Select.module.scss';
const DropdownIndicator = ({
className,
selectProps,
...props
}) => (
<components.DropdownIndicator
{...props}
className={classnames(styles.selectIndicator, className)}
selectProps={selectProps}
>
<Icon glyph={`caret-${selectProps.menuIsOpen ? 'up' : 'down'}`} />
</components.DropdownIndicator>
);
You can also change base styling of your component using a custom styles function
export const dropdownIndicatorStyles = (base, state) => {
const { isDisabled } = state;
return {
...base,
...(isDisabled && { display: 'none' }),
};
};
That I then pass it all in to my Select
import DropdownIndicator from './DropdownIndicator';
import {dropdownIndicatorStyles} from './styleFunctions';
// ...
const {components, styles} = useMemo(() => ({
components: {
DropdownIndicator
},
styles: {
dropdownIndicator: dropdownIndicatorStyles
}
}), []);
// ...
<Select components={components} styles={styles} {...otherProps} />
I want to remove the blue outline and box-shadow when the input tag is active.
You need to pass custom styles prop.
Something like this
const customStyles = {
control: (base, state) => ({
...base,
height: "100%",
minHeight: "100%",
border: 0,
boxShadow: "none",
}),
dropdownIndicator: (base, state) => {
return {
...base,
};
},
placeholder: (base, state) => ({
...base,
}),
singleValue: (base, state) => ({
...base,
}),
option: (base, state) => ({
...base,
}),
};
return (
<Select
//REST OF YOUR PROPS
styles={customStyles}
isSearchable={false} //This gets rid of the default cursor
/>
)
Try playing around with the customStyles object to style it further :)
The default styles are derived from a theme object, which you can mutate like styles.
The theme object is available for the styles functions as well.
<Select
label="Single select"
options={user}
theme={theme => ({
...theme,
borderRadius: 'none',
colors: {
...theme.colors,
primary25: 'primary',
primary: 'neutral5',
},
})}
/>
const style = {
control: base => ({
...base,
border: 0,
boxShadow: 'none'
})
};
Old question but the blue outline is a drop-shadow on the input field itself (at least was in my case), I ended up just adding a custom class to the select field like
<ReactSelect
title = { __( 'Title', 'lang' ) }
className = { 'your-custom-class' }
...
and then styling it out with
.your-custom-class input {
box-shadow: none;
}
I'm personalizing the react stripe elements provided by Stripe, but I can't change the font color, the background is working and other styles, but the font color stays on black.
This is my stripe element:
<Grid item md={6}>
<TextField
variant="outlined"
size="small"
required
fullWidth
className={classes.inputStyle}
InputProps={{
inputComponent: StripeInput,
inputProps: {
component: CardCvcElement
},
className: classes.multilineColor
}}
/>
</Grid>
It's styles:
inputFields: {
borderRadius: theme.spacing(1),
backgroundColor: '#000000',
color: '#FFF'
},
multilineColor: {
color: '#FFFFFF'
},
The StripeInput component is this:
function StripeInput ({ component: Component, inputRef, ...props }) {
const elementRef = useRef();
useImperativeHandle(inputRef, () => ({
focus: () => elementRef.current.focus
}));
return (
<Component
onReady={element => (elementRef.current = element)}
style={{
base: {
color: 'green' // The desired result is white, for the example I'm using green but no changes
}
}}
{...props}/>
)
}
export default StripeInput;
The normal text should be displayed with green or white color for example but this is the result:
The text always is displayed black
So I just fixed my issue with the font color, the fix was to add the styles to the Stripe Input component like this:
function StripeInput ({ component: Component, inputRef, ...props }) {
const elementRef = useRef();
useImperativeHandle(inputRef, () => ({
focus: () => elementRef.current.focus
}));
return (
<Component
onReady={element => (elementRef.current = element)}
options={{
style: {
base: {
color: '#FFF'
}
}
}}
{...props}/>
)
}
export default StripeInput;
//Component Style:
const BorderLinearProgress = withStyles(theme => ({
bar: {
borderRadius: 8,
backgroundColor: "red"
}
}))(LinearProgress);
//Component use:
<BorderLinearProgress variant="determinate" value={50} />
I am new to react and material-ui.
In the above code I need to pass or change bar:backgroundColor dynamically.
Please let me know what are the options to do.
Thanks in advance
You can pass your color with the theme variable.
// Passing theme
const useStyles = makeStyles((theme) => ({
bar: props => ({
borderRadius: 8,
backgroundColor: props.color
})
}))
//Using style in component
...
const [progressColor, setProgressColor] = React.useState({ color: 'red' })
const classes = useStyles(progressColor);
// Update color based on your requirements i.e. setProgressColor({color: 'green'}) in some useEffect() when progress crosses some threshold
return (
<LinearProgress color={classes.bar} />
)
...
You can find an example in official docs: https://material-ui.com/styles/basics/#adapting-based-on-props
Below code works fine with dynamic values and colors
const LinearProgressBar: React.FC<ILinearProps> = ({ value, color }) => {
const useStyles = makeStyles({
root: {
height: 10,
borderRadius: 5
},
colorPrimary: {
backgroundColor: '#E9E9E9'
},
bar: {
borderRadius: 5,
backgroundColor: color
}
});
const classes = useStyles();
return (
<LinearProgress
variant="determinate"
value={value}
classes={{
root: classes.root,
colorPrimary: classes.colorPrimary,
bar: classes.bar
}}
/>
);
};
export default LinearProgressBar;
You can do it in two ways:
1). just Write
<LinearProgress style={{backgroundColor: "red"}} variant="determinate" value={50} />
2).
import React from 'react';
import { withStyles } from '#material-ui/core/styles';
const styles = {
LinerProgressColor: {
backgroundColor: 'red',
},
};
function BorderLinearProgress (props) {
return <LinearProgress className={LinerProgressColor} variant="determinate" value={50} />;
}
export default withStyles(styles)(BorderLinearProgress);
I am trying to improve my UI for the react-select. I did some researches online, but I still cannot figure out how to remove the bar in the select.
Can I style the control component to remove the bar? How?
import React from 'react';
import chroma from 'chroma-js';
import { colourOptions } from './docs/data';
import Select from 'react-select';
const dot = (color = '#ccc') => ({
alignItems: 'center',
display: 'flex',
':before': {
backgroundColor: color,
borderRadius: 10,
content: ' ',
display: 'block',
marginRight: 8,
height: 10,
width: 10,
},
});
const colourStyles = {
control: styles => ({ ...styles, backgroundColor: 'white' }),
option: (styles, { data, isDisabled, isFocused, isSelected }) => {
const color = chroma(data.color);
return {
...styles,
backgroundColor: isDisabled
? null
: isSelected ? data.color : isFocused ? color.alpha(0.1).css() : null,
color: isDisabled
? '#ccc'
: isSelected
? chroma.contrast(color, 'white') > 2 ? 'white' : 'black'
: data.color,
cursor: isDisabled ? 'not-allowed' : 'default',
};
},
input: styles => ({ ...styles, ...dot() }),
placeholder: styles => ({ ...styles, ...dot() }),
singleValue: (styles, { data }) => ({ ...styles, ...dot(data.color) }),
};
export default () => (
<Select
defaultValue={colourOptions[2]}
label="Single select"
options={colourOptions}
styles={colourStyles}
/>
);
react-select allows us to control components by doing
components={{
IndicatorSeparator: () => null
}}
For example:
<Select
id="search-commodity"
options={comodityOptions}
components={{
IndicatorSeparator: () => null
}}
/>
The component you are looking to style is indicatorSeparator. For instance, add this to your styles:
indicatorSeparator: (styles) => ({display:'none'})
How did I find this out? I added classNamePrefix to the react-select properties and then used the inspector to see what the class name of the element was.
import Select from "react-select";
export default () => (
<Select
styles={{
indicatorSeparator: () => ({ display: "none" }),
}}
/>
)
You can hide indicatorSeparator with styles prop.
Be aware! Not IndicatorSeparator but indicatorSeparator.