Skip to content

Commit

Permalink
fix(snackbar): Use superclass properties without trailing underscores
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 312722264
  • Loading branch information
patrickrodee authored and copybara-github committed May 21, 2020
1 parent b4e2fe9 commit 5ea0f3f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 34 deletions.
36 changes: 19 additions & 17 deletions packages/mdc-snackbar/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ export class MDCSnackbar extends MDCComponent<MDCSnackbarFoundation> {
}

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);
}
};

Expand All @@ -79,7 +79,7 @@ export class MDCSnackbar extends MDCComponent<MDCSnackbarFoundation> {
}

open() {
this.foundation_.open();
this.foundation.open();
}

/**
Expand All @@ -88,42 +88,44 @@ export class MDCSnackbar extends MDCComponent<MDCSnackbarFoundation> {
* 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<MDCFooAdapter>.
// 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<MDCSnackbarCloseEventDetail>(CLOSED_EVENT, reason ? {reason} : {}),
notifyClosing: (reason) => this.emit<MDCSnackbarCloseEventDetail>(CLOSING_EVENT, reason ? {reason} : {}),
notifyClosed: (reason) => this.emit<MDCSnackbarCloseEventDetail>(
CLOSED_EVENT, reason ? {reason} : {}),
notifyClosing: (reason) => this.emit<MDCSnackbarCloseEventDetail>(
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 {
Expand Down
34 changes: 17 additions & 17 deletions packages/mdc-snackbar/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,33 +70,33 @@ export class MDCSnackbarFoundation extends MDCFoundation<MDCSnackbarAdapter> {
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);
});
}

Expand All @@ -116,15 +116,15 @@ export class MDCSnackbarFoundation extends MDCFoundation<MDCSnackbarAdapter> {
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);
}

Expand Down Expand Up @@ -181,8 +181,8 @@ export class MDCSnackbarFoundation extends MDCFoundation<MDCSnackbarAdapter> {

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);
}

/**
Expand Down

0 comments on commit 5ea0f3f

Please sign in to comment.