Skip to content

Commit

Permalink
fix(icon-button): Use superclass properties without trailing underscores
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 312693330
  • Loading branch information
patrickrodee authored and copybara-github committed May 21, 2020
1 parent da05f66 commit 740860e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
18 changes: 9 additions & 9 deletions packages/mdc-icon-button/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class MDCIconButtonToggle extends MDCComponent<MDCIconButtonToggleFoundat

initialSyncWithDOM() {
this.handleClick = () => {
this.foundation_.handleClick();
this.foundation.handleClick();
};
this.listen('click', this.handleClick);
}
Expand All @@ -58,16 +58,16 @@ export class MDCIconButtonToggle extends MDCComponent<MDCIconButtonToggleFoundat
// 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: MDCIconButtonToggleAdapter = {
addClass: (className) => this.root_.classList.add(className),
hasClass: (className) => this.root_.classList.contains(className),
addClass: (className) => this.root.classList.add(className),
hasClass: (className) => this.root.classList.contains(className),
notifyChange: (evtData) => {
this.emit<MDCIconButtonToggleEventDetail>(
strings.CHANGE_EVENT, evtData);
},
removeClass: (className) => this.root_.classList.remove(className),
getAttr: (attrName) => this.root_.getAttribute(attrName),
removeClass: (className) => this.root.classList.remove(className),
getAttr: (attrName) => this.root.getAttribute(attrName),
setAttr: (attrName, attrValue) =>
this.root_.setAttribute(attrName, attrValue),
this.root.setAttribute(attrName, attrValue),
};
return new MDCIconButtonToggleFoundation(adapter);
}
Expand All @@ -77,15 +77,15 @@ export class MDCIconButtonToggle extends MDCComponent<MDCIconButtonToggleFoundat
}

get on(): boolean {
return this.foundation_.isOn();
return this.foundation.isOn();
}

set on(isOn: boolean) {
this.foundation_.toggle(isOn);
this.foundation.toggle(isOn);
}

private createRipple(): MDCRipple {
const ripple = new MDCRipple(this.root_);
const ripple = new MDCRipple(this.root);
ripple.unbounded = true;
return ripple;
}
Expand Down
24 changes: 12 additions & 12 deletions packages/mdc-icon-button/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,46 +56,46 @@ export class MDCIconButtonToggleFoundation extends MDCFoundation<MDCIconButtonTo
}

init() {
const ariaLabelOn = this.adapter_.getAttr(strings.DATA_ARIA_LABEL_ON);
const ariaLabelOff = this.adapter_.getAttr(strings.DATA_ARIA_LABEL_OFF);
const ariaLabelOn = this.adapter.getAttr(strings.DATA_ARIA_LABEL_ON);
const ariaLabelOff = this.adapter.getAttr(strings.DATA_ARIA_LABEL_OFF);
if (ariaLabelOn && ariaLabelOff) {
if (this.adapter_.getAttr(strings.ARIA_PRESSED) !== null) {
if (this.adapter.getAttr(strings.ARIA_PRESSED) !== null) {
throw new Error(
'MDCIconButtonToggleFoundation: Button should not set ' +
'`aria-pressed` if it has a toggled aria label.');
}

this.hasToggledAriaLabel = true;
} else {
this.adapter_.setAttr(strings.ARIA_PRESSED, String(this.isOn()));
this.adapter.setAttr(strings.ARIA_PRESSED, String(this.isOn()));
}
}

handleClick() {
this.toggle();
this.adapter_.notifyChange({isOn: this.isOn()});
this.adapter.notifyChange({isOn: this.isOn()});
}

isOn(): boolean {
return this.adapter_.hasClass(cssClasses.ICON_BUTTON_ON);
return this.adapter.hasClass(cssClasses.ICON_BUTTON_ON);
}

toggle(isOn: boolean = !this.isOn()) {
// Toggle UI based on state.
if (isOn) {
this.adapter_.addClass(cssClasses.ICON_BUTTON_ON);
this.adapter.addClass(cssClasses.ICON_BUTTON_ON);
} else {
this.adapter_.removeClass(cssClasses.ICON_BUTTON_ON);
this.adapter.removeClass(cssClasses.ICON_BUTTON_ON);
}

// Toggle aria attributes based on state.
if (this.hasToggledAriaLabel) {
const ariaLabel = isOn ?
this.adapter_.getAttr(strings.DATA_ARIA_LABEL_ON) :
this.adapter_.getAttr(strings.DATA_ARIA_LABEL_OFF);
this.adapter_.setAttr(strings.ARIA_LABEL, ariaLabel || '');
this.adapter.getAttr(strings.DATA_ARIA_LABEL_ON) :
this.adapter.getAttr(strings.DATA_ARIA_LABEL_OFF);
this.adapter.setAttr(strings.ARIA_LABEL, ariaLabel || '');
} else {
this.adapter_.setAttr(strings.ARIA_PRESSED, `${isOn}`);
this.adapter.setAttr(strings.ARIA_PRESSED, `${isOn}`);
}
}
}
Expand Down

0 comments on commit 740860e

Please sign in to comment.