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

Commit

Permalink
feat(select): add mdOnClose expression eval event
Browse files Browse the repository at this point in the history
closes #3217
  • Loading branch information
rschmukler committed Jun 11, 2015
1 parent 67be5ce commit d7bfc86
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/components/select/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ angular.module('material.components.select', [
* @description Displays a select box, bound to an ng-model.
*
* @param {expression} ng-model The model!
* @param {expression=} md-on-close expression to be evaluated when the select is closed

This comment has been minimized.

Copy link
@DerekLouie

DerekLouie Jun 11, 2015

Contributor

I am a little fuzzy on this, but I must ask is this async? If not could we make this 'expression&' instead?

We would like to pass a promise into this in the persisting data case and we would like the dropdown wait for the promise to resolve before further actions are taken.

* @param {boolean=} multiple Whether it's multiple.
* @param {string=} placeholder Placeholder hint text.
* @param {string=} aria-label Optional label for accessibility. Only necessary if no placeholder or
Expand Down Expand Up @@ -155,7 +156,7 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $mdAria, $interpolate,
$mdTheming(element);

if (attr.name && formCtrl) {
var selectEl = element.parent()[0].querySelector('select[name=".' + attr.name + '"]')
var selectEl = element.parent()[0].querySelector('select[name=".' + attr.name + '"]');
formCtrl.$removeControl(angular.element(selectEl).controller());
}

Expand All @@ -177,6 +178,10 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $mdAria, $interpolate,
val ? labelEl.addClass('md-placeholder') : labelEl.removeClass('md-placeholder');
};

mdSelectCtrl.triggerClose = function() {
$parse(attr.mdOnClose)(scope);
};

scope.$$postDigest(function() {
setAriaLabel();
syncLabelText();
Expand Down Expand Up @@ -879,6 +884,7 @@ function SelectProvider($$interimElementProvider) {
opts.restoreScroll();
}
if (opts.restoreFocus) opts.target.focus();
mdSelect && mdSelect.triggerClose();
});
}

Expand Down
14 changes: 14 additions & 0 deletions src/components/select/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ describe('<md-select>', function() {
expect(select.attr('aria-disabled')).toBe('true');
}));

it('calls the md-on-close fn on close', inject(function($document, $rootScope) {
var called = false;
$rootScope.onClose = function() {
called = true;
};
var select = setupSelect('ng-model="val", md-on-close="onClose()"', [1, 2, 3]);
openSelect(select);

$document.find('md-option')[0].click();
waitForSelectClose();

expect(called).toBe(true);
}));

xit('closes the menu if the element is destroyed', inject(function($document, $rootScope) {
var select = setupSelect('ng-model="val"');

Expand Down

2 comments on commit d7bfc86

@DerekLouie
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello Ryan!

Thanks for the quick fix! I hate to nitpick but I had a question about the "expression=" bit of it.

With an = it does not run async correct? So this would no play nicely with promises?

@rschmukler
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DerekLouie it should work with promises. The expression= is just jsdoc notation

Please sign in to comment.