Skip to content

Commit 51aef91

Browse files
committed
feat(icon-toggle): rename isOn/isOnChange to on/onChange
BREAKING CHANGE: the isOn/isOnChange properties of mdcIconToggle are renamed to on/onChange
1 parent 414f9ba commit 51aef91

File tree

4 files changed

+13
-17
lines changed

4 files changed

+13
-17
lines changed

bundle/src/components/icon-toggle/mdc.icon-toggle.directive.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('MdcIconToggleDirective standalone', () => {
1515
iconOn="favorite"
1616
iconOff="favorite_border"
1717
[disabled]="disabled"
18-
[(isOn)]="favorite"
18+
[(on)]="favorite"
1919
(click)="action()"></i>
2020
`
2121
})
@@ -73,23 +73,23 @@ describe('MdcIconToggleDirective standalone', () => {
7373
const iconToggle = fixture.debugElement.query(By.directive(MdcIconToggleDirective)).injector.get(MdcIconToggleDirective);
7474
const testComponent = fixture.debugElement.injector.get(TestComponent);
7575

76-
expect(iconToggle.isOn).toBe(false); // initial value from 'favorite' property
76+
expect(iconToggle.on).toBe(false); // initial value from 'favorite' property
7777
expect(testComponent.favorite).toBeFalsy(); // not yet initialized, may be undefined or false
7878
expect(iconToggle._elm.nativeElement.textContent).toBe('favorite_border');
7979
expect(iconToggle._elm.nativeElement.getAttribute('aria-label')).toBe('Add to favorites');
8080
expect(iconToggle._elm.nativeElement.getAttribute('aria-pressed')).toBe('false');
8181

8282
iconToggle._elm.nativeElement.click(); tick(); fixture.detectChanges();
8383

84-
expect(iconToggle.isOn).toBe(true);
84+
expect(iconToggle.on).toBe(true);
8585
expect(testComponent.favorite).toBe(true);
8686
expect(iconToggle._elm.nativeElement.textContent).toBe('favorite');
8787
expect(iconToggle._elm.nativeElement.getAttribute('aria-label')).toBe('Remove from favorites');
8888
expect(iconToggle._elm.nativeElement.getAttribute('aria-pressed')).toBe('true');
8989

9090
iconToggle._elm.nativeElement.click(); tick(); fixture.detectChanges();
9191

92-
expect(iconToggle.isOn).toBe(false);
92+
expect(iconToggle.on).toBe(false);
9393
expect(testComponent.favorite).toBe(false);
9494
expect(iconToggle._elm.nativeElement.textContent).toBe('favorite_border');
9595
expect(iconToggle._elm.nativeElement.getAttribute('aria-label')).toBe('Add to favorites');
@@ -106,7 +106,7 @@ describe('MdcIconToggleDirective with MdcIconToggleIconDirective', () => {
106106
iconOn="fa-heart"
107107
iconOff="fa-heart-o"
108108
[disabled]="disabled"
109-
[(isOn)]="like">
109+
[(on)]="like">
110110
<i mdcIconToggleIcon class="fa"></i>
111111
</span>
112112
`

bundle/src/components/icon-toggle/mdc.icon-toggle.directive.ts

+5-9
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ import { AbstractMdcRipple } from '../ripple/abstract.mdc.ripple';
1010
import { AbstractMdcIcon } from '../icon/abstract.mdc.icon';
1111
import { MdcEventRegistry } from '../../utils/mdc.event.registry';
1212

13-
interface MdcIconToggleChangeEvent {
14-
isOn: boolean
15-
}
16-
1713
/**
1814
* Directive for an icon nested inside a <code>MdcIconToggleDirective</code>.
1915
* This directive is only needed when the icon font uses CSS pseudo-elements in order
@@ -49,7 +45,7 @@ export class MdcIconToggleDirective extends AbstractMdcIcon implements AfterCont
4945
* Event emitted when the state of the icon changes (for example when a user clicks
5046
* the icon).
5147
*/
52-
@Output() isOnChange: EventEmitter<boolean> = new EventEmitter();
48+
@Output() onChange: EventEmitter<boolean> = new EventEmitter();
5349
private _onChange: (value: any) => void = (value) => {};
5450
private _onTouched: () => any = () => {};
5551
private _beforeInitQueu: Array<() => any> = [];
@@ -85,9 +81,9 @@ export class MdcIconToggleDirective extends AbstractMdcIcon implements AfterCont
8581
getAttr: (name: string) => this._elm.nativeElement.getAttribute(name),
8682
setAttr: (name: string, value: string) => { this.renderer.setAttribute(this._elm.nativeElement, name, value); },
8783
rmAttr: (name: string) => { this.renderer.removeAttribute(this._elm.nativeElement, name); },
88-
notifyChange: (evtData: MdcIconToggleChangeEvent) => {
84+
notifyChange: (evtData: {isOn: boolean}) => {
8985
this._onChange(evtData.isOn);
90-
this.isOnChange.emit(evtData.isOn);
86+
this.onChange.emit(evtData.isOn);
9187
}
9288
};
9389
private foundation: {
@@ -206,11 +202,11 @@ export class MdcIconToggleDirective extends AbstractMdcIcon implements AfterCont
206202
/**
207203
* The current state of the icon (true for on/pressed, false for off/unpressed).
208204
*/
209-
@Input() get isOn() {
205+
@Input() get on() {
210206
return this.foundation.isOn();
211207
}
212208

213-
set isOn(value: any) {
209+
set on(value: any) {
214210
this.execAfterInit(() => this.foundation.toggle(asBoolean(value)));
215211
}
216212

site/src/app/components/code.sample/code.sample.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ <h3><ng-content select="[bloxSampleTitle]"></ng-content></h3>
1313
labelOff="Show source code"
1414
iconOn="expand_less"
1515
iconOff="expand_more"
16-
[(isOn)]="showCode"
16+
[(on)]="showCode"
1717
title="Show/hide code"></i>
1818
</div>
1919
</div>

site/src/app/components/snippets/directives/snippet.icon-toggle.component.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
iconOn="favorite"
88
iconOff="favorite_border"
99
[disabled]="disabled"
10-
[(isOn)]="favorite"></i>
10+
[(on)]="favorite"></i>
1111
<span>(Value: {{favorite}}. Uses an icon from Material Icons.)</span>
1212
</div>
1313
<div>
@@ -17,7 +17,7 @@
1717
iconOn="fa-thumbs-up"
1818
iconOff="fa-thumbs-o-up"
1919
[disabled]="disabled"
20-
[(isOn)]="like">
20+
[(on)]="like">
2121
<i mdcIconToggleIcon class="fa"></i>
2222
</span>
2323
<span>(Value: {{like}}. Uses an icon from Font Awesome.)</span>

0 commit comments

Comments
 (0)