Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit baa869a

Browse files
crisbetotinayuangao
authored andcommitted
fix(gesture): unable to move text cursor and tap away on mobile (#10821)
* Fixes not being able to move the text cursor within and input on mobile. * Fixes not being able to blur an input by tapping away on mobile. Both of the issues were due to the click hijacking from the gesture service being too aggressive and preventing focus from shifting. Fixes #10301. Fixes #5365.
1 parent fa997b9 commit baa869a

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

src/core/services/gesture/gesture.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,9 @@ function MdGesture($$MdGestureHandler, $$rAF, $timeout) {
104104
maxDistance: maxClickDistance
105105
},
106106
onEnd: function(ev, pointer) {
107-
if (pointer.distance < this.state.options.maxDistance) {
108-
if (canFocus(ev.target)) {
109-
this.dispatchEvent(ev, 'focus', pointer);
110-
ev.target.focus();
111-
}
112-
}
113-
114-
function canFocus(element) {
115-
var focusableElements = ['INPUT', 'SELECT', 'BUTTON', 'TEXTAREA', 'VIDEO', 'AUDIO'];
116-
117-
return (element.getAttribute('tabindex') != '-1') &&
118-
!element.hasAttribute('DISABLED') &&
119-
(element.hasAttribute('tabindex') || element.hasAttribute('href') || element.isContentEditable ||
120-
(focusableElements.indexOf(element.nodeName) != -1));
107+
if (pointer.distance < this.state.options.maxDistance && canFocus(ev.target)) {
108+
this.dispatchEvent(ev, 'focus', pointer);
109+
ev.target.focus();
121110
}
122111
}
123112
});
@@ -550,8 +539,14 @@ function attachToDocument( $mdGesture, $$MdGestureHandler ) {
550539

551540
function mouseInputHijacker(ev) {
552541
var isKeyClick = !ev.clientX && !ev.clientY;
553-
if (!isKeyClick && !ev.$material && !ev.isIonicTap
554-
&& !isInputEventFromLabelClick(ev)) {
542+
543+
if (
544+
!isKeyClick &&
545+
!ev.$material &&
546+
!ev.isIonicTap &&
547+
!isInputEventFromLabelClick(ev) &&
548+
(ev.type !== 'mousedown' || (!canFocus(ev.target) && !canFocus(document.activeElement)))
549+
) {
555550
ev.preventDefault();
556551
ev.stopPropagation();
557552
}
@@ -745,3 +740,18 @@ function getEventPoint(ev) {
745740
(ev.changedTouches && ev.changedTouches[0]) ||
746741
ev;
747742
}
743+
744+
/** Checks whether an element can be focused. */
745+
function canFocus(element) {
746+
return (
747+
!!element &&
748+
element.getAttribute('tabindex') != '-1' &&
749+
!element.hasAttribute('disabled') &&
750+
(
751+
element.hasAttribute('tabindex') ||
752+
element.hasAttribute('href') ||
753+
element.isContentEditable ||
754+
['INPUT', 'SELECT', 'BUTTON', 'TEXTAREA', 'VIDEO', 'AUDIO'].indexOf(element.nodeName) != -1
755+
)
756+
);
757+
}

0 commit comments

Comments
 (0)