forked from angular/material
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(util/datepicker): Remove usages of scope().
A few places use `element.scope()` to retrieve the proper scope, however, this is only available when Angular's debugging option is enabled and thus fails in production. Replace usages of `.scope()` in `util.js` and `datepicker.js` with appropriate alternatives. Fixes angular#6474.
- Loading branch information
1 parent
bf78b0c
commit 45e90fa
Showing
4 changed files
with
148 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
angular.module('material.core') | ||
.directive('mdAutofocus', MdAutofocusDirective) | ||
|
||
// Support the deprecated md-auto-focus and md-sidenav-focus as well | ||
.directive('mdAutoFocus', MdAutofocusDirective) | ||
.directive('mdSidenavFocus', MdAutofocusDirective); | ||
|
||
/** | ||
* @ngdoc directive | ||
* @name mdAutofocus | ||
* @module material.core.util | ||
* | ||
* | ||
* @description | ||
* `$mdUtil.findFocusTarget()` provides an optional way to identify the focused element when a dialog, bottomsheet, sideNav | ||
* or other element opens. This is optional attribute finds a nested element with the mdAutoFocus attribute and optional | ||
* expression. An expression may be specified as the directive value; to enable conditional activation of the autoFocus. | ||
* | ||
* @usage | ||
* ### Dialog | ||
* <hljs lang="html"> | ||
* <md-dialog> | ||
* <form> | ||
* <md-input-container> | ||
* <label for="testInput">Label</label> | ||
* <input id="testInput" type="text" md-autofocus> | ||
* </md-input-container> | ||
* </form> | ||
* </md-dialog> | ||
* </hljs> | ||
* | ||
* ### Bottomsheet | ||
* <hljs lang="html"> | ||
* <md-bottom-sheet class="md-list md-has-header"> | ||
* <md-subheader>Comment Actions</md-subheader> | ||
* <md-list> | ||
* <md-list-item ng-repeat="item in items"> | ||
* | ||
* <md-button md-autofocus="$index == 2"> | ||
* <md-icon md-svg-src="{{item.icon}}"></md-icon> | ||
* <span class="md-inline-list-icon-label">{{ item.name }}</span> | ||
* </md-button> | ||
* | ||
* </md-list-item> | ||
* </md-list> | ||
* </md-bottom-sheet> | ||
* </hljs> | ||
* | ||
* ### Autocomplete | ||
* <hljs lang="html"> | ||
* <md-autocomplete | ||
* md-autofocus | ||
* md-selected-item="selectedItem" | ||
* md-search-text="searchText" | ||
* md-items="item in getMatches(searchText)" | ||
* md-item-text="item.display"> | ||
* <span md-highlight-text="searchText">{{item.display}}</span> | ||
* </md-autocomplete> | ||
* </hljs> | ||
* | ||
* ### Sidenav | ||
* <hljs lang="html"> | ||
* <div layout="row" ng-controller="MyController"> | ||
* <md-sidenav md-component-id="left" class="md-sidenav-left"> | ||
* Left Nav! | ||
* </md-sidenav> | ||
* | ||
* <md-content> | ||
* Center Content | ||
* <md-button ng-click="openLeftMenu()"> | ||
* Open Left Menu | ||
* </md-button> | ||
* </md-content> | ||
* | ||
* <md-sidenav md-component-id="right" | ||
* md-is-locked-open="$mdMedia('min-width: 333px')" | ||
* class="md-sidenav-right"> | ||
* <form> | ||
* <md-input-container> | ||
* <label for="testInput">Test input</label> | ||
* <input id="testInput" type="text" | ||
* ng-model="data" md-autofocus> | ||
* </md-input-container> | ||
* </form> | ||
* </md-sidenav> | ||
* </div> | ||
* </hljs> | ||
**/ | ||
function MdAutofocusDirective() { | ||
return { | ||
restrict: 'A', | ||
|
||
link: postLink | ||
} | ||
} | ||
|
||
function postLink(scope, element, attrs) { | ||
var attr = attrs.mdAutoFocus || attrs.mdAutofocus || attrs.mdSidenavFocus; | ||
|
||
// Setup a watcher on the proper attribute to update a class we can check for in $mdUtil | ||
scope.$watch(attr, function(canAutofocus) { | ||
element.toggleClass('_md-can-autofocus', canAutofocus); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
describe('md-autofocus', function() { | ||
var $rootScope, pageScope, element; | ||
|
||
beforeEach(module('material.core')); | ||
beforeEach(inject(function(_$rootScope_) { | ||
$rootScope = _$rootScope_; | ||
})); | ||
|
||
it('adds/removes the _md-can-autofocus class', function() { | ||
build('<input id="test" type="text" md-autofocus="shouldAutoFocus">'); | ||
|
||
// By default, we assume an undefined value for the expression is true | ||
expect(element).toHaveClass('_md-can-autofocus'); | ||
|
||
// Set the expression to false | ||
pageScope.$apply('shouldAutoFocus=false'); | ||
expect(element).not.toHaveClass('_md-can-autofocus'); | ||
|
||
// Set the expression to true | ||
pageScope.$apply('shouldAutoFocus=true'); | ||
expect(element).toHaveClass('_md-can-autofocus'); | ||
}); | ||
|
||
function build(template) { | ||
inject(function($compile) { | ||
pageScope = $rootScope.$new(); | ||
element = $compile(template)(pageScope); | ||
|
||
pageScope.$apply(); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters