Skip to content

Commit

Permalink
fix(floating-label): Use superclass properties without trailing under…
Browse files Browse the repository at this point in the history
…scores

PiperOrigin-RevId: 312693498
  • Loading branch information
patrickrodee authored and copybara-github committed May 21, 2020
1 parent cf7747e commit 5cea261
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
14 changes: 7 additions & 7 deletions packages/mdc-floating-label/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,37 +38,37 @@ export class MDCFloatingLabel extends MDCComponent<MDCFloatingLabelFoundation> {
* @param shouldShake If true, shakes the label by adding a CSS class; otherwise, stops shaking by removing the class.
*/
shake(shouldShake: boolean) {
this.foundation_.shake(shouldShake);
this.foundation.shake(shouldShake);
}

/**
* Styles the label to float/dock.
* @param shouldFloat If true, floats the label by adding a CSS class; otherwise, docks it by removing the class.
*/
float(shouldFloat: boolean) {
this.foundation_.float(shouldFloat);
this.foundation.float(shouldFloat);
}

/**
* Styles the label as required.
* @param isRequired If true, adds an asterisk to the label, indicating that it is required.
*/
setRequired(isRequired: boolean) {
this.foundation_.setRequired(isRequired);
this.foundation.setRequired(isRequired);
}

getWidth(): number {
return this.foundation_.getWidth();
return this.foundation.getWidth();
}

getDefaultFoundation() {
// DO NOT INLINE this variable. For backward compatibility, foundations take a Partial<MDCFooAdapter>.
// To ensure we don't accidentally omit any methods, we need a separate, strongly typed adapter variable.
// tslint:disable:object-literal-sort-keys Methods should be in the same order as the adapter interface.
const adapter: MDCFloatingLabelAdapter = {
addClass: (className) => this.root_.classList.add(className),
removeClass: (className) => this.root_.classList.remove(className),
getWidth: () => estimateScrollWidth(this.root_),
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) =>
Expand Down
22 changes: 11 additions & 11 deletions packages/mdc-floating-label/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ export class MDCFloatingLabelFoundation extends MDCFoundation<MDCFloatingLabelAd
}

init() {
this.adapter_.registerInteractionHandler('animationend', this.shakeAnimationEndHandler_);
this.adapter.registerInteractionHandler('animationend', this.shakeAnimationEndHandler_);
}

destroy() {
this.adapter_.deregisterInteractionHandler('animationend', this.shakeAnimationEndHandler_);
this.adapter.deregisterInteractionHandler('animationend', this.shakeAnimationEndHandler_);
}

/**
* Returns the width of the label element.
*/
getWidth(): number {
return this.adapter_.getWidth();
return this.adapter.getWidth();
}

/**
Expand All @@ -76,9 +76,9 @@ export class MDCFloatingLabelFoundation extends MDCFoundation<MDCFloatingLabelAd
shake(shouldShake: boolean) {
const {LABEL_SHAKE} = MDCFloatingLabelFoundation.cssClasses;
if (shouldShake) {
this.adapter_.addClass(LABEL_SHAKE);
this.adapter.addClass(LABEL_SHAKE);
} else {
this.adapter_.removeClass(LABEL_SHAKE);
this.adapter.removeClass(LABEL_SHAKE);
}
}

Expand All @@ -89,10 +89,10 @@ export class MDCFloatingLabelFoundation extends MDCFoundation<MDCFloatingLabelAd
float(shouldFloat: boolean) {
const {LABEL_FLOAT_ABOVE, LABEL_SHAKE} = MDCFloatingLabelFoundation.cssClasses;
if (shouldFloat) {
this.adapter_.addClass(LABEL_FLOAT_ABOVE);
this.adapter.addClass(LABEL_FLOAT_ABOVE);
} else {
this.adapter_.removeClass(LABEL_FLOAT_ABOVE);
this.adapter_.removeClass(LABEL_SHAKE);
this.adapter.removeClass(LABEL_FLOAT_ABOVE);
this.adapter.removeClass(LABEL_SHAKE);
}
}

Expand All @@ -103,15 +103,15 @@ export class MDCFloatingLabelFoundation extends MDCFoundation<MDCFloatingLabelAd
setRequired(isRequired: boolean) {
const {LABEL_REQUIRED} = MDCFloatingLabelFoundation.cssClasses;
if (isRequired) {
this.adapter_.addClass(LABEL_REQUIRED);
this.adapter.addClass(LABEL_REQUIRED);
} else {
this.adapter_.removeClass(LABEL_REQUIRED);
this.adapter.removeClass(LABEL_REQUIRED);
}
}

private handleShakeAnimationEnd_() {
const {LABEL_SHAKE} = MDCFloatingLabelFoundation.cssClasses;
this.adapter_.removeClass(LABEL_SHAKE);
this.adapter.removeClass(LABEL_SHAKE);
}
}

Expand Down

0 comments on commit 5cea261

Please sign in to comment.