-
-
Notifications
You must be signed in to change notification settings - Fork 107
Description
Expected Behavior
Floating labels should work on <input>
elements that do not provide an explicit type attribute. This is because text
is the default value for the type
attribute of <input>
elements as described here: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#type. So essentially,
<input type="text" id="my-text-field">
is equivalent to,
<input id="my-text-field">
Current Behavior
At present, if the type
attribute is missing from <input>
then the the floating labels do not float, they stay within the bounds of the area of the input field where the text typed by the end-user would appear.
Possible Solution
Would the solution be as simple as adding 'input:not([type])'
to TEXT_BASED_INPUT_SELECTOR found here: https://github.com/materializecss/materialize/blob/main/js/forms.js#L2?
I have not tested the above, but I would be happy to test and create a PR if this is an acceptable solution.
Steps to Reproduce
Here is a reproduction of the bug: https://codepen.io/coffeeandwork/pen/dyegXgE.
Two <input>
fields are provided one with an explicit type="text"
attribute and one without. The floating label works for the one with the explicit attribute.
Context
When using https://github.com/terser/html-minifier-terser to minify html, terser removes the explicit type="text"
attributes from the html as a legitimate way to reduce the amount of html content we transport to client browsers. Because of this, using terser with materializecss seems to break floating labels. A workaround at present is to enclose all instances of <input type="text" ...>
within <!-- htmlmin:ignore -->
annotations to indicate to terser not to minify the enclosed html content.
It would be awesome if materializecss worked without needing this workaround.