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

Commit

Permalink
fix(autocomplete): fix autocomplete tabindex support
Browse files Browse the repository at this point in the history
- We should always apply to the root directive a tabindex of `-1`
- We should direct the tabindex to the input (if tabindex is specified)
- Added accompanying tests

Fixes #6999. Closes #7005
  • Loading branch information
devversion authored and ThomasBurleson committed Feb 4, 2016
1 parent bc55ac9 commit 1f54bf6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
43 changes: 43 additions & 0 deletions src/components/autocomplete/autocomplete.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,49 @@ describe('<md-autocomplete>', function() {
element.remove();
}));

it('should forward the tabindex to the input', inject(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" ' +
'tabindex="3"' +
'placeholder="placeholder">' +
'<span md-highlight-text="searchText">{{item.display}}</span>' +
'</md-autocomplete>';

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

expect(input.attr('tabindex')).toBe('3');

element.remove();
}));

it('should always set the tabindex of the autcomplete to `-1`', inject(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" ' +
'tabindex="3"' +
'placeholder="placeholder">' +
'<span md-highlight-text="searchText">{{item.display}}</span>' +
'</md-autocomplete>';

var element = compile(template, scope);

expect(element.attr('tabindex')).toBe('-1');

element.remove();
}));

it('should clear value when hitting escape', inject(function($mdConstant, $timeout) {
var scope = createScope();
var template = '\
Expand Down
4 changes: 3 additions & 1 deletion src/components/autocomplete/js/autocompleteDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ function MdAutocomplete () {
// Set our variable for the link function above which runs later
element.hasNotFoundTemplate = !!noItemsTemplate;

if (!attr.hasOwnProperty('tabindex')) element.attr('tabindex', '-1');
// Always set our tabindex of the autocomplete directive to -1, because our input
// will hold the actual tabindex.
element.attr('tabindex', '-1');

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

0 comments on commit 1f54bf6

Please sign in to comment.