I came across this recently. If you specify the same styles as wordpress does, but set the values to inherit
, at the same global level then the later CSS rules will take precedence and undo the things the wordpress styles have set. I've added the CSS I ended up with below which does the job for all the material ui components I've used so far.
This does mess the rest of the admin ui up a bit if you include the css on every page, so to work around that I just include the css conditionally:
function my_plugin_admin_scripts() {
if (strpos($current_screen->base, 'myplugin-slug') === false) {
return;
}
$admin_css = 'build/admin.css';
wp_enqueue_style(
'my-plugin-admin',
plugins_url( $admin_css, __FILE__ ),
['wp-components'],
filemtime( "$dir/$admin_css" )
);
}
add_action( 'admin_enqueue_scripts', 'my_plugin_admin_scripts', 10 );
This works for my use case, which is to embed extra screens using material ui within the wordpress admin ui.
button,
input,
select,
textarea {
box-sizing: inherit;
font-family: inherit;
font-size: inherit;
font-weight: inherit;
}
input,
textarea {
font-size: inherit;
}
textarea {
overflow: inheritauto;
padding: inherit;
line-height: inherit;
resize: inherit;
}
label {
cursor: inherit;
}
input,
select {
margin: inherit;
}
textarea.code {
padding: inherit;
}
input[type="color"],
input[type="date"],
input[type="datetime-local"],
input[type="datetime"],
input[type="email"],
input[type="month"],
input[type="number"],
input[type="password"],
input[type="search"],
input[type="tel"],
input[type="text"],
input[type="time"],
input[type="url"],
input[type="week"],
select,
textarea {
border: initial;
padding: initial;
line-height: initial;
min-height: initial;
box-shadow: initial;
border-radius: initial;
background-color: initial;
color: initial;
// .MuiInput-input {
// padding: 4px 0 5px;
// }
}
// redundant
// input[type="date"],
// input[type="datetime-local"],
// input[type="datetime"],
// input[type="email"],
// input[type="month"],
// input[type="number"],
// input[type="password"],
// input[type="search"],
// input[type="tel"],
// input[type="text"],
// input[type="time"],
// input[type="url"],
// input[type="week"] {
// padding: initial;
// line-height: initial;
// min-height: initial;
// }
input[type="checkbox"],
input[type="radio"] {
border: initial;
border-radius: initial;
background: initial;
color: initial;
clear: initial;
cursor: initial;
display: initial;
line-height: initial;
height: initial;
margin: initial;
outline: initial;
padding: initial;
text-align: initial;
vertical-align: initial;
width: initial;
min-width: initial;
box-shadow: initial;
transition: initial;
}
input[type="color"].MuiInput-input,
input[type="date"].MuiInput-input,
input[type="datetime-local"].MuiInput-input,
input[type="datetime"].MuiInput-input,
input[type="email"].MuiInput-input,
input[type="month"].MuiInput-input,
input[type="number"].MuiInput-input,
input[type="password"].MuiInput-input,
input[type="search"].MuiInput-input,
input[type="tel"].MuiInput-input,
input[type="text"].MuiInput-input,
input[type="time"].MuiInput-input,
input[type="url"].MuiInput-input,
input[type="week"].MuiInput-input,
input[type="checkbox"].MuiInput-input,
input[type="radio"].MuiInput-input,
select.MuiInput-input,
textarea.MuiInput-input {
padding: 4px 0 5px;
}
// input.MuiInput-input {
// padding: 4px 0 5px;
// }
div.MuiInputBase-root {
font-family: "Roboto","Helvetica","Arial",sans-serif;
font-weight: 400;
font-size: 1rem;
line-height: 1.4375em;
letter-spacing: 0.00938em;
color: rgba(0, 0, 0, 0.87);
cursor: text;
}
button.MuiPickersDay-root {
line-height: initial;
}
input[type=checkbox]:focus,
input[type=color]:focus,
input[type=date]:focus,
input[type=datetime-local]:focus,
input[type=datetime]:focus,
input[type=email]:focus,
input[type=month]:focus,
input[type=number]:focus,
input[type=password]:focus,
input[type=radio]:focus,
input[type=search]:focus,
input[type=tel]:focus,
input[type=text]:focus,
input[type=time]:focus,
input[type=url]:focus,
input[type=week]:focus,
select:focus,
textarea:focus {
border-color: initial;
box-shadow: initial;
outline: initial;
}
input[type=radio]:checked+label:before {
color: initial;
}
input[type=radio] {
border-radius: initial;
margin-right: initial;
line-height: initial;
}
input[type=checkbox]:checked::before,
input[type=radio]:checked::before {
float: initial;
display: inline-initial;
vertical-align: initial;
width: initial;
speak: initial;
// -webkit-font-smoothing: antialiased;
// -moz-osx-font-smoothing: grayscale
}
input[type=checkbox]:checked::before {
content: initial;
margin: initial;
height: initial;
width: initial;
}
input[type=radio]:checked::before {
content: initial;
border-radius:initial;
width: initial;
height: initial;
margin: initial;
background-color: initial;
line-height: initial;
}
input.readonly,
input[readonly],
textarea.readonly,
textarea[readonly] {
background-color: initial;
}
input.disabled,
input:disabled,
select.disabled,
select:disabled,
textarea.disabled,
textarea:disabled {
background: initial;
border-color: initial;
box-shadow: initial;
color: initial;
}
input[type=file].disabled,
input[type=file]:disabled,
input[type=range].disabled,
input[type=range]:disabled {
background: initial;
box-shadow: initial;
cursor: initial;
}
input[type=checkbox].disabled,
input[type=checkbox].disabled:checked:before,
input[type=checkbox]:disabled,
input[type=checkbox]:disabled:checked:before,
input[type=radio].disabled,
input[type=radio].disabled:checked:before,
input[type=radio]:disabled,
input[type=radio]:disabled:checked:before {
opacity: initial;
}
.z-alert,
.notistack-SnackbarContainer .z-alert
{
z-index: 10000;
}