Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
refactor(select): rename ngMultiple to mdMultiple
Browse files Browse the repository at this point in the history
- remove unused `$injector`
- remove unused variables and parameters
- add some types
- add missing semicolon

BREAKING CHANGE: `ngMultiple` has been renamed to `mdMultiple` to make it clear that this
API is provided by AngularJS Material and not by AngularJS.

If you had:
```html
  <md-select ng-multiple="expression">...</md-select>
```
You need to change to:
```html
  <md-select md-multiple="expression">...</md-select>
```
  • Loading branch information
Splaktar committed Jul 17, 2020
1 parent 01d2cde commit 4c75858
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions src/components/select/select.js
Expand Up @@ -157,8 +157,7 @@ angular.module('material.components.select', [
* </div>
* </hljs>
*/
function SelectDirective($mdSelect, $mdUtil, $mdConstant, $mdTheming, $mdAria, $parse, $sce,
$injector) {
function SelectDirective($mdSelect, $mdUtil, $mdConstant, $mdTheming, $mdAria, $parse, $sce) {
return {
restrict: 'E',
require: ['^?mdInputContainer', 'mdSelect', 'ngModel', '?^form'],
Expand All @@ -167,6 +166,11 @@ function SelectDirective($mdSelect, $mdUtil, $mdConstant, $mdTheming, $mdAria, $
} // empty placeholder controller to be initialized in link
};

/**
* @param {JQLite} tElement
* @param {IAttributes} tAttrs
* @return {postLink}
*/
function compile(tElement, tAttrs) {
var isMultiple = $mdUtil.parseAttributeBoolean(tAttrs.multiple);
// add the select value that will hold our placeholder or selected option value
Expand Down Expand Up @@ -271,7 +275,7 @@ function SelectDirective($mdSelect, $mdUtil, $mdConstant, $mdTheming, $mdAria, $
var selectValueElement = element.find('md-select-value');
var isReadonly = angular.isDefined(attrs.readonly);
var disableAsterisk = $mdUtil.parseAttributeBoolean(attrs.mdNoAsterisk);
var stopNgMultipleWatch;
var stopMdMultipleWatch;
var userDefinedLabelledby = angular.isDefined(attrs.ariaLabelledby);
var listboxContentElement = element.find('md-content');

Expand Down Expand Up @@ -390,7 +394,7 @@ function SelectDirective($mdSelect, $mdUtil, $mdConstant, $mdTheming, $mdAria, $
} else {
selectValueElement.removeAttr('aria-hidden');
if (!userDefinedLabelledby) {
element.attr('aria-labelledby', element[0].id + ' ' + selectValueElement[0].id)
element.attr('aria-labelledby', element[0].id + ' ' + selectValueElement[0].id);
}
}
};
Expand Down Expand Up @@ -428,7 +432,7 @@ function SelectDirective($mdSelect, $mdUtil, $mdConstant, $mdTheming, $mdAria, $
containerCtrl && containerCtrl.setFocused(false);
inputCheckValue();
};
var handleFocus = function(ev) {
var handleFocus = function() {
// Always focus the container (if we have one) so floating labels and other styles are
// applied properly
containerCtrl && containerCtrl.setFocused(true);
Expand Down Expand Up @@ -465,15 +469,14 @@ function SelectDirective($mdSelect, $mdUtil, $mdConstant, $mdTheming, $mdAria, $
mdSelectCtrl.setSelectValueText(selectMenuCtrl.getSelectedLabels());
}

// TODO add tests for ngMultiple
// TODO add docs for ngMultiple
// TODO in 1.2.0 rename this to mdMultiple
var stopNgMultipleObserver = attrs.$observe('ngMultiple', function(val) {
if (stopNgMultipleWatch) {
stopNgMultipleWatch();
// TODO add tests for mdMultiple
// TODO add docs for mdMultiple
var stopMdMultipleObserver = attrs.$observe('mdMultiple', function(val) {
if (stopMdMultipleWatch) {
stopMdMultipleWatch();
}
var parser = $parse(val);
stopNgMultipleWatch = scope.$watch(function() {
stopMdMultipleWatch = scope.$watch(function() {
return parser(scope);
}, function(multiple, prevVal) {
var selectMenu = selectContainer.find('md-select-menu');
Expand Down Expand Up @@ -561,8 +564,8 @@ function SelectDirective($mdSelect, $mdUtil, $mdConstant, $mdTheming, $mdAria, $
scope.$on('$destroy', function() {
stopRequiredObserver && stopRequiredObserver();
stopDisabledObserver && stopDisabledObserver();
stopNgMultipleWatch && stopNgMultipleWatch();
stopNgMultipleObserver && stopNgMultipleObserver();
stopMdMultipleWatch && stopMdMultipleWatch();
stopMdMultipleObserver && stopMdMultipleObserver();
stopSelectedLabelsWatcher && stopSelectedLabelsWatcher();
stopPlaceholderObserver && stopPlaceholderObserver();
stopInvalidWatch && stopInvalidWatch();
Expand Down Expand Up @@ -1207,6 +1210,11 @@ function OptionDirective($mdButtonInkRipple, $mdUtil, $mdTheming) {
compile: compile
};

/**
* @param {JQLite} element
* @param {IAttributes} attrs
* @return {postLink}
*/
function compile(element, attrs) {
// Manual transclusion to avoid the extra inner <span> that ng-transclude generates
element.append(angular.element('<div class="md-text">').append(element.contents()));
Expand Down Expand Up @@ -1332,6 +1340,10 @@ function OptionDirective($mdButtonInkRipple, $mdUtil, $mdTheming) {
}
}

/**
* @param {JQLite} $element
* @constructor
*/
function OptionController($element) {
/**
* @param {boolean} isSelected
Expand Down Expand Up @@ -1757,7 +1769,6 @@ function SelectProvider($$interimElementProvider) {

var dropDown = opts.selectEl;
var selectMenuController = dropDown.controller('mdSelectMenu') || {};
var listbox = opts.contentEl;

element.addClass('md-clickable');

Expand Down

0 comments on commit 4c75858

Please sign in to comment.