Skip to content

Commit

Permalink
feat(text-field): Added support for text field without label (#4285)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhiomkar committed Jan 29, 2019
1 parent 97a8585 commit bf956fa
Show file tree
Hide file tree
Showing 10 changed files with 476 additions and 7 deletions.
41 changes: 40 additions & 1 deletion packages/mdc-textfield/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ path: /catalog/input-controls/text-field/

## Important - Deprecation Notice

The dense variant of the text field will be removed in an upcoming release.
The dense variant of the text field will be removed in an upcoming release.
See [github issue](https://github.com/material-components/material-components-web/issues/4142) for details.

# Text Field
Expand Down Expand Up @@ -129,6 +129,44 @@ To disable the text field, add the `disabled` attribute to the `<input>` element
</div>
```

### Text Field without label

A text field doesn’t require a label if a separate but clear label indicator is already displayed adjacent to the text field.
Add class name `mdc-text-field--no-label` and remove the label element from the structure.

#### Filled

```html
<div class="mdc-text-field mdc-text-field--no-label">
<input type="text" class="mdc-text-field__input" placeholder="Placeholder text" aria-label="Label">
<div class="mdc-line-ripple"></div>
</div>
```

#### Outlined

```html
<div class="mdc-text-field mdc-text-field--outlined mdc-text-field--no-label">
<input type="text" class="mdc-text-field__input" aria-label="Label">
<div class="mdc-notched-outline">
<div class="mdc-notched-outline__leading"></div>
<div class="mdc-notched-outline__trailing"></div>
</div>
</div>
```

#### Textarea

```html
<div class="mdc-text-field mdc-text-field--textarea mdc-text-field--no-label">
<textarea class="mdc-text-field__input" rows="8" cols="40" aria-label="Label"></textarea>
<div class="mdc-notched-outline">
<div class="mdc-notched-outline__leading"></div>
<div class="mdc-notched-outline__trailing"></div>
</div>
</div>
```

### Text Field with Helper Text

The helper text provides supplemental information and/or validation messages to users. It appears on input field focus
Expand Down Expand Up @@ -187,6 +225,7 @@ CSS Class | Description
`mdc-text-field--with-leading-icon` | Styles the text field as a text field with a leading icon.
`mdc-text-field--with-trailing-icon` | Styles the text field as a text field with a trailing icon.
`mdc-text-field--focused` | Styles the text field as a text field in focus.
`mdc-text-field--no-label` | Styles the text field that has no label.

### Sass Mixins

Expand Down
5 changes: 0 additions & 5 deletions packages/mdc-textfield/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,4 @@
.mdc-floating-label {
@include mdc-floating-label-ink-color($color);
}

// CSS-only version
.mdc-text-field__input::placeholder {
@include mdc-theme-prop(color, $color);
}
}
1 change: 1 addition & 0 deletions packages/mdc-textfield/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ $mdc-text-field-ink-color: rgba(mdc-theme-prop-value(on-surface), .87) !default;
$mdc-text-field-helper-text-color: rgba(mdc-theme-prop-value(on-surface), .6) !default;
$mdc-text-field-icon-color: rgba(mdc-theme-prop-value(on-surface), .54) !default;
$mdc-text-field-focused-label-color: rgba(mdc-theme-prop-value(primary), .87) !default;
$mdc-text-field-placeholder-ink-color: rgba(mdc-theme-prop-value(on-surface), .54) !default;

$mdc-text-field-disabled-label-color: rgba(mdc-theme-prop-value(on-surface), .37) !default;
$mdc-text-field-disabled-ink-color: rgba(mdc-theme-prop-value(on-surface), .37) !default;
Expand Down
20 changes: 19 additions & 1 deletion packages/mdc-textfield/mdc-text-field.scss
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,20 @@
appearance: none;

&::placeholder {
transition: mdc-text-field-transition(color);
transition: mdc-text-field-transition(opacity);
opacity: 0;
color: $mdc-text-field-placeholder-ink-color;
}

// Override the placeholder styles in IE with important rule to improve specificity.
// stylelint-disable-next-line selector-no-vendor-prefix
&:-ms-input-placeholder {
color: $mdc-text-field-placeholder-ink-color !important;
}

// Always show placeholder for text field without label and show only on focused state when label is present.
.mdc-text-field--no-label &::placeholder,
.mdc-text-field--focused &::placeholder {
opacity: 1;
}

Expand All @@ -105,6 +118,11 @@
&:-webkit-autofill {
z-index: auto !important;
}

// Vertically center aligns the text input placeholder and value for only filled variant.
.mdc-text-field--no-label:not(.mdc-text-field--outlined):not(.mdc-text-field--textarea) & {
padding: 16px;
}
}
// stylelint-disable-next-line plugin/selector-bem-pattern
// Move label when text-field gets auto-filled in Chrome.
Expand Down
35 changes: 35 additions & 0 deletions test/screenshot/golden.json
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,15 @@
"desktop_windows_ie@11": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2018/11/21/19_18_38_795/spec/mdc-textfield/classes/baseline-no-js.html.windows_ie_11.png"
}
},
"spec/mdc-textfield/classes/baseline-placeholder.html": {
"public_url": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2019/01/28/23_00_53_388/spec/mdc-textfield/classes/baseline-placeholder.html?utm_source=golden_json",
"screenshots": {
"desktop_windows_chrome@latest": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2019/01/28/23_00_53_388/spec/mdc-textfield/classes/baseline-placeholder.html.windows_chrome_71.png",
"desktop_windows_edge@latest": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2019/01/28/23_00_53_388/spec/mdc-textfield/classes/baseline-placeholder.html.windows_edge_17.png",
"desktop_windows_firefox@latest": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2019/01/28/23_00_53_388/spec/mdc-textfield/classes/baseline-placeholder.html.windows_firefox_64.png",
"desktop_windows_ie@11": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2019/01/28/23_00_53_388/spec/mdc-textfield/classes/baseline-placeholder.html.windows_ie_11.png"
}
},
"spec/mdc-textfield/classes/baseline-trailing-icon.html": {
"public_url": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2018/11/21/19_18_38_795/spec/mdc-textfield/classes/baseline-trailing-icon.html?utm_source=golden_json",
"screenshots": {
Expand All @@ -1383,6 +1392,15 @@
"desktop_windows_ie@11": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2018/11/21/19_18_38_795/spec/mdc-textfield/classes/baseline-trailing-icon.html.windows_ie_11.png"
}
},
"spec/mdc-textfield/classes/baseline-without-label.html": {
"public_url": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2019/01/28/23_00_53_388/spec/mdc-textfield/classes/baseline-without-label.html?utm_source=golden_json",
"screenshots": {
"desktop_windows_chrome@latest": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2019/01/28/23_00_53_388/spec/mdc-textfield/classes/baseline-without-label.html.windows_chrome_71.png",
"desktop_windows_edge@latest": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2019/01/28/23_00_53_388/spec/mdc-textfield/classes/baseline-without-label.html.windows_edge_17.png",
"desktop_windows_firefox@latest": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2019/01/28/23_00_53_388/spec/mdc-textfield/classes/baseline-without-label.html.windows_firefox_64.png",
"desktop_windows_ie@11": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2019/01/28/23_00_53_388/spec/mdc-textfield/classes/baseline-without-label.html.windows_ie_11.png"
}
},
"spec/mdc-textfield/classes/baseline.html": {
"public_url": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2018/11/21/19_18_38_795/spec/mdc-textfield/classes/baseline.html?utm_source=golden_json",
"screenshots": {
Expand Down Expand Up @@ -1518,6 +1536,15 @@
"desktop_windows_ie@11": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2018/11/21/19_18_38_795/spec/mdc-textfield/classes/focused-leading-trailing-icons.html.windows_ie_11.png"
}
},
"spec/mdc-textfield/classes/focused-placeholder.html": {
"public_url": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2019/01/29/15_51_27_987/spec/mdc-textfield/classes/focused-placeholder.html?utm_source=golden_json",
"screenshots": {
"desktop_windows_chrome@latest": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2019/01/29/15_51_27_987/spec/mdc-textfield/classes/focused-placeholder.html.windows_chrome_71.png",
"desktop_windows_edge@latest": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2019/01/29/15_51_27_987/spec/mdc-textfield/classes/focused-placeholder.html.windows_edge_17.png",
"desktop_windows_firefox@latest": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2019/01/29/15_51_27_987/spec/mdc-textfield/classes/focused-placeholder.html.windows_firefox_64.png",
"desktop_windows_ie@11": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2019/01/29/15_51_27_987/spec/mdc-textfield/classes/focused-placeholder.html.windows_ie_11.png"
}
},
"spec/mdc-textfield/classes/focused-trailing-icon.html": {
"public_url": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2018/11/21/19_18_38_795/spec/mdc-textfield/classes/focused-trailing-icon.html?utm_source=golden_json",
"screenshots": {
Expand Down Expand Up @@ -1712,6 +1739,14 @@
"desktop_windows_ie@11": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2018/11/21/19_18_38_795/spec/mdc-textfield/classes/textarea-invalid.html.windows_ie_11.png"
}
},
"spec/mdc-textfield/classes/textarea-without-label.html": {
"public_url": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2019/01/28/23_00_53_388/spec/mdc-textfield/classes/textarea-without-label.html?utm_source=golden_json",
"screenshots": {
"desktop_windows_chrome@latest": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2019/01/28/23_00_53_388/spec/mdc-textfield/classes/textarea-without-label.html.windows_chrome_71.png",
"desktop_windows_firefox@latest": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2019/01/28/23_00_53_388/spec/mdc-textfield/classes/textarea-without-label.html.windows_firefox_64.png",
"desktop_windows_ie@11": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2019/01/28/23_00_53_388/spec/mdc-textfield/classes/textarea-without-label.html.windows_ie_11.png"
}
},
"spec/mdc-textfield/classes/textarea.html": {
"public_url": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2018/11/21/19_18_38_795/spec/mdc-textfield/classes/textarea.html?utm_source=golden_json",
"screenshots": {
Expand Down
100 changes: 100 additions & 0 deletions test/screenshot/spec/mdc-textfield/classes/baseline-placeholder.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<!DOCTYPE html>
<!--
Copyright 2019 Google Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<html lang="en">
<head>
<meta charset="utf-8">
<title>Baseline Text Field Element with Placeholder - MDC Web Screenshot Test</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../../../out/mdc.textfield.css">
<link rel="stylesheet" href="../../../out/mdc.typography.css">
<link rel="stylesheet" href="../../../out/spec/fixture.css">
<link rel="stylesheet" href="../../../out/spec/mdc-textfield/fixture.css">

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-118996389-2"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-118996389-2');
</script>
</head>

<body class="test-container">
<main class="test-viewport test-viewport--mobile">
<div class="test-layout">

<div class="test-cell test-cell--textfield">
<div class="mdc-text-field">
<input type="text" id="filled-text-field" class="mdc-text-field__input test-text-field__input" placeholder="Placeholder text">
<label class="mdc-floating-label" for="filled-text-field">Label</label>
<div class="mdc-line-ripple"></div>
</div>
</div>

<div class="test-cell test-cell--textfield">
<div class="mdc-text-field mdc-text-field--outlined">
<input type="text" id="outlined-text-field" class="mdc-text-field__input test-text-field__input" placeholder="Placeholder text">
<div class="mdc-notched-outline">
<div class="mdc-notched-outline__leading"></div>
<div class="mdc-notched-outline__notch">
<label for="outlined-text-field" class="mdc-floating-label">Label</label>
</div>
<div class="mdc-notched-outline__trailing"></div>
</div>
</div>
</div>

<div class="test-cell test-cell--textfield">
<div class="mdc-text-field">
<input type="text" id="filled-text-field-with-value" class="mdc-text-field__input test-text-field__input" placeholder="Placeholder text" value="Filled value">
<label for="filled-text-field-with-value" class="mdc-floating-label mdc-floating-label--float-above">Label</label>
<div class="mdc-line-ripple"></div>
</div>
</div>

<div class="test-cell test-cell--textfield">
<div class="mdc-text-field mdc-text-field--outlined">
<input type="text" id="outlined-text-field-with-value" class="mdc-text-field__input test-text-field__input" placeholder="Placeholder text" value="Filled value">
<div class="mdc-notched-outline mdc-notched-outline--notched">
<div class="mdc-notched-outline__leading"></div>
<div class="mdc-notched-outline__notch">
<label for="outlined-text-field-with-value" class="mdc-floating-label mdc-floating-label--float-above">Label</label>
</div>
<div class="mdc-notched-outline__trailing"></div>
</div>
</div>
</div>

</div>
</main>

<!-- Automatically provides/replaces `Promise` if missing or broken. -->
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.js"></script>
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fontfaceobserver/2.0.13/fontfaceobserver.standalone.js"></script>
<script src="../../../out/material-components-web.js"></script>
<script src="../../../out/spec/fixture.js"></script>
<script src="../../../out/spec/mdc-textfield/fixture.js"></script>
</body>
</html>
100 changes: 100 additions & 0 deletions test/screenshot/spec/mdc-textfield/classes/baseline-without-label.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<!DOCTYPE html>
<!--
Copyright 2019 Google Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<html lang="en">
<head>
<meta charset="utf-8">
<title>Baseline Text Field Element without Label - MDC Web Screenshot Test</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../../../out/mdc.textfield.css">
<link rel="stylesheet" href="../../../out/mdc.typography.css">
<link rel="stylesheet" href="../../../out/spec/fixture.css">
<link rel="stylesheet" href="../../../out/spec/mdc-textfield/fixture.css">

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-118996389-2"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-118996389-2');
</script>
</head>

<body class="test-container">
<main class="test-viewport test-viewport--mobile">
<div class="test-layout">

<div class="test-cell test-cell--textfield">
<div class="mdc-text-field mdc-text-field--no-label">
<!-- htmllint-disable -->
<input type="text" class="mdc-text-field__input test-text-field__input" placeholder="Placeholder text" aria-label="Label">
<!-- htmllint-enable -->
<div class="mdc-line-ripple"></div>
</div>
</div>

<div class="test-cell test-cell--textfield">
<div class="mdc-text-field mdc-text-field--outlined mdc-text-field--no-label">
<!-- htmllint-disable -->
<input type="text" class="mdc-text-field__input test-text-field__input" placeholder="Placeholder text" aria-label="Label">
<!-- htmllint-enable -->
<div class="mdc-notched-outline">
<div class="mdc-notched-outline__leading"></div>
<div class="mdc-notched-outline__trailing"></div>
</div>
</div>
</div>

<div class="test-cell test-cell--textfield">
<div class="mdc-text-field mdc-text-field--no-label">
<!-- htmllint-disable -->
<input type="text" class="mdc-text-field__input test-text-field__input" value="Filled value" placeholder="Placeholder text" aria-label="Label">
<!-- htmllint-enable -->
<div class="mdc-line-ripple"></div>
</div>
</div>

<div class="test-cell test-cell--textfield">
<div class="mdc-text-field mdc-text-field--outlined mdc-text-field--no-label">
<!-- htmllint-disable -->
<input type="text" class="mdc-text-field__input test-text-field__input" value="Filled value" placeholder="Placeholder text" aria-label="Label">
<!-- htmllint-enable -->
<div class="mdc-notched-outline">
<div class="mdc-notched-outline__leading"></div>
<div class="mdc-notched-outline__trailing"></div>
</div>
</div>
</div>

</div>
</main>

<!-- Automatically provides/replaces `Promise` if missing or broken. -->
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.js"></script>
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fontfaceobserver/2.0.13/fontfaceobserver.standalone.js"></script>
<script src="../../../out/material-components-web.js"></script>
<script src="../../../out/spec/fixture.js"></script>
<script src="../../../out/spec/mdc-textfield/fixture.js"></script>
</body>
</html>
Loading

0 comments on commit bf956fa

Please sign in to comment.