Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow "valid" placeholders for form inputs #383

Merged
merged 2 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions pug/contents/text_inputs_content.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,46 @@ <h3 class="header">Input fields</h3>
&lt;/form>
&lt;/div>
</code></pre>
<h5>Floating Labels with CSS only</h5>
<p>There should not be any problems with initializing the inputs properly, since the floating Labels are rendered with CSS only. The CSS Technique requires to use an empty placeholder in the HTML. You have to put an emtpy space in the placeholder. Putting an empty string wont work.</p>
<div class="input-field outline">
<input value="Daniel" id="first_name2" type="text" class="validate" placeholder=" ">
<label class="active" for="first_name2">First Name</label>
<h5 id="floating-labels">Floating Labels</h5>
<p>
Since <b>MaterializeCSS v2</b>, floating Labels are rendered with CSS only by default.
However, it is required to use a placeholder with a single white space (" ") in the HTML
(providing an empty string will not work!).
</p>
<p>
<strong><b>Important:</b></strong> If you provide a value different than a single white space,
the CSS rules will treat it as a "important" placeholder value and will always render the
labels in "active" state.
</p>
<div class="row">
<div class="col s12 m6">
<div class="input-field outlined" style="margin: 0 4px;">
<input id="first_name2" type="text" class="validate" placeholder=" ">
<label class="active" for="first_name2">First Name</label>
</div>
</div>
<div class="col s12 m6">
<div class="input-field outlined" style="margin: 0 4px;">
<input id="last_name2" type="text" class="validate" placeholder="Doe...">
<label class="active" for="last_name2">Last Name</label>
</div>
</div>
</div>

<pre><code class="language-markup">
&lt;div class="input-field">
&lt;input value="Daniel" id="first_name2" type="text" class="validate" placeholder=" ">
&lt;label class="active" for="first_name2">First Name&lt;/label>
&lt;div class="row">
&lt;div class="col s12 m6">
&lt;div class="input-field outlined" style="margin: 0 4px;">
&lt;input id="first_name2" type="text" class="validate" placeholder=" ">
&lt;label class="active" for="first_name2">First Name&lt;/label>
&lt;/div>
&lt;/div>
&lt;div class="col s12 m6">
&lt;div class="input-field outlined" style="margin: 0 4px;">
&lt;input id="last_name2" type="text" class="validate" placeholder="Doe...">
&lt;label class="active" for="last_name2">Last Name&lt;/label>
&lt;/div>
&lt;/div>
&lt;/div>
</code></pre>

Expand Down
2 changes: 2 additions & 0 deletions sass/components/forms/_input-fields.scss
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ textarea.materialize-textarea {
color: $input-focus-color;
}
&:focus:not([readonly]) + label,
&:not([placeholder=' ']) + label,
&:not(:placeholder-shown) + label {
//font-size: 12px; // md.sys.typescale.body-small.size
// https://stackoverflow.com/questions/34717492/css-transition-font-size-avoid-jittering-wiggling
Expand Down Expand Up @@ -187,6 +188,7 @@ textarea.materialize-textarea {
color: $input-focus-color;
}
&:focus:not([readonly]) + label,
&:not([placeholder=' ']) + label,
&:not(:placeholder-shown) + label {
top: -8px;
left: 16px;
Expand Down