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

Commit d3c0acb

Browse files
devversionjelbourn
authored andcommitted
fix(autocomplete): always set tabindex to allow receiving focus.
Closes #6101 Fixes #5665 Closes #6135
1 parent d0b7bac commit d3c0acb

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/components/autocomplete/autocomplete.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,29 @@ describe('<md-autocomplete>', function() {
9898
element.remove();
9999
}));
100100

101+
it('should allow receiving focus on the autocomplete', function() {
102+
var scope = createScope(null, {inputId: 'custom-input-id'});
103+
var template = '<md-autocomplete ' +
104+
'md-input-id="{{inputId}}" ' +
105+
'md-selected-item="selectedItem" ' +
106+
'md-search-text="searchText" ' +
107+
'md-items="item in match(searchText)" ' +
108+
'md-item-text="item.display" ' +
109+
'placeholder="placeholder">' +
110+
'<span md-highlight-text="searchText">{{item.display}}</span>' +
111+
'</md-autocomplete>';
112+
var element = compile(template, scope);
113+
var focusSpy = jasmine.createSpy('focus');
114+
115+
document.body.appendChild(element[0]);
116+
117+
element.on('focus', focusSpy);
118+
119+
element.focus();
120+
121+
expect(focusSpy).toHaveBeenCalled();
122+
});
123+
101124
it('should allow you to set an input id without floating label', inject(function() {
102125
var scope = createScope(null, {inputId: 'custom-input-id'});
103126
var template = '\

src/components/autocomplete/js/autocompleteDirective.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,7 @@ function MdAutocomplete () {
156156
// Set our variable for the link function above which runs later
157157
hasNotFoundTemplate = noItemsTemplate ? true : false;
158158

159-
if (attr.hasOwnProperty('tabindex')) {
160-
element.attr('tabindex', '-1');
161-
}
159+
if (!attr.hasOwnProperty('tabindex')) element.attr('tabindex', '-1');
162160

163161
return '\
164162
<md-autocomplete-wrap\

0 commit comments

Comments
 (0)