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

Commit 4b9f93d

Browse files
devversionThomasBurleson
authored andcommitted
feat(autocomplete): forward md-select-on-focus attribute to input aswell
Fixes #7125 Closes #7127
1 parent 0627d9e commit 4b9f93d

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/components/autocomplete/autocomplete.spec.js

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

166+
it('should forward the `md-select-on-focus` attribute to the input', inject(function() {
167+
var scope = createScope(null, {inputId: 'custom-input-id'});
168+
var template =
169+
'<md-autocomplete ' +
170+
'md-input-id="{{inputId}}" ' +
171+
'md-selected-item="selectedItem" ' +
172+
'md-search-text="searchText" ' +
173+
'md-items="item in match(searchText)" ' +
174+
'md-item-text="item.display" ' +
175+
'md-select-on-focus="" ' +
176+
'tabindex="3"' +
177+
'placeholder="placeholder">' +
178+
'<span md-highlight-text="searchText">{{item.display}}</span>' +
179+
'</md-autocomplete>';
180+
181+
var element = compile(template, scope);
182+
var input = element.find('input');
183+
184+
expect(input.attr('md-select-on-focus')).toBe("");
185+
186+
element.remove();
187+
}));
188+
166189
it('should forward the tabindex to the input', inject(function() {
167190
var scope = createScope(null, {inputId: 'custom-input-id'});
168191
var template =

src/components/autocomplete/js/autocompleteDirective.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ angular
5858
* `md-input-container`
5959
* @param {string=} md-input-name The name attribute given to the input element to be used with
6060
* FormController
61+
* @param {string=} md-select-on-focus When present the inputs text will be automatically selected
62+
* on focus.
6163
* @param {string=} md-input-id An ID to be added to the input element
6264
* @param {number=} md-input-minlength The minimum length for the input's value for validation
6365
* @param {number=} md-input-maxlength The maximum length for the input's value for validation
@@ -243,6 +245,7 @@ function MdAutocomplete () {
243245
ng-blur="$mdAutocompleteCtrl.blur()"\
244246
ng-focus="$mdAutocompleteCtrl.focus()"\
245247
aria-owns="ul-{{$mdAutocompleteCtrl.id}}"\
248+
' + (attr.mdSelectOnFocus != null ? 'md-select-on-focus=""' : '') + '\
246249
aria-label="{{floatingLabel}}"\
247250
aria-autocomplete="list"\
248251
aria-haspopup="true"\
@@ -266,6 +269,7 @@ function MdAutocomplete () {
266269
ng-focus="$mdAutocompleteCtrl.focus()"\
267270
placeholder="{{placeholder}}"\
268271
aria-owns="ul-{{$mdAutocompleteCtrl.id}}"\
272+
' + (attr.mdSelectOnFocus != null ? 'md-select-on-focus=""' : '') + '\
269273
aria-label="{{placeholder}}"\
270274
aria-autocomplete="list"\
271275
aria-haspopup="true"\

0 commit comments

Comments
 (0)