Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
fix(textfield): prevent placeholder styles from collapsing with minif…
Browse files Browse the repository at this point in the history
…iers

PiperOrigin-RevId: 289004779

Co-authored-by: Material Web Copybara Robot <59487319+material-web-copybara@users.noreply.github.com>
  • Loading branch information
asyncLiz and material-web-copybara authored Jan 14, 2020
1 parent 60354c5 commit d07c78d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
6 changes: 4 additions & 2 deletions packages/mdc-floating-label/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ export class MDCFloatingLabel extends MDCComponent<MDCFloatingLabelFoundation> {
addClass: (className) => this.root_.classList.add(className),
removeClass: (className) => this.root_.classList.remove(className),
getWidth: () => estimateScrollWidth(this.root_),
registerInteractionHandler: (evtType, handler) => this.listen(evtType, handler),
deregisterInteractionHandler: (evtType, handler) => this.unlisten(evtType, handler),
registerInteractionHandler: (evtType, handler) =>
this.listen(evtType, handler),
deregisterInteractionHandler: (evtType, handler) =>
this.unlisten(evtType, handler),
};
// tslint:enable:object-literal-sort-keys
return new MDCFloatingLabelFoundation(adapter);
Expand Down
24 changes: 18 additions & 6 deletions packages/mdc-textfield/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -839,14 +839,26 @@
}

@mixin placeholder-color_($color) {
.mdc-text-field__input::placeholder {
@include theme-mixins.prop(color, $color);
// GSS will combine selectors with the same content, and some browsers have a
// CSS quirk where it drops a rule if it does not recognize one of the
// selectors.
// To avoid GSS combining the ::placeholder and :-ms-input-placeholder
// selectors, we wrap them in `@media all`.
// TODO(b/142329051)
@media all {
// ::placeholder needs to be wrapped because IE11 will drop other selectors
// using the same color
.mdc-text-field__input::placeholder {
@include theme-mixins.prop(color, $color);
}
}

// Override the placeholder styles in IE with important rule to improve specificity.
// stylelint-disable-next-line selector-no-vendor-prefix
.mdc-text-field__input:-ms-input-placeholder {
@include theme-mixins.prop(color, $color, $important: true);
@media all {
// :-ms-input-placeholder needs to be wrapped because Firefox will drop
// other selectors using the same color
.mdc-text-field__input:-ms-input-placeholder {
@include theme-mixins.prop(color, $color);
}
}
}

Expand Down
20 changes: 4 additions & 16 deletions packages/mdc-textfield/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,13 @@ import {MDCRippleAdapter} from '@material/ripple/adapter';
import {MDCRipple, MDCRippleFactory} from '@material/ripple/component';
import {MDCRippleFoundation} from '@material/ripple/foundation';
import {MDCRippleCapableSurface} from '@material/ripple/types';
import {
MDCTextFieldAdapter,
MDCTextFieldInputAdapter,
MDCTextFieldLabelAdapter,
MDCTextFieldLineRippleAdapter,
MDCTextFieldOutlineAdapter,
MDCTextFieldRootAdapter,
} from './adapter';
import {
MDCTextFieldCharacterCounter,
MDCTextFieldCharacterCounterFactory,
} from './character-counter/component';

import {MDCTextFieldAdapter, MDCTextFieldInputAdapter, MDCTextFieldLabelAdapter, MDCTextFieldLineRippleAdapter, MDCTextFieldOutlineAdapter, MDCTextFieldRootAdapter,} from './adapter';
import {MDCTextFieldCharacterCounter, MDCTextFieldCharacterCounterFactory,} from './character-counter/component';
import {MDCTextFieldCharacterCounterFoundation} from './character-counter/foundation';
import {cssClasses, strings} from './constants';
import {MDCTextFieldFoundation} from './foundation';
import {
MDCTextFieldHelperText,
MDCTextFieldHelperTextFactory,
} from './helper-text/component';
import {MDCTextFieldHelperText, MDCTextFieldHelperTextFactory,} from './helper-text/component';
import {MDCTextFieldHelperTextFoundation} from './helper-text/foundation';
import {MDCTextFieldIcon, MDCTextFieldIconFactory} from './icon/component';
import {MDCTextFieldFoundationMap} from './types';
Expand Down

0 comments on commit d07c78d

Please sign in to comment.