This question already has an answer here:
Global outlined override
(1 answer)
Closed 2 years ago.
I have a custom theme in which I'd like to override the border-color of the OutlinedInput component. Anyone has any idea how to override the focused color?
export const defaultTheme = createMuiTheme({
palette: {
primary: {
main: colors.primary,
contrastText: colors.white,
},
...
},
typography: {
...
},
overrides: {
MuiButton: {
outlinedPrimary: {
color: colors.text,
},
},
MuiInput: {
underline: {
'&::before': {
borderBottomColor: colors.grey,
},
'&::after': {
borderBottomColor: colors.greyDark,
}
},
},
MuiOutlinedInput: {
notchedOutline: {
borderColor: colors.grey,
},
}
}
});
Found the solution:
overrides: {
MuiButton: {
outlinedPrimary: {
color: colors.text,
},
},
MuiInput: {
underline: {
'&::before': {
borderBottomColor: colors.grey,
},
'&::after': {
borderBottomColor: colors.greyDark,
}
},
},
MuiOutlinedInput: {
root: {
'&$focused': {
'& $notchedOutline': {
borderColor: colors.greyDark,
},
},
},
notchedOutline: {
borderColor: colors.grey,
},
}
}
Related
Is there a way to map default typography for TextField and all my inputs via theme? I know I can do this
components: {
MuiInput: {
styleOverrides: {
root: {
fontSize: '16px',
lineHeight: '25px'
}
}
},
but I wish to find a way to map it to 'body2'
MuiInput: {
defaultProps: {
typographyProps???: {
variant: 'body2'
}
}
For using body2 font size value in another component, You need to access the theme object's typography property.
Then You will set the MUI TextFiled's font-size equal to that value from the theme object.
import { createTheme } from "#mui/material";
const theme = createTheme({});
theme!.components!.MuiTextField = {
styleOverrides: {
root: {
"& .MuiInputBase-input": {
fontSize: theme.typography.body2.fontSize, // this is the default mui body2 font-size
lineHeight: "25px", // and any other styles you want...
},
},
},
};
And You can change the body2 fontSize when defining the theme object:
const theme = createTheme({
typography: {
body2: {
fontSize: 80,
},
});
theme!.components!.MuiTextField = {
styleOverrides: {
root: {
"& .MuiInputBase-input": {
fontSize: theme.typography.body2.fontSize, // this will be 80px
lineHeight: "25px", // and any other styles you want...
},
},
},
};
EDIT:
If You are not ok with overriding the theme after defining it, You can use this approach:
import { createTheme } from "#mui/material";
const myBody2FontSize = 20px;
const theme = createTheme({
typography: {
body2: {
fontSize: myBody2FontSize,
},
},
components: {
MuiTextField: {
styleOverrides: {
root: {
"& .MuiInputBase-input": {
fontSize: myBody2FontSize , // this is the default mui body2 font-size
lineHeight: "25px", // and any other styles you want...
},
},
},
},
},
});
You could try setting it via classname. Its a bit awkward because an input doesnt actually use Typography internally.
MuiInput: {
defaultProps: {
className: 'MuiTypography-body2'
}
}
Or possibly
MuiTextField: {
defaultProps: {
InputProps: {className: 'MuiTypography-body2' }
}
}
I want to change the hover color to red. Wrote a topic for this element does not respond, how to fix it? it turns out it goes dark by default, I want to change it to another color, for example, red, but it doesn't work
MuiOutlinedInput: {
styleOverrides: {
root: {
"& $notchedOutline": {
borderColor: "#ff0000",
},
"&:hover $notchedOutline": {
borderColor: "#ff0000",
},
"&$focused $notchedOutline": {
borderWidth: 0,
},
},
},
},
import OutlinedInput from "#mui/material/OutlinedInput";
const Search = () => {
return (
<>
<OutlinedInput />
</>
);
};
export default Search;
You can do it like this:
const theme = createTheme({
components: {
MuiOutlinedInput: {
styleOverrides: {
root: {
"&:hover .MuiOutlinedInput-notchedOutline": {
borderColor: "#ff0000"
},
"&.Mui-focused .MuiOutlinedInput-notchedOutline": {
borderColor: "#ff0000"
}
}
}
}
}
});
Working example
$notchedOutline doesn't work for me.
I'm just getting started with MUI, and need help with setting breakpoints of different variants of MUI components.
let theme = createTheme({
components: {
MuiTypography: {
variants: [
{
props: { variant: "login-static-title" },
style: {
fontFamily: "Jack Bold",
textTransform: "uppercase",
fontSize: "2rem",
},
},
{
props: { variant: "login-static-bank-name" },
style: {
fontFamily: "Jack Medium",
textTransform: "uppercase",
},
},
],
},
},
});
export default theme;
However, this works, but I want my different variants to have different breakpoints.
theme.typography.staticLoginTitle = {
fontFamily: "Jack Bold",
textTransform: "uppercase",
[theme.breakpoints.up("sm")]: {
fontSize: "2.5rem",
},
[theme.breakpoints.between("xs", "sm")]: {
fontSize: "1.5rem",
},
};
Thanks in advance.
I am trying to customise my theme for material v5 and I would like to know how I can disable the black border that appears when I hover over the textfield component. This is what I have so far under my custom theme
MuiTextField: {
styleOverrides: {
root: {},
},
defaultProps: {
inputProps: {
style: {
fontSize: '11.8px',
// height: '.85rem',
},
},
},
},
Checkout the documentation at: https://mui.com/material-ui/react-text-field/#customization
import * as React from 'react';
import { alpha, styled } from '#mui/material/styles';
import TextField from '#mui/material/TextField';
const CssTextField = styled(TextField)({
'& label.Mui-focused': {
color: 'green',
},
'& .MuiInput-underline:after': {
borderBottomColor: 'green',
},
'& .MuiOutlinedInput-root': {
'& fieldset': {
borderColor: 'red',
},
'&:hover fieldset': {
borderColor: 'yellow',
},
'&.Mui-focused fieldset': {
borderColor: 'green',
},
},
});
export default function CustomizedInputs() {
return (
<CssTextField label="Custom CSS" id="custom-css-outlined-input" />
);
}
Change your styleOverrides like this:
MuiTextField: {
styleOverrides: {
root: {
"& .MuiOutlinedInput-root": {
"&:hover fieldset": {
borderColor: "rgba(0, 0, 0, 0.23)",
},
"&.Mui-focused fieldset": {
borderColor: "rgba(0, 0, 0, 0.23)",
},
},
},
},
defaultProps: {
inputProps: {
style: {
fontSize: "11.8px",
// height: '.85rem',
},
},
},
},
I have a react setup in which I am using Tailwind and Material-UI. I have a component library in the Storybook which has MUI Theme in it to style the variants like button outline. I am trying to find a way of how can I use these two things to make the react app white-labeled. Basically, Which properties I can set in my theme that it can be directly applied to the components by the user/providers/companies. Currently, my theme looks something like this in the component library.
import { createTheme, ThemeOptions } from '#mui/material/styles';
import { Colours } from '../common';
export const MyThemeOptions: ThemeOptions = {
palette: {
primary: {
main: Colours.primary,
},
secondary: {
main: Colours.secondary,
},
error: {
main: Colours.error,
},
warning: {
main: Colours.warning,
},
info: {
main: Colours.info,
},
success: {
main: Colours.success,
},
},
components: {
MuiButton: {
styleOverrides: {
root: {
borderRadius: '4px',
},
contained: {
padding: '4px 12px',
},
outlined: {
border: '1px solid #bdbdbd',
textTransform: 'none',
minWidth: 0,
color: '#212121',
},
outlinedSizeSmall: {
padding: '2px',
},
outlinedSizeMedium: {
padding: '6px',
},
outlinedSizeLarge: {
padding: '10px'
},
},
},
MuiButtonGroup: {
styleOverrides: {
grouped: {
minWidth: 0,
},
},
},
MuiCard: {
styleOverrides: {
root: {
boxShadow: '0 3px 7px 0 rgba(98, 125, 152, 0.16), 0 0 2px 0 rgba(36, 59, 83, 0.04)',
},
},
},
MuiToggleButton: {
styleOverrides: {
root: {
border: '1px solid #bdbdbd',
borderRadius: '4px',
textTransform: 'none',
color: '#212121',
minWidth: 0,
},
sizeSmall: {
padding: '2px',
},
sizeMedium: {
padding: '6px',
},
sizeLarge: {
padding: '10px',
}
}
}
},
};
const MyTheme = createTheme(MyThemeOptions);
export default MyTheme;
I am not able to find an article or tutorial or something which could lead me in a direction of how can I achieve the white labeling? If you know any knowledge asset in this direction, please share with me. Thank you!