Skip to content

Commit

Permalink
fix(autocomplete): always set tabindex to allow receiving focus.
Browse files Browse the repository at this point in the history
  • Loading branch information
devversion committed Dec 7, 2015
1 parent f73ef23 commit f8fcbb2
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
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
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');
}
if (!tabindex) element.attr('tabindex', '-1');

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

0 comments on commit f8fcbb2

Please sign in to comment.