Skip to content

Commit bcbe03c

Browse files
manucorporatadamdbradley
authored andcommitted
fix(icon): isActive="false" with ios mode
fixes #8435
1 parent da62b63 commit bcbe03c

File tree

3 files changed

+77
-31
lines changed

3 files changed

+77
-31
lines changed

src/components/icon/icon.ts

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,10 @@ export class Icon extends Ion {
106106
if (!(/^md-|^ios-|^logo-/.test(val))) {
107107
// this does not have one of the defaults
108108
// so lets auto add in the mode prefix for them
109-
val = this._iconMode + '-' + val;
109+
this._name = this._iconMode + '-' + val;
110+
} else {
111+
this._name = val;
110112
}
111-
this._name = val;
112113
this.update();
113114
}
114115

@@ -161,34 +162,43 @@ export class Icon extends Ion {
161162
* @private
162163
*/
163164
update() {
164-
let css = 'ion-';
165-
166-
this._hidden = (this._name === null);
167-
165+
let name;
168166
if (this._ios && this._iconMode === 'ios') {
169-
css += this._ios;
170-
167+
name = this._ios;
171168
} else if (this._md && this._iconMode === 'md') {
172-
css += this._md;
173-
169+
name = this._md;
174170
} else {
175-
css += this._name;
171+
name = this._name;
176172
}
177-
178-
if (this._iconMode === 'ios' && !this.isActive && css.indexOf('logo') < 0) {
179-
css += '-outline';
173+
let hidden = this._hidden = (name === null);
174+
if (hidden) {
175+
return;
180176
}
181177

182-
if (this._css !== css) {
183-
if (this._css) {
184-
this.setElementClass(this._css, false);
185-
}
186-
this._css = css;
187-
this.setElementClass(css, true);
178+
let iconMode = name.split('-', 2)[0];
179+
if (
180+
iconMode === 'ios' &&
181+
!this.isActive &&
182+
name.indexOf('logo-') < 0 &&
183+
name.indexOf('-outline') < 0) {
184+
name += '-outline';
185+
}
188186

189-
this.setElementAttribute('aria-label',
190-
css.replace('ion-', '').replace('ios-', '').replace('md-', '').replace('-', ' '));
187+
let css = 'ion-' + name;
188+
if (this._css === css) {
189+
return;
190+
}
191+
if (this._css) {
192+
this.setElementClass(this._css, false);
191193
}
194+
this._css = css;
195+
this.setElementClass(css, true);
196+
197+
let label = name
198+
.replace('ios-', '')
199+
.replace('md-', '')
200+
.replace('-', ' ');
201+
this.setElementAttribute('aria-label', label);
192202
}
193203

194204
}

src/components/icon/test/basic/main.html

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,37 @@
1212
<ion-list>
1313

1414
<ion-item>
15-
<ion-icon name="home" item-left [color]="dynamicColor"></ion-icon>
15+
<ion-icon name="home" [color]="dynamicColor" item-left></ion-icon>
1616
<code>
1717
name="home"
1818
</code>
1919
</ion-item>
2020

2121
<ion-item>
22-
<ion-icon [name]="homeIcon" item-left></ion-icon>
22+
<ion-icon name="home" isActive="true" item-left></ion-icon>
2323
<code>
24-
[name]="homeIcon"
24+
name="home" isActive="true"
2525
</code>
2626
</ion-item>
2727

2828
<ion-item>
29-
<ion-icon name="home" isActive="true" item-left></ion-icon>
29+
<ion-icon [name]="homeIcon" [isActive]="isActive" item-left></ion-icon>
3030
<code>
31-
name="home" isActive="true"
31+
[name]="homeIcon" [isActive]="isActive" (false)
3232
</code>
3333
</ion-item>
3434

3535
<ion-item>
36-
<ion-icon name="home" [isActive]="isActive" item-left></ion-icon>
36+
<ion-icon name="md-home" isActive="false" item-left></ion-icon>
3737
<code>
38-
name="home" [isActive]="isActive"
38+
name="md-home" isActive="false"
39+
</code>
40+
</ion-item>
41+
42+
<ion-item>
43+
<ion-icon name="ios-home" isActive="false" item-left></ion-icon>
44+
<code>
45+
name="ios-home" isActive="false"
3946
</code>
4047
</ion-item>
4148

@@ -53,6 +60,13 @@
5360
</code>
5461
</ion-item>
5562

63+
<ion-item>
64+
<ion-icon name="ios-home-outline" isActive="false" item-left></ion-icon>
65+
<code>
66+
name="ios-home-outline" isActive="false"
67+
</code>
68+
</ion-item>
69+
5670
<ion-item>
5771
<ion-icon name="md-home" color="primary" item-left></ion-icon>
5872
<code>
@@ -74,12 +88,34 @@
7488
</code>
7589
</ion-item>
7690

91+
<ion-item>
92+
<ion-icon ios="md-color-filter" md="ios-color-filter" item-left></ion-icon>
93+
<code>
94+
ios="md-color-filter" md="ios-color-filter"
95+
</code>
96+
</ion-item>
97+
98+
<ion-item>
99+
<ion-icon ios="md-color-filter" md="ios-color-filter" isActive="false" item-left></ion-icon>
100+
<code>
101+
ios="md-color-filter" md="ios-color-filter" isActive="false"
102+
</code>
103+
</ion-item>
104+
105+
<ion-item>
106+
<ion-icon item-left></ion-icon>
107+
<code>
108+
name="null"
109+
</code>
110+
</ion-item>
111+
77112
<ion-item detail-push>
78113
<code>
79114
ion-item w/ [detail-push] attr. text text text text text text
80115
</code>
81116
</ion-item>
82117

118+
83119
</ion-list>
84120

85121
<p>

src/components/tabs/test/basic/app-module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ export class Tab3 {
237237
<ion-tab tabTitle="Plain List" tabIcon="star" [root]="root1" (ionSelect)="onSelect($event)"></ion-tab>
238238
<ion-tab tabTitle="Schedule" tabIcon="globe" [root]="root2"></ion-tab>
239239
<ion-tab tabTitle="Stopwatch" tabIcon="logo-facebook" [root]="root3"></ion-tab>
240-
<ion-tab tabTitle="Messages" tabIcon="chatboxes" [root]="root1"></ion-tab>
241-
<ion-tab tabTitle="My Profile" tabIcon="person" [root]="root2"></ion-tab>
240+
<ion-tab tabTitle="Messages" tabIcon="md-chatboxes" [root]="root1"></ion-tab>
241+
<ion-tab tabTitle="My Profile" tabIcon="ios-person" [root]="root2"></ion-tab>
242242
</ion-tabs>
243243
`
244244
})

0 commit comments

Comments
 (0)