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

Commit

Permalink
fix(autocomplete): support ng-click on md-autocomplete
Browse files Browse the repository at this point in the history
Relates to #11625. Relates to #11757.
  • Loading branch information
Splaktar committed Jul 3, 2019
1 parent 8f14afd commit bfc071e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
28 changes: 27 additions & 1 deletion src/components/autocomplete/autocomplete.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,32 @@ describe('<md-autocomplete>', function() {
element.remove();
}));

fit('should support ng-click on the md-autocomplete', inject(function() {
var scope = createScope(null, {inputId: 'custom-input-id'});
scope.test = false;
var template =
'<md-autocomplete ' +
'md-selected-item="selectedItem" ' +
'md-search-text="searchText" ' +
'md-items="item in match(searchText)" ' +
'md-item-text="item.display" ' +
'ng-click="test = true" ' +
'placeholder="placeholder">' +
' <span md-highlight-text="searchText">{{item.display}}</span>' +
'</md-autocomplete>';

var element = compile(template, scope);
var input = element.find('input');

expect(scope.test).toBe(false);

input[0].click();

expect(scope.test).toBe(true);

element.remove();
}));

it('should support ng-trim for the search input', inject(function() {
var scope = createScope(null, {inputId: 'custom-input-id'});
var template =
Expand Down Expand Up @@ -615,7 +641,7 @@ describe('<md-autocomplete>', function() {
element.remove();
}));

it('always sets the tabindex of the autcomplete to `-1`', inject(function() {
it('always sets the tabindex of the autocomplete to `-1`', inject(function() {
var scope = createScope(null, {inputId: 'custom-input-id'});
var template =
'<md-autocomplete ' +
Expand Down
10 changes: 7 additions & 3 deletions src/components/autocomplete/js/autocompleteDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,15 @@ function MdAutocomplete ($$mdSvgRegistry) {
}

scope.mdMode = getRepeatMode(attrs.mdMode);

// Stop click events from bubbling up to the document and triggering a flicker of the
// options panel while still supporting ng-click to be placed on md-autocomplete.
element.on('click', function(event) {
event.stopPropagation();
});
};
},
template: function (element, attr) {
template: function (element, attr) {
var noItemsTemplate = getNoItemsTemplate(),
itemTemplate = getItemTemplate(),
leftover = element.html(),
Expand Down Expand Up @@ -493,7 +499,6 @@ function MdAutocomplete ($$mdSvgRegistry) {
ng-keydown="$mdAutocompleteCtrl.keydown($event)"\
ng-blur="$mdAutocompleteCtrl.blur($event)"\
ng-focus="$mdAutocompleteCtrl.focus($event)"\
ng-click="$event.stopPropagation()"\
aria-label="{{floatingLabel}}"\
aria-autocomplete="list"\
role="combobox"\
Expand Down Expand Up @@ -521,7 +526,6 @@ function MdAutocomplete ($$mdSvgRegistry) {
ng-keydown="$mdAutocompleteCtrl.keydown($event)"\
ng-blur="$mdAutocompleteCtrl.blur($event)"\
ng-focus="$mdAutocompleteCtrl.focus($event)"\
ng-click="$event.stopPropagation()"\
placeholder="{{placeholder}}"\
aria-label="{{placeholder}}"\
aria-autocomplete="list"\
Expand Down

0 comments on commit bfc071e

Please sign in to comment.