Skip to content

Commit baa04cd

Browse files
committed
feat(active): Removing use of :active in favor of .active for more control of active state
Using the :active pseudo works fine for desktop, but mobile is a completely different beast, especially with the quirks of each platform. By intentionally not using any :active selectors and manually adding/removing a .active class, it gives us a precise control on how the active state works for ALL platforms. Additionally, this places less selectors in the css, and reduces the possibility of unnecessary repaints. Currently this method of using .active instead of :active is being applied to .button and .item elements.
1 parent a3ea027 commit baa04cd

10 files changed

+31
-20
lines changed

Diff for: js/utils/tap.js

+23
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@
175175
var tap = isRecentTap(e);
176176
if(tap) delete tapCoordinates[tap.id];
177177
}, REMOVE_PREVENT_DELAY);
178+
179+
setTimeout(function(){
180+
for(var hitKey in hitElements) {
181+
hitElements[hitKey] && hitElements[hitKey].classList.remove('active');
182+
delete hitElements[hitKey];
183+
}
184+
}, 150);
178185
}
179186

180187
function stopEvent(e){
@@ -197,13 +204,29 @@
197204

198205
function recordStartCoordinates(e) {
199206
startCoordinates = getCoordinates(e);
207+
208+
var x, ele = e.target;
209+
for(x=0; x<5; x++) {
210+
if(!ele || ele.tagName === 'LABEL') break;
211+
if( ele.classList.contains('item') || ele.classList.contains('button') ) {
212+
hitElements[hitCounts] = ele;
213+
hitCounts = (hitCounts > 24 ? 0 : hitCounts + 1);
214+
ionic.requestAnimationFrame(function(){
215+
ele.classList.add('active');
216+
});
217+
break;
218+
}
219+
ele = ele.parentElement;
220+
}
200221
}
201222

202223
var tapCoordinates = {}; // used to remember coordinates to ignore if they happen again quickly
203224
var startCoordinates = {}; // used to remember where the coordinates of the start of the tap
204225
var CLICK_PREVENT_DURATION = 1500; // max milliseconds ghostclicks in the same area should be prevented
205226
var REMOVE_PREVENT_DELAY = 375; // delay after a touchend/mouseup before removing the ghostclick prevent
206227
var HIT_RADIUS = 15;
228+
var hitElements = {};
229+
var hitCounts = 0;
207230

208231
// set global click handler and check if the event should stop or not
209232
document.addEventListener('click', preventGhostClick, true);

Diff for: scss/_action-sheet.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
border-width: 1px 0px 0px 0px;
7070
border-radius: 0;
7171

72-
&.active, &:active {
72+
&.active {
7373
background-color: transparent;
7474
color: inherit;
7575
}

Diff for: scss/_bar.scss

-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@
173173
}
174174
}
175175

176-
&.back-button:active,
177176
&.back-button.active {
178177
opacity: 1;
179178
}

Diff for: scss/_button.scss

+1-2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@
164164
border-color: transparent;
165165
background: none;
166166

167-
&.button:active,
168167
&.button.active {
169168
border-color: transparent;
170169
background: none;
@@ -187,7 +186,7 @@
187186
background: none;
188187
box-shadow: none;
189188

190-
&:active, &.active {
189+
&.active {
191190
opacity: 0.3;
192191
}
193192
}

Diff for: scss/_checkbox.scss

+1-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@
100100
.item-checkbox {
101101
padding-left: ($item-padding * 2) + $checkbox-width;
102102

103-
&.active,
104-
&:active {
103+
&.active {
105104
box-shadow: none;
106105
}
107106
}

Diff for: scss/_form.scss

-6
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,6 @@ textarea {
6868
font-size: 16px;
6969
}
7070

71-
&.item.active,
72-
.ionic-pseudo &.item:active {
73-
border-color: $item-default-border;
74-
background-color: transparent;
75-
}
76-
7771
.button-bar {
7872
@include border-radius(0);
7973
@include flex(1, 0, 220px);

Diff for: scss/_items.scss

+1-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@
9595
}
9696

9797
// Link and Button Active States
98-
.item.active:not(.item-divider):not(.item-input-inset),
99-
.item:active:not(.item-divider):not(.item-input-inset),
98+
.item.active:not(.item-divider):not(.item-input):not(.item-input-inset),
10099
.item-complex.active .item-content {
101100
@include item-active-style($item-default-active-bg, $item-default-active-border);
102101

Diff for: scss/_mixins.scss

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
color: $color;
1313
text-decoration: none;
1414
}
15-
&.active, &:active {
15+
&.active {
1616
background-color: $active-bg-color;
1717
box-shadow: inset 0px 1px 3px rgba(0,0,0,0.15);
1818
border-color: $active-border-color;
@@ -44,7 +44,7 @@
4444
$text-color: $color;
4545
}
4646
color: $text-color;
47-
&.active, &:active {
47+
&.active {
4848
background-color: $color;
4949
color: #fff;
5050
box-shadow: none;

Diff for: scss/_tabs.scss

+1-2
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,7 @@
168168
/* Navigational tab */
169169

170170
/* Active state for tab */
171-
.tab-item.active,
172-
.tab-item:active {
171+
.tab-item.active {
173172
opacity: 1;
174173

175174
&.tab-item-light {

Diff for: scss/_toggle.scss

+1-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@
104104
.item-toggle {
105105
padding-right: ($item-padding * 3) + $toggle-width;
106106

107-
&.active,
108-
&:active {
107+
&.active {
109108
box-shadow: none;
110109
}
111110
}

0 commit comments

Comments
 (0)