-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Buttons need to be tapped twice in order to fire the click event (iOS) #1316
Comments
Is the problem the same in Chrome for iOS? |
Same with Chrome on iOS. |
I can confirm the same experience iPhone 6s, IOS 10, Mobile Safari - The first tap highlights the button. The second tap fires the click event. |
I see the same, but only for md-icon-button. |
+1, md-icon-button (sidenav toggle) needs two taps to open the sidenav on Safari, iOS 10, iPad |
One workaround (maybe a not bad solution) is to have a CSS media query that removes the hover change(s) on mobile devices. In that case there will be no reason for the mobile browsers to fire the hover changes first. |
@mfodor How to do that? |
@sunshineo The following worked for me... Download a build of Modernizr link to a build. The most important step is to include the 'Touch Events' browser feature. My {
"minify": true,
"classPrefix": "mod-",
"options": [
"setClasses"
],
"feature-detects": [
"test/touchevents"
]
} Then, tell SystemJS or Webpack where to find the generated modernizr.js file. In my Angular2 component that contains my [md-icon-button] for my sidenav I define the following SCSS selectors. // using Modernizer CSS classes to detect if browser supports the W3C Touch Events API
:host-context(.mod-touchevents) [md-button]:hover::after, [md-icon-button]:hover::after {
content: none;
} |
@sunshineo Here is a Plunkr showing my idea. It's without having a 3rdparty like modernizr, however, I can encourage you to use that. Also my solution is too simple so it not recognizes whether it's a touch device or just a really narrow window on a PC. So @pcwa-ahendricks 's solution looks much better. |
Found a blog post explaining the issue |
Thank you @mfodor . Actually @pcwa-ahendricks 's solution is too complicated for me. |
md-raised-button fires on a single click on iOS chrome/safari. |
@crisbeto do you have an iOS device to investigate this? |
@jelbourn, as @pcwa-ahendricks mentioned, this is due to the hover effect on the buttons. Touch devices trigger the hover styles on the first tap and then do the click handler on the second one. The way I've dealt with this before is similar to @pcwa-ahendricks. We can have a @mixin hover() {
.md-no-touch &:hover {
@content;
}
}
.md-button {
@include hover {
// hover styles
}
} We should keep in mind that this will add some bloat and will increase the specificity on the hover selectors. |
@crisbeto Are you saying end user should have these css code? I hope there is a way to make this project just not have this problem on touch device. |
Nope, I'm suggesting how we could solve it in Material. |
I've confirmed that this issue started with iOS 10. 9.3 did not have this problem. |
Improves the tap responsiveness of buttons on mobile by replacing the `::after` overlay with a DOM node that prevents the default touch action. Previously, the `::after` overlay would capture the first tap, causing the button to have to tapped twice in order to fire it's click handler. Fixes angular#1316.
* fix(button): improved tap responsiveness on mobile Improves the tap responsiveness of buttons on mobile by replacing the `::after` overlay with a DOM node that prevents the default touch action. Previously, the `::after` overlay would capture the first tap, causing the button to have to tapped twice in order to fire it's click handler. Fixes #1316.
Which version will this fix be in? |
I wasn't able to reproduce it @MetaVurt. I tried both the exact same HTML as yours (aside from pointing it to a different URL) and one that triggers an alert on tap. Can you post an example of something that doesn't work as expected? You can use this as a template. |
@crisbeto - ah ok, interesting! And yes, I can; I am on west coast, US (GMT -8). I will try my best to post something this evening. |
I'm having the same problem with md-icon-button and md-raised-button. Using material 2.0.0-beta.2 in Chrome on iPhone 6s iOs 10.2.1 in a fresh angular-cli project. First tap highlights, second tap actually taps but only if immediately after the first tap. |
I'm building a separate, simple app right now to show test case, and associated build steps for others to test/reproduce. 60 minutes I will post repo and link to live url. |
@crisbeto - sorry for the delay. I just did a quick build using a brand new -cli initialized base, and adding in bare bones navigation with icons. Just tested in Chrome on iOS 10.1 and the double tap is still necessary to get page(s) to load. First tap shows the overlay, second tap resolves the route. Also, I just built this without using your suggested template - apologies for that; was just trying to put up something quickly and my personal domain is easy for that. @mm420admin, thank you for listing which iOS you are using; that helps! @sunshineo, can you please show us how or what you may or may not have done in order to get it working? Current top level modules:
To reproduceEasy way: grab the repo from here, which is visible at http://www.weo3.com/howdyPlease correct me if I am misusing Material Design. I do recognize that the flat buttons are not necessarily for use with md-icon, however, I do not believe this is the reason for the weird double tap necessity on mobile view. FWIW, I use the flat icons because I do not want circular buttons in any part of my apps, and it was easy implementing icons within flat than it was to negate the circular affect. Let me know if there is anything else I can do to help clarify or test! |
I think it has something to do with how iOs handles css :hover and :hover::after, but I can't seem to work around it. |
@mm420admin - I did not post this earlier, as I would like to maintain focus on resolving it in the package, but I do have a workaround for you. In this css, (which comes from my testing repository) –
– the first batch of code is just styling; but after, "the below makes the difference" it is the Being able to use I hope that helps. |
@MetaVurt your workaround does the trick for now, thanks for that. For anyone else interested, @MetaVurt's workaround amounted to adding
to my main css file. I'll keep my eye out for the real fix. |
Thanks for the repro case @MetaVurt. I still can't reproduce it against our demo app with the exact same styling that you provided, but I can reproduce it by running your example locally. It looks like the Also FYI, the |
Awesome, thanks for the feedback, @crisbeto! And derp on me with the So the url I provided with the repo live, works for you? I am very curious about this, as when I visit that link with my iOS device, the double-tap issue exists. If you have time, could you please let me know if you are able to view the link with no issues; then I think we could say that the behavior would be attached to a particular iOS version, or a particular browser version, rather than the software itself. |
What I meant is that I see the issue both against your link and the repo that you posted. I'm having a hard time getting it to break when I transfer the same code to the demo app that we use for testing. |
Thank you @crisbeto for the clarification. That now causes me to ask then, what is in your test environment that fixes it? My repo and link is literally a brand new install using angular-cli, and including material design, and a tiny bit of css styling. That is it, and the issue exists. Wondering if there is some css in your test environment that fixes it, either directly and with purpose, or indirectly, accidentally, with what appears to be a beneficial outcome. |
I'm not exactly sure. I spent some time trying to pinpoint it, a few days ago, with no luck. I'll be looking into it further. |
@MetaVurt I finally managed to reproduce your issue against our demo app. It seems like it happens because you haven't included a theme in your app. You can check our theming guide on how to do it. I'll keep looking to see if I can pinpoint which style fixes the issue and whether we can move it into the button styles. |
Closing this, because including the theme is mandatory for other components to work properly, in addition to the button. There's a pending PR that will log a warning if these styles are missing. |
I HAVE a theme! In fact, I've customized my theme by building custom palettes. Yet, I still have this issue. I had this issue using orange primary and amber secondary. Yep, using themes. So, that's not the end-all-be-all solution to this problem. |
Can you post a Plunkr that shows the issue @jkyoutsey? You can use this as a template: https://goo.gl/DlHd6U. |
I have to double click on Carousel in IOS device. Any solution for that? |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug, feature request, or proposal:
Bug
What is the expected behavior?
A tap on the button should fire the click event.
What is the current behavior?
The first tap highlights the button. The second tap fires the click event.
What are the steps to reproduce?
Click on the sidenav icon on an iPhone or iPad: http://material2-test.firebaseapp.com/
Which versions of Angular, Material, OS, browsers are affected?
The text was updated successfully, but these errors were encountered: