Fluenui white dropdown color CSS - reactjs

Hello I am trying to configure my dropdown using Fluent ui. But I am unable to achieve current vs expected result.
How do you I configure in order to have a black background when drop down. At the moment my drop-down background is standard white and text normal.
Current:
Expected Result:
My code:
import { Dropdown } from '#fluentui/react/lib/Dropdown';
Inline styling:
const dropdownStyles = (styleProps) => {
const chkStyles = {
title: [{
borderRadius: "5px",
backgroundColor: "transparent",
borderColor: "white",
height: "50px",
width: "100%",
fontSize: 16,
color: "white",
lineHeight: "45px",
}],
dropdown: [{
color: "white",
fontSize: 16,
"&:hover .ms-Dropdown-titleIsPlaceHolder": {
backgroundColor: "transparent",
color: "white",
},
"&:hover .ms-Dropdown-title": {
color: "white",
backgroundColor: "transparent",
borderColor: "white",
},
"&:focus .ms-Dropdown-title": {
color: "white",
},
"&:active .ms-Dropdown-titleIsPlaceHolder": {
color: "white",
},
"&:focus .ms-Dropdown-titleIsPlaceHolder": {
color: "white",
},
}],
"caretDown": {
paddingTop: "10px",
color: "white !important",
},
};
return chkStyles
};
Dropdown:
<Dropdown
componentRef={dropdownRef}
placeholder="Choose a category"
aria-label="choose a category"
title="choose a category"
aria-required="true"
onChange={handleCategory}
value={category}
options={categoryoptions}
calloutProps={{ directionalHintFixed: true }}
styles={dropdownStyles}
type='text'
errorMessage={validationErrors.category ? "Category is required" : undefined}
/>

Related

auto compleate style changes

hey i wanted to know how can i set my auto compleate from mui
to look like google search bar with the round container and round object
itryd this but this not working
const StyledAutocomplete = styled(Autocomplete)({
"& .MuiAutocomplete-inputRoot": {
color: "grey",
backgroundColor: "white",
borderRadius: "100px",
height: "100%",
padding: 5,
"& .MuiOutlinedInput-notchedOutline": {
borderColor: "transparent",
},
"&:hover .MuiOutlinedInput-notchedOutline": {
borderColor: "transparent",
},
"&.Mui-focused .MuiOutlinedInput-notchedOutline": {
borderColor: "transparent",
},
},
"& .MuiOutlinedInput-root": { paddingRight: 10 },
});

How do I change MUI's select background color?

I am struggling with changing MUI's Select background color. I've tried multiple solutions. I've tried changing it from <Select/> className property and it didn't work. Neither did setting it from Menu Prop's. I believe my theme might be causing this problem.
My select component
<Select
variant="standard"
id={id}
native={true}
className={classes.select}
MenuProps={{
sx: {
maxHeight: 200,
},
classes: {
paper: classes.paper,
},
}}
inputProps={{
classes: {
root: classes.root,
},
}}
sx={{
border: errors.installments
? "1px solid rgba(255, 0,0,0.5)"
: "1px solid rgba(0, 0, 0, 0.1)",
borderRadius: 1,
}}
disabled={installments ? false : true}
{...field}
></Select>
The styling sheet
export default makeStyles({
form: {
minWidth: 280,
maxWidth: "45%",
backgroundColor: "rgba(255, 255, 255, 0.1)",
borderColor: "rgba(255, 255, 255, 0.4)",
borderRadius: 1,
},
select: {
padding: 10,
"&:before": {
borderColor: "white",
borderRadius: 5,
content: "''",
},
"&:after": {
borderColor: "rgba(255, 255, 255, 0.7)",
borderRadius: 5,
},
"&:not(.Mui-disabled):hover::before": {
borderColor: "white",
borderRadius: 5,
},
'&:focus':{
backgroundColor: 'red'
}
},
root: {
color: "white",
borderRadius: 1,
},
paper: {
position: "absolute",
overflowY: "auto",
overflowX: "hidden",
// So we see the popover when it's empty.
// It's most likely on issue on userland.
maxHeight: 200,
},
});
The palette defined on the theme
palette: {
mode: "light",
primary: {
main: "#0f9688",
},
secondary: {
main: "#D96098",
},
info: {
main: "#007668",
},
background: {
paper: "#0f9688",
default: "ffffff",
},
},
MuiSelect with green background
You can modify the underlying <MenuList> styles by doing:
<Select
inputProps={{
MenuProps: {
MenuListProps: {
sx: {
backgroundColor: 'red'
}
}
}
}}
>
<Select>
componentsProps={{
listbox: {
sx: {backgroundColor: '#000'}
}
}}
</Select>
You can use the sx prop to change the color of the Select Component.
<Select
sx={{ backgroundColor:'red' }}
labelId="demo-simple-select-label"
id="demo-simple-select"
value={age}
label="Age"
onChange={handleChange}
>

Material UI V4.11.0 - Override Autocomplete nested styles

I'm actually trying to override the input styling for the autocomplete component, I already overrided some of the styles on the theme, but I wasn't able to override the one for the input underline to remove it, on the devtools I found that I have to remove the borderBottom and the content styles but since this is kinda nested nothing that I tried worked:
Actual behavior
Desired behavior
This is what I need
This styles are working:
MuiAutocomplete: {
root: {
paddingLeft: "15px",
paddingRight: "15px",
},
groupLabel: {
fontWeight: 700,
color: "black",
fontSize: 14
},
option: {
paddingTop: "0px",
paddingBottom: "0px",
fontSize: 14,
height: "25px"
}
}
I tried something like this:
MuiAutocomplete: {
input: {
content: "",
borderBottom: "none"
},
inputFocused: {
content: "",
borderBottom: "none"
},
inputRoot: {
content: "",
borderBottom: "none"
},
root: {
paddingLeft: "15px",
paddingRight: "15px",
},
groupLabel: {
fontWeight: 700,
color: "black",
fontSize: 14
},
option: {
paddingTop: "0px",
paddingBottom: "0px",
fontSize: 14,
height: "25px"
}
}
Also tried using the makeStyles with inputRoot, input and inputFocused with no success:
const useStyles = makeStyles(theme => ({
inputRoot: {
"& .MuiInput-underline": {
content: "",
borderButton: "none"
},
"&:before .MuiInput-underline": {
content: "",
borderButton: "none"
},
"&.after ..MuiInput-underline": {
content: "",
borderButton: "none"
}
}
}));
Thanks in advice!
That underline is a pseudo element of the MuiInput-underline not the root input. Furthermore, a pseudo element cannot have a child so this &:before .MuiInput-underline type of syntax won't work
To solve this issue: just reference the generated root class, its descendant should be .MuiInput-underline, with pseudo element before
const useStyles = makeStyles(theme => ({
inputRoot: {
"& .MuiInput-underline:before": {
borderBottom: "none"
}
}
}));
<Autocomplete
renderInput={(params) => <TextField classes={{root: classes.inputRoot}} {...params} label="Combo box" />}
/>

ToggleButtonGroup react material ui

I cant seem to get the ToggleButton selected property from material ui to work on ToggleButton.
I have made a StyledToggleButton as the documentation from Material Ui.
const StyledToggleButton = withStyles({
root: {
fontFamily: 'Arial',
fontSize: '14px',
lineHeight: '20px',
letterSpacing: '0.25',
color: 'rgba(0, 0, 0, 0.87)',
padding: '15px 15px',
textTransform: 'none',
width: '100%',
'&$selected': { //<--this is my attempt as per documentation
color: 'red !important',
backgroundColor: 'red !important',
},
selected: {},
},
})(ToggleButton);
I am using the ToggleButtonGroup and passing ToggleButton as a child.
I have looked at using MuiTheme but i did not understand how to make that work in this example.
here is the rest for reference:
const StyledToggleButton = withStyles({
root: {
fontFamily: 'Arial',
fontSize: '14px',
lineHeight: '20px',
letterSpacing: '0.25',
color: 'rgba(0, 0, 0, 0.87)',
padding: '15px 15px',
textTransform: 'none',
width: '100%',
'&$selected': {
color: 'red !important',
backgroundColor: 'red !important',
},
selected: {},
},
})(ToggleButton);
const StyledGroupButton = withStyles({
root: {
padding: '15px 15px',
width: '100%',
},
})(ToggleButtonGroup);
export default function ObjectViewCard(props) {
const classes = useStyles();
const [alignment, setAlignment] = React.useState('none');
const handleChange = (
event: React.MouseEvent<HTMLElement>,
newAlignment: string,
) => {
setAlignment(newAlignment);
};
const children = [
<StyledToggleButton key={1} value="left">
{props.leftButtonContent}
</StyledToggleButton>,
<StyledToggleButton key={2} value="right">
{props.rightButtonContent}
</StyledToggleButton>,
];
return (
<Card>
<hr className={classes.divider}/>
<div className={`row ${classes.rowContainer}`}>
<div className="col-6">
<span className={classes.header}>Velg visning</span>
</div>
<div className="col-6">
<span className={classes.info}>
<InfoOutlinedIcon className={classes.icon}/> Vis tegnforklaring
</span>
</div>
</div>
<StyledGroupButton value={alignment} exclusive onChange={handleChange}>
{children}
</StyledGroupButton>
</Card>
);
}
```
call it like i did, but selected: {} need to be on same tree-level as root, solution here:
const StyledToggleButton = withStyles({
root: {
fontFamily: 'Arial',
fontSize: '14px',
lineHeight: '20px',
letterSpacing: '0.25px',
color: 'rgba(0, 0, 0, 0.87)',
padding: '15px 15px',
textTransform: 'none',
width: '100%',
'&$selected': {
backgroundColor: 'rgba(33, 137, 214, 0.14)',
color: 'rgb(26, 88, 159)',
'&:hover': {
backgroundColor: 'rgba(33, 137, 214, 0.14)',
color: 'rgb(26, 88, 159)',
},
},
},
selected: {},
})(ToggleButton);

Material-ui Override StepLabel nested property

I want to override the marginTop: 16 property that occurs in this implementation of StepLabel:
label: {
color: theme.palette.text.secondary,
'&$active': {
color: theme.palette.text.primary,
fontWeight: 500,
},
'&$completed': {
color: theme.palette.text.primary,
fontWeight: 500,
},
'&$alternativeLabel': {
textAlign: 'center',
marginTop: 16,
},
'&$error': {
color: theme.palette.error.main,
},
},
So that I get this as the desired outcome:
But I cannot for the life of me figure out how.... here's my implementation:
<StepLabel
classes={{
root: classes.root,
labelContainer: classes.labelContainer,
label: classes.myLabel
}}
>
{this.state.labels[label - 1]}
</StepLabel>
Here's the classes:
const styles = theme => ({
root: {
marginTop: 0,
padding: 0,
"& $alternativeLabel": {
marginTop: 0
}
},
labelContainer: {
backgroundColor: "green",
marginTop: 0,
"& $alternativeLabel": {
marginTop: 0
}
},
myLabel: {
backgroundColor: "red",
marginTop: 0,
"& $alternativeLabel": {
marginTop: 0
}
},
});
The result - the marginTop DOES NOT get overridden. :(
Further information - the property that I want to override:
seems like the way to do it is like this - credit to this answer Material-UI Style Override?
Put an empty alternativeLabel: {} in, so that the property &$alternativeLabel is overridden:
const styles = theme => ({
labelContainer: {
"& $alternativeLabel": {
marginTop: 0
}
},
alternativeLabel: {},
});
and then call it like this in your component:
<StepLabel
classes={{
alternativeLabel: classes.alternativeLabel,
labelContainer: classes.labelContainer
}}
>

Resources