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

autocomplete: can't tap outside to close dropdown on mobile #8996

Closed
clshortfuse opened this issue Jul 11, 2016 · 5 comments
Closed

autocomplete: can't tap outside to close dropdown on mobile #8996

clshortfuse opened this issue Jul 11, 2016 · 5 comments
Assignees
Labels
P1: urgent Urgent issues that should be addressed in the next minor or patch release. resolution: duplicate type: gestures

Comments

@clshortfuse
Copy link
Contributor

Actual Behavior:

  • What is the issue? Can't close autocomplete dropdown by touching outside
  • What is the expected behavior? Close autocomplete dropdown by clicking

CodePen (or steps to reproduce the issue): *

Angular Versions: *

  • Angular Version: 1.5.5
  • Angular Material Version: master

Additional Information:

  • Browser Type: * ChromeOS
  • Browser Version: * V52
  • OS: * ChromeOS
  • Stack Traces:

It seems touch events aren't allowed. md-select doesn't have this issue.

@bradrich This might interest you.

@topherfangio topherfangio added the P1: urgent Urgent issues that should be addressed in the next minor or patch release. label Jul 25, 2016
@topherfangio topherfangio added this to the - Backlog milestone Jul 25, 2016
@topherfangio
Copy link
Contributor

@clshortfuse Why don't you go ahead and work on this one too. If you run into trouble, reach out to me and I can assist.

@marlonmleite
Copy link

Someone contains provisional solution?
It's big problem for me.

@donmccurdy
Copy link
Contributor

@marlonmleite – a temporary workaround is discussed in #9581. ($mdGestureProvider.skipClickHijack();).

@clshortfuse
Copy link
Contributor Author

For those that need a workaround and don't want to sacrifice it on all devices, here's what I'm using. Add during your Angular app config phase. :

function hasViewportSet() {
  // https://webkit.org/blog/5610/more-responsive-tapping-on-ios/
  // https://developers.google.com/web/updates/2013/12/300ms-tap-delay-gone-away
  return [].slice.call(document.querySelectorAll("meta[name=viewport]")).some(function(element) {
    var viewportContent = element.getAttribute('content');
    return (viewportContent && viewportContent.split(/,| /).some(function(property) {
      return property.toLowerCase() == 'width=device-width';
    }));
  });
}

function hasMobileUserAgent() {
  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent
  return navigator.userAgent.indexOf('Mobi') !== -1;
}

function hasTabletUserAgent() {
  // https://developer.chrome.com/multidevice/user-agent
  return navigator.userAgent.indexOf('Android') !== -1;
}

function browserDetectsMobileSites() {
  function checkMinVersion(regexMatch, major, minor) {
    if (!regexMatch) return false;
    var splitVersions = regexMatch[1].split('.');
    var parsedMajor = parseInt(splitVersions[0]);
    if (isNaN(parsedMajor) || !parsedMajor || parsedMajor < major) return false;
    if (parsedMajor > major || minor === undefined || minor === null || minor === 0) return true;
    var parsedMinor = parseInt(splitVersions[1]);
    if (isNaN(parsedMinor) || !parsedMinor || parsedMinor < minor) return false;
    return true;
  }
  // Chrome v32+
  if (checkMinVersion(navigator.userAgent.match(/Chrome\/([.0-9]*)/), 32)) return true;

  // AppleWebKit 601.1+
  // Safari versions were reset around iOS 8.0 and are unreliable
  if (checkMinVersion(navigator.userAgent.match(/AppleWebKit\/([.0-9]*)/), 601, 1)) return true;


  // FireFox v27+
  if (checkMinVersion(navigator.userAgent.match(/Firefox\/([.0-9]*)/), 27)) return true;

  // Blackberry v10.3+
  if (navigator.userAgent.indexOf('BB10') !== -1) {
    if (checkMinVersion(navigator.userAgent.match(/Version\/([.0-9]*)/), 10, 3)) return true;
  }
  return false;
}

if ((hasMobileUserAgent() || hasTabletUserAgent()) ? (hasViewportSet() && browserDetectsMobileSites()) : true) {
  $mdGestureProvider.skipClickHijack();
}

@devversion
Copy link
Member

I will merge this issue into #9581 (regardless of the issue number now)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P1: urgent Urgent issues that should be addressed in the next minor or patch release. resolution: duplicate type: gestures
Projects
None yet
Development

No branches or pull requests

7 participants