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

Commit

Permalink
fix(mobile-ng-click): prevent unwanted opening of the soft keyboard
Browse files Browse the repository at this point in the history
Ghost clicks are busted but the corresponding form elements are still focused. This means that for example on smartphones the soft keyboard will be opened. This pull request prevents the unwanted opening of the soft keyboard.
  • Loading branch information
JanLaussmann authored and mhevery committed Jul 31, 2013
1 parent 3fdbe81 commit 0bbd20f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ngMobile/directive/ngClick.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ ngMobile.directive('ngClick', ['$parse', '$timeout', '$rootElement',
// If we didn't find an allowable region, bust the click.
event.stopPropagation();
event.preventDefault();

// Blur focused form elements
event.target && event.target.blur();
}


Expand Down
3 changes: 3 additions & 0 deletions test/ngMobile/directive/ngClickSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@ describe('ngClick (mobile)', function() {
expect($rootScope.count1).toBe(1);

time = 90;
// Verify that it is blured so we don't get soft-keyboard
element1[0].blur = jasmine.createSpy('blur');
browserTrigger(element1, 'click', [], 10, 10);
expect(element1[0].blur).toHaveBeenCalled();

expect($rootScope.count1).toBe(1);

Expand Down

5 comments on commit 0bbd20f

@damrbaby
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very breaking change, please see my comments here: #2989 (comment)

@OlenDavis
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I second that this is a breaking change; or if you prefer diplomacy, a grossly inflexible, opinionated choice. If the developer wants ng-click not to focus a clicked focusable element (whether that element is the one with ng-click or any ancestor of it, which is not uncommon at all and includes most dialog directives) we're well-prepared if not even accustomed to doing just that with $event.target or various other means. But, that should be up to the developer, not ngTouch; and it certainly shouldn't be something that silently breaks all inputs in dialogs (for instance) a only on mobile devices, and b only when with ngTouch is on the module. That's how you hurt adoption.

@adamreisnz
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is causing us grief as well. Any input element in a parent container which has an ng-click directive is now unclickable on mobile.

@JudahGabriel
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the above commenter: this is causing us grief. I cannot use ngTouch in my app because of this behavior, as it breaks my app on mobile.

@jpodpro
Copy link

@jpodpro jpodpro commented on 0bbd20f Dec 1, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Please sign in to comment.