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

Commit

Permalink
fix(autocomplete): always set tabindex to allow receiving focus.
Browse files Browse the repository at this point in the history
Closes #6101 Fixes #5665
  • Loading branch information
devversion committed Dec 7, 2015
1 parent f73ef23 commit 94ebebb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
25 changes: 25 additions & 0 deletions src/components/autocomplete/autocomplete.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,31 @@ describe('<md-autocomplete>', function() {
element.remove();
}));

it('should allow receiving focus on the autocomplete', function() {
var scope = createScope(null, {inputId: 'custom-input-id'});
var template = '\
<md-autocomplete\
md-input-id="{{inputId}}"\
md-selected-item="selectedItem"\
md-search-text="searchText"\
md-items="item in match(searchText)"\
md-item-text="item.display"\
md-autofocus="true"\
placeholder="placeholder">\
<span md-highlight-text="searchText">{{item.display}}</span>\
</md-autocomplete>';
var element = compile(template, scope);
var focusSpy = jasmine.createSpy('focus');

document.body.appendChild(element[0]);

element.on('focus', focusSpy);

element.focus();

expect(focusSpy).toHaveBeenCalled();
});

it('should allow you to set an input id without floating label', inject(function() {
var scope = createScope(null, {inputId: 'custom-input-id'});
var template = '\
Expand Down
4 changes: 1 addition & 3 deletions src/components/autocomplete/js/autocompleteDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@ function MdAutocomplete () {
// Set our variable for the link function above which runs later
hasNotFoundTemplate = noItemsTemplate ? true : false;

if (attr.hasOwnProperty('tabindex')) {
element.attr('tabindex', '-1');
}
element.attr('tabindex', '-1');

return '\
<md-autocomplete-wrap\
Expand Down

0 comments on commit 94ebebb

Please sign in to comment.