Skip to content

Commit a017dfe

Browse files
committed
(/^(select|option)$/i).test(e.target.tagName) has been repeated 3 times in the code so I thought it'd be better to export it in its own helper function isSelectOrOption(tagName)
1 parent bab6cad commit a017dfe

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Diff for: js/utils/tap.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ function tapMouseDown(e) {
353353
console.log('mousedown', 'stop event');
354354
e.stopPropagation();
355355

356-
if ((!ionic.tap.isTextInput(e.target) || tapLastTouchTarget !== e.target) && !(/^(select|option)$/i).test(e.target.tagName)) {
356+
if ((!ionic.tap.isTextInput(e.target) || tapLastTouchTarget !== e.target) && !isSelectOrOption(e.target.tagName)) {
357357
// If you preventDefault on a text input then you cannot move its text caret/cursor.
358358
// Allow through only the text input default. However, without preventDefault on an
359359
// input the 300ms delay can change focus on inputs after the keyboard shows up.
@@ -379,7 +379,7 @@ function tapMouseUp(e) {
379379
return false;
380380
}
381381

382-
if (tapIgnoreEvent(e) || (/^(select|option)$/i).test(e.target.tagName)) return false;
382+
if (tapIgnoreEvent(e) || isSelectOrOption(e.target.tagName)) return false;
383383

384384
if (!tapHasPointerMoved(e)) {
385385
tapClick(e);
@@ -434,7 +434,7 @@ function tapTouchEnd(e) {
434434
if (!tapHasPointerMoved(e)) {
435435
tapClick(e);
436436

437-
if ((/^(select|option)$/i).test(e.target.tagName)) {
437+
if (isSelectOrOption(e.target.tagName)) {
438438
e.preventDefault();
439439
}
440440
}
@@ -593,6 +593,10 @@ function tapTargetElement(ele) {
593593
return ele;
594594
}
595595

596+
function isSelectOrOption(tagName){
597+
return (/^(select|option)$/i).test(tagName);
598+
}
599+
596600
ionic.DomUtil.ready(function() {
597601
var ng = typeof angular !== 'undefined' ? angular : null;
598602
//do nothing for e2e tests

0 commit comments

Comments
 (0)