This package was introduced to collect and fix all common known issues of Materialize library without removing any features, but rather making them work as expected.
Currently there are few commonly known issues caused by the Materialize:
On iOS, when clicking one select dropdown option, other one is being selected. This issue is caused by the dropdown animation. This package will fix the bug while keeping the dropdown animation.
Select trigger input causes a Lighthouse warning for not having a label or placeholder:
Form elements do not have associated labels
This package will dynamically add a placeholder depending on a selected option value.
When an input is autocompleted by the browser (i.e "username" and "password" fields), the onchange
event for the input is not being triggered and that causes the label element to cover the input even tho it is autocompleted and filled in by the browser. This package will listen to onautocomplete
event and assign .active
class to the label forcing it to move up.
This is not fixed by this package. Use passive-events-support package to resolve it.
yarn add materialize-css-helper
By default, this package will automatically resolve all the in the Known Issues section mentioned issues. It's script will automatically be executed upon DOMContentLoaded
.
Make sure this package is loaded after the Materialize script.
// With JS
import 'materialize-css-helper'
// to pass the custom configuration
import { initMaterializeHelper } from 'materialize-css-helper/src/utils'
initMaterializeHelper({/*...*/})
<!-- With HTML -->
<script>
// if undefined will apply the default configuration
window.materializeHelper = {/*...*/}
</script>
<script type="text/javascript" src="node_modules/materialize-css-helper/dist/main.js"></script>
Every issue fix is optional and has it's toggle option.
Option | Type | Default |
---|---|---|
debug |
boolean |
false |
selectOptions |
boolean |
true |
selectTriggers |
boolean |
true |
autocompletedInputLabels |
boolean |
true |
When enabled, fixed elements will be logged into console.
{
debug: true
}
Console output
[Materialize Helper] Fixed select options
{ options: [
0: Element
1: Element
2: Element
]}
// other logs...
Whether M.Select
element behaviour for iOS should be fixed. See the exact issue to learn more.
{
selectOptions: true // default value
}
In case you prefer a css solution, you can disable the JavaScript fix by passing false
and manually removing the select dropdown animation:
.dropdown-content {
transform: none !important;
}
Whether select trigger input should have a placeholder assigned. See the exact issue to learn more.
{
selectTriggers: true // default value
}
Whether label and input should be marked as filled in when autocompleted. See the exact issue to learn more.
{
autocompletedInputLabels: true // default value
}
Please raise other Materialize caused issues and workarounds, so it could be added to this package.