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

Commit 5fc572d

Browse files
update(autocomplete, bottomsheet, dialog, sidenav): revert autocomplete md-auto-focus changes
Autocomplete should not use $mdUtils.findFocusTarget(); since it may be used as a child component within InterimElements. * Change tag usage from `md-auto-focus` to `md-autofocus`. * AutoComplete calls `focusElement()` when the component recieves focus.
1 parent ae64a60 commit 5fc572d

File tree

11 files changed

+21
-26
lines changed

11 files changed

+21
-26
lines changed

src/components/autocomplete/demoBasicUsage/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<p>Use <code>md-autocomplete</code> to search for matches from local or remote data sources.</p>
55
<md-autocomplete
66
ng-disabled="ctrl.isDisabled"
7-
md-enable-autofocus="true"
87
md-no-cache="ctrl.noCache"
98
md-selected-item="ctrl.selectedItem"
109
md-search-text-change="ctrl.searchTextChange(ctrl.searchText)"

src/components/autocomplete/js/autocompleteController.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $mdTheming,
6363
gatherElements();
6464
moveDropdown();
6565
focusElement();
66+
$element.on('focus', focusElement);
6667
});
6768
}
6869

@@ -124,10 +125,7 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $mdTheming,
124125
* Sends focus to the input element.
125126
*/
126127
function focusElement () {
127-
if ($scope.enableAutofocus) {
128-
$mdUtil.findFocusTarget($element);
129-
}
130-
//elements.input.focus();
128+
if ($scope.autofocus) elements.input.focus();
131129
}
132130

133131
/**

src/components/autocomplete/js/autocompleteDirective.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ angular
4949
* make suggestions
5050
* @param {number=} md-delay Specifies the amount of time (in milliseconds) to wait before looking
5151
* for results
52-
* @param {boolean=} md-enable-autofocus If true, will immediately focus the input element
52+
* @param {boolean=} md-autofocus If true, will immediately focus the input element
5353
* @param {boolean=} md-autoselect If true, the first item will be selected by default
5454
* @param {string=} md-menu-class This will be applied to the dropdown menu for styling
5555
* @param {string=} md-floating-label This will add a floating label to autocomplete and wrap it in
@@ -136,7 +136,7 @@ function MdAutocomplete () {
136136
textChange: '&?mdSearchTextChange',
137137
minLength: '=?mdMinLength',
138138
delay: '=?mdDelay',
139-
enableAutofocus:'=?mdEnableAutofocus',
139+
autofocus: '=?mdAutofocus',
140140
floatingLabel: '@?mdFloatingLabel',
141141
autoselect: '=?mdAutoselect',
142142
menuClass: '@?mdMenuClass',
@@ -219,8 +219,7 @@ function MdAutocomplete () {
219219
aria-autocomplete="list"\
220220
aria-haspopup="true"\
221221
aria-activedescendant=""\
222-
aria-expanded="{{!$mdAutocompleteCtrl.hidden}}"\
223-
md-auto-focus/>\
222+
aria-expanded="{{!$mdAutocompleteCtrl.hidden}}"/>\
224223
<div md-autocomplete-parent-scope md-autocomplete-replace>' + leftover + '</div>\
225224
</md-input-container>';
226225
} else {
@@ -242,8 +241,7 @@ function MdAutocomplete () {
242241
aria-autocomplete="list"\
243242
aria-haspopup="true"\
244243
aria-activedescendant=""\
245-
aria-expanded="{{!$mdAutocompleteCtrl.hidden}}"\
246-
md-auto-focus/>\
244+
aria-expanded="{{!$mdAutocompleteCtrl.hidden}}"/>\
247245
<button\
248246
type="button"\
249247
tabindex="-1"\

src/components/bottomSheet/bottomSheet.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ describe('$mdBottomSheet service', function() {
4242
expect(parent.find('md-bottom-sheet').length).toBe(1);
4343
}));
4444

45-
it('should focus child with md-auto-focus', inject(function($rootScope, $animate, $document, $mdBottomSheet) {
45+
it('should focus child with md-autofocus', inject(function($rootScope, $animate, $document, $mdBottomSheet) {
4646
jasmine.mockElementFocus(this);
4747
var parent = angular.element('<div>');
4848
var markup = '' +
4949
'<md-bottom-sheet>' +
5050
' <md-input-container><label>Label</label>' +
51-
' <input type="text" md-auto-focus>' +
51+
' <input type="text" md-autofocus>' +
5252
' </md-input-container>' +
5353
' <md-input-container><label>Label</label>' +
54-
' <input type="text" md-auto-focus>' +
54+
' <input type="text" md-autofocus>' +
5555
' </md-input-container>' +
5656
'<md-bottom-sheet>';
5757

@@ -67,7 +67,7 @@ describe('$mdBottomSheet service', function() {
6767
expect(sheet.length).toBe(1);
6868
var focusEl = sheet.find('input');
6969

70-
// Focus should be on the last md-auto-focus element
70+
// Focus should be on the last md-autofocus element
7171
expect($document.activeElement).toBe(focusEl[1]);
7272
}));
7373
});

src/components/bottomSheet/demoBasicUsage/bottom-sheet-list-template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<md-button
77
ng-click="listItemClick($index)"
8-
md-auto-focus="$index == 2"
8+
md-autofocus="$index == 2"
99
class="md-list-item-content" >
1010
<md-icon md-svg-src="{{item.icon}}"></md-icon>
1111
<span class="md-inline-list-icon-label">{{ item.name }}</span>

src/components/dialog/demoBasicUsage/dialog1.tmpl.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ <h2>Mango (Fruit)</h2>
2727
</md-dialog-content>
2828

2929
<div class="md-actions" layout="row">
30-
<md-button href="http://en.wikipedia.org/wiki/Mango" target="_blank" md-auto-focus>
30+
<md-button href="http://en.wikipedia.org/wiki/Mango" target="_blank" md-autofocus>
3131
More on Wikipedia
3232
</md-button>
3333
<span flex></span>

src/components/dialog/dialog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ function MdDialogProvider($$interimElementProvider) {
415415
' ng-click="dialog.abort()" class="md-primary">',
416416
' {{ dialog.cancel }}',
417417
' </md-button>',
418-
' <md-button ng-click="dialog.hide()" class="md-primary" md-auto-focus="dialog.$type!=\'confirm\'">',
418+
' <md-button ng-click="dialog.hide()" class="md-primary" md-autofocus="dialog.$type!=\'confirm\'">',
419419
' {{ dialog.ok }}',
420420
' </md-button>',
421421
' </div>',

src/components/dialog/dialog.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ describe('$mdDialog', function() {
7979
$mdDialog.show(
8080
$mdDialog.alert({
8181
template: '<md-dialog>' +
82-
'<md-dialog-content tabIndex="0" md-auto-focus>' +
82+
'<md-dialog-content tabIndex="0" md-autofocus>' +
8383
'<p>Muppets are the best</p>' +
8484
'</md-dialog-content>' +
8585
'</md-dialog>',

src/components/sidenav/demoBasicUsage/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ <h1 class="md-toolbar-tools">Sidenav Right</h1>
5959
<md-input-container>
6060
<label for="testInput">Test input</label>
6161
<input type="text" id="testInput"
62-
ng-model="data" md-auto-focus>
62+
ng-model="data" md-autofocus>
6363
</md-input-container>
6464
</form>
6565
<md-button ng-click="close()" class="md-primary">

src/components/sidenav/sidenav.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ describe('mdSidenav', function() {
7979
expect($document.activeElement).toBe(focusEl[0]);
8080
}));
8181

82-
it('should focus child with md-auto-focus', inject(function($rootScope, $animate, $document, $compile) {
82+
it('should focus child with md-autofocus', inject(function($rootScope, $animate, $document, $compile) {
8383
jasmine.mockElementFocus(this);
8484
var parent = angular.element('<div>');
8585
var markup = '<md-sidenav md-is-open="show">'+
8686
'<md-input-container><label>Label</label>' +
87-
'<input type="text" md-auto-focus>' +
87+
'<input type="text" md-autofocus>' +
8888
'</md-input-container>' +
8989
'<md-sidenav>';
9090
var sidenavEl = angular.element(markup);

src/core/util/util.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function UtilFactory($document, $timeout, $compile, $rootScope, $$mdAnimate) {
7878
* <form>
7979
* <md-input-container>
8080
* <label for="testInput">Label</label>
81-
* <input id="testInput" type="text" md-auto-focus>
81+
* <input id="testInput" type="text" md-autofocus>
8282
* </md-input-container>
8383
* </form>
8484
* </md-dialog>
@@ -90,7 +90,7 @@ function UtilFactory($document, $timeout, $compile, $rootScope, $$mdAnimate) {
9090
* <md-list>
9191
* <md-list-item ng-repeat="item in items">
9292
*
93-
* <md-button md-auto-focus="$index == 2">
93+
* <md-button md-autofocus="$index == 2">
9494
* <md-icon md-svg-src="{{item.icon}}"></md-icon>
9595
* <span class="md-inline-list-icon-label">{{ item.name }}</span>
9696
* </md-button>
@@ -102,14 +102,14 @@ function UtilFactory($document, $timeout, $compile, $rootScope, $$mdAnimate) {
102102
*
103103
**/
104104
findFocusTarget: function(containerEl, attributeVal) {
105-
var elToFocus, items = containerEl[0].querySelectorAll(attributeVal || '[md-auto-focus]');
105+
var elToFocus, items = containerEl[0].querySelectorAll(attributeVal || '[md-autofocus]');
106106

107107
// Find the last child element with the focus attribute
108108
items.length && angular.forEach(items, function(it) {
109109
it = angular.element(it);
110110

111111
// If the expression evaluates to FALSE, then it is not focusable target
112-
var focusExpression = it[0].getAttribute('md-auto-focus');
112+
var focusExpression = it[0].getAttribute('md-autofocus');
113113
var isFocusable = focusExpression ? (it.scope().$eval(focusExpression) !== false ) : true;
114114

115115
if (isFocusable) elToFocus = it;

0 commit comments

Comments
 (0)