Skip to content

Commit

Permalink
feat(textfield): Use mdc-states mixin and add support for focus shade
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth G. Franqueiro committed Dec 1, 2017
1 parent 3b8ce1b commit 31b1616
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
8 changes: 4 additions & 4 deletions packages/mdc-textfield/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,13 @@ can be controlled by passing a ripple factory argument to the constructor.

```js
const textFieldBoxEl = document.querySelector('.mdc-text-field--box');
const textField = new MDCTextField(textFieldBoxEl, /* foundation */ undefined, (el) => {
// do something with el...
return new MDCRipple(el);
const textField = new MDCTextField(textFieldBoxEl, /* foundation */ undefined, (el, foundation) => {
// Optionally do something with el or foundation...
return new MDCRipple(el, foundation);
});
```

By default the ripple factory simply calls `new MDCRipple(el)` and returns the result.
By default the ripple factory simply calls `new MDCRipple(el, foundation)` and returns the result.

#### MDCTextField API

Expand Down
15 changes: 12 additions & 3 deletions packages/mdc-textfield/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
*/

import MDCComponent from '@material/base/component';
import {MDCRipple} from '@material/ripple';
import {MDCRipple, MDCRippleFoundation} from '@material/ripple';
import {getMatchesProperty} from '@material/ripple/util';


import {cssClasses, strings} from './constants';
import {MDCTextFieldAdapter} from './adapter';
Expand Down Expand Up @@ -63,13 +65,20 @@ class MDCTextField extends MDCComponent {
* creates a new MDCTextFieldBottomLine.
*/
initialize(
rippleFactory = (el) => new MDCRipple(el),
rippleFactory = (el, foundation) => new MDCRipple(el, foundation),
bottomLineFactory = (el) => new MDCTextFieldBottomLine(el)) {
this.input_ = this.root_.querySelector(strings.INPUT_SELECTOR);
this.label_ = this.root_.querySelector(strings.LABEL_SELECTOR);
this.ripple = null;
if (this.root_.classList.contains(cssClasses.BOX)) {
this.ripple = rippleFactory(this.root_);
const MATCHES = getMatchesProperty(HTMLElement.prototype);
const adapter = Object.assign(MDCRipple.createAdapter(this), {
isSurfaceActive: () => this.input_[MATCHES](':active'),
registerInteractionHandler: (type, handler) => this.input_.addEventListener(type, handler),
deregisterInteractionHandler: (type, handler) => this.input_.removeEventListener(type, handler),
});
const foundation = new MDCRippleFoundation(adapter);
this.ripple = rippleFactory(this.root_, foundation);
};
if (!this.root_.classList.contains(cssClasses.TEXTAREA)) {
const bottomLineElement = this.root_.querySelector(strings.BOTTOM_LINE_SELECTOR);
Expand Down
4 changes: 2 additions & 2 deletions packages/mdc-textfield/mdc-text-field.scss
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@

.mdc-text-field--box {
@include mdc-ripple-surface;
@include mdc-ripple-color(black, .04);
@include mdc-states(text-primary-on-light, $has-nested-focusable-element: true);
@include mdc-ripple-radius;
@include mdc-text-field-box-corner-radius($mdc-text-field-border-radius);

Expand All @@ -156,7 +156,7 @@
}

@include mdc-theme-dark(".mdc-text-field", true) {
@include mdc-ripple-color(white, .05);
@include mdc-states(text-primary-on-dark, $has-nested-focusable-element: true);
}

// NOTE: For some reason, stylelint complains that the patterns below don't follow BEM.
Expand Down

0 comments on commit 31b1616

Please sign in to comment.