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

Closes #6135
  • Loading branch information
devversion authored and jelbourn committed Dec 8, 2015
1 parent d0b7bac commit d3c0acb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
23 changes: 23 additions & 0 deletions src/components/autocomplete/autocomplete.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,29 @@ 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" ' +
'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');
}
if (!attr.hasOwnProperty('tabindex')) element.attr('tabindex', '-1');

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

0 comments on commit d3c0acb

Please sign in to comment.