From 94ebebb07770ba6f70fa8e63740683d62657ffa4 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Mon, 7 Dec 2015 22:43:56 +0100 Subject: [PATCH] fix(autocomplete): always set tabindex to allow receiving focus. Closes #6101 Fixes #5665 --- .../autocomplete/autocomplete.spec.js | 25 +++++++++++++++++++ .../autocomplete/js/autocompleteDirective.js | 4 +-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/components/autocomplete/autocomplete.spec.js b/src/components/autocomplete/autocomplete.spec.js index dcc8f23cfa7..87bc79a2b80 100644 --- a/src/components/autocomplete/autocomplete.spec.js +++ b/src/components/autocomplete/autocomplete.spec.js @@ -98,6 +98,31 @@ describe('', function() { element.remove(); })); + it('should allow receiving focus on the autocomplete', function() { + var scope = createScope(null, {inputId: 'custom-input-id'}); + var template = '\ + \ + {{item.display}}\ + '; + 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 = '\ diff --git a/src/components/autocomplete/js/autocompleteDirective.js b/src/components/autocomplete/js/autocompleteDirective.js index 7d60117cc2b..7ed3e7aaec9 100644 --- a/src/components/autocomplete/js/autocompleteDirective.js +++ b/src/components/autocomplete/js/autocompleteDirective.js @@ -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 '\