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

feat(textfield): Use mdc-states mixin and add support for focus shade #1677

Merged
merged 3 commits into from
Dec 5, 2017
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
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, /* MDCTextFieldFoundation */ undefined, (el, foundation) => {
// Optionally do something with the element or the Ripple 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