From 5ea0f3fc47e8bd18fcc8fd3af84fcecc17b3f800 Mon Sep 17 00:00:00 2001 From: Patty RoDee Date: Thu, 21 May 2020 12:47:49 -0700 Subject: [PATCH] fix(snackbar): Use superclass properties without trailing underscores PiperOrigin-RevId: 312722264 --- packages/mdc-snackbar/component.ts | 36 +++++++++++++++-------------- packages/mdc-snackbar/foundation.ts | 34 +++++++++++++-------------- 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/packages/mdc-snackbar/component.ts b/packages/mdc-snackbar/component.ts index fba7f38142c..f52814e9deb 100644 --- a/packages/mdc-snackbar/component.ts +++ b/packages/mdc-snackbar/component.ts @@ -54,17 +54,17 @@ export class MDCSnackbar extends MDCComponent { } initialSyncWithDOM() { - this.surfaceEl_ = this.root_.querySelector(SURFACE_SELECTOR)!; - this.labelEl_ = this.root_.querySelector(LABEL_SELECTOR)!; - this.actionEl_ = this.root_.querySelector(ACTION_SELECTOR)!; + this.surfaceEl_ = this.root.querySelector(SURFACE_SELECTOR)!; + this.labelEl_ = this.root.querySelector(LABEL_SELECTOR)!; + this.actionEl_ = this.root.querySelector(ACTION_SELECTOR)!; - this.handleKeyDown_ = (evt) => this.foundation_.handleKeyDown(evt); + this.handleKeyDown_ = (evt) => this.foundation.handleKeyDown(evt); this.handleSurfaceClick_ = (evt) => { const target = evt.target as Element; if (this.isActionButton_(target)) { - this.foundation_.handleActionButtonClick(evt); + this.foundation.handleActionButtonClick(evt); } else if (this.isActionIcon_(target)) { - this.foundation_.handleActionIconClick(evt); + this.foundation.handleActionIconClick(evt); } }; @@ -79,7 +79,7 @@ export class MDCSnackbar extends MDCComponent { } open() { - this.foundation_.open(); + this.foundation.open(); } /** @@ -88,42 +88,44 @@ export class MDCSnackbar extends MDCComponent { * client-specific values may also be used if desired. */ close(reason = '') { - this.foundation_.close(reason); + this.foundation.close(reason); } getDefaultFoundation() { // DO NOT INLINE this variable. For backward compatibility, foundations take a Partial. // To ensure we don't accidentally omit any methods, we need a separate, strongly typed adapter variable. const adapter: MDCSnackbarAdapter = { - addClass: (className) => this.root_.classList.add(className), + addClass: (className) => this.root.classList.add(className), announce: () => this.announce_(this.labelEl_), - notifyClosed: (reason) => this.emit(CLOSED_EVENT, reason ? {reason} : {}), - notifyClosing: (reason) => this.emit(CLOSING_EVENT, reason ? {reason} : {}), + notifyClosed: (reason) => this.emit( + CLOSED_EVENT, reason ? {reason} : {}), + notifyClosing: (reason) => this.emit( + CLOSING_EVENT, reason ? {reason} : {}), notifyOpened: () => this.emit(OPENED_EVENT, {}), notifyOpening: () => this.emit(OPENING_EVENT, {}), - removeClass: (className) => this.root_.classList.remove(className), + removeClass: (className) => this.root.classList.remove(className), }; return new MDCSnackbarFoundation(adapter); } get timeoutMs(): number { - return this.foundation_.getTimeoutMs(); + return this.foundation.getTimeoutMs(); } set timeoutMs(timeoutMs: number) { - this.foundation_.setTimeoutMs(timeoutMs); + this.foundation.setTimeoutMs(timeoutMs); } get closeOnEscape(): boolean { - return this.foundation_.getCloseOnEscape(); + return this.foundation.getCloseOnEscape(); } set closeOnEscape(closeOnEscape: boolean) { - this.foundation_.setCloseOnEscape(closeOnEscape); + this.foundation.setCloseOnEscape(closeOnEscape); } get isOpen(): boolean { - return this.foundation_.isOpen(); + return this.foundation.isOpen(); } get labelText(): string { diff --git a/packages/mdc-snackbar/foundation.ts b/packages/mdc-snackbar/foundation.ts index a74ea7b1447..a0dc98bbc44 100644 --- a/packages/mdc-snackbar/foundation.ts +++ b/packages/mdc-snackbar/foundation.ts @@ -70,33 +70,33 @@ export class MDCSnackbarFoundation extends MDCFoundation { this.animationFrame_ = 0; clearTimeout(this.animationTimer_); this.animationTimer_ = 0; - this.adapter_.removeClass(OPENING); - this.adapter_.removeClass(OPEN); - this.adapter_.removeClass(CLOSING); + this.adapter.removeClass(OPENING); + this.adapter.removeClass(OPEN); + this.adapter.removeClass(CLOSING); } open() { this.clearAutoDismissTimer_(); this.isOpen_ = true; - this.adapter_.notifyOpening(); - this.adapter_.removeClass(CLOSING); - this.adapter_.addClass(OPENING); - this.adapter_.announce(); + this.adapter.notifyOpening(); + this.adapter.removeClass(CLOSING); + this.adapter.addClass(OPENING); + this.adapter.announce(); // Wait a frame once display is no longer "none", to establish basis for animation this.runNextAnimationFrame_(() => { - this.adapter_.addClass(OPEN); + this.adapter.addClass(OPEN); this.animationTimer_ = setTimeout(() => { const timeoutMs = this.getTimeoutMs(); this.handleAnimationTimerEnd_(); - this.adapter_.notifyOpened(); + this.adapter.notifyOpened(); if (timeoutMs !== numbers.INDETERMINATE) { this.autoDismissTimer_ = setTimeout(() => { this.close(REASON_DISMISS); }, timeoutMs); } - }, numbers.SNACKBAR_ANIMATION_OPEN_TIME_MS); + }, numbers.SNACKBAR_ANIMATION_OPEN_TIME_MS); }); } @@ -116,15 +116,15 @@ export class MDCSnackbarFoundation extends MDCFoundation { this.clearAutoDismissTimer_(); this.isOpen_ = false; - this.adapter_.notifyClosing(reason); - this.adapter_.addClass(cssClasses.CLOSING); - this.adapter_.removeClass(cssClasses.OPEN); - this.adapter_.removeClass(cssClasses.OPENING); + this.adapter.notifyClosing(reason); + this.adapter.addClass(cssClasses.CLOSING); + this.adapter.removeClass(cssClasses.OPEN); + this.adapter.removeClass(cssClasses.OPENING); clearTimeout(this.animationTimer_); this.animationTimer_ = setTimeout(() => { this.handleAnimationTimerEnd_(); - this.adapter_.notifyClosed(reason); + this.adapter.notifyClosed(reason); }, numbers.SNACKBAR_ANIMATION_CLOSE_TIME_MS); } @@ -181,8 +181,8 @@ export class MDCSnackbarFoundation extends MDCFoundation { private handleAnimationTimerEnd_() { this.animationTimer_ = 0; - this.adapter_.removeClass(cssClasses.OPENING); - this.adapter_.removeClass(cssClasses.CLOSING); + this.adapter.removeClass(cssClasses.OPENING); + this.adapter.removeClass(cssClasses.CLOSING); } /**