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

Commit 825108a

Browse files
committed
feat(panel): add the ability to update the animation of an existing panel
* Adds the ability to update the animation of a panel, without having to re-create it. * Adds a unit test for verifying that the backdrop animation duration matches the one of the panel. This was missed in #9570.
1 parent 8f8274a commit 825108a

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

src/components/panel/panel.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,16 @@ angular
447447
* @returns {!MdPanelRef}
448448
*/
449449

450+
/**
451+
* @ngdoc method
452+
* @name MdPanelRef#updateAnimation
453+
* @description
454+
* Updates the animation configuration for a panel. You can use this to change
455+
* the panel's animation without having to re-create it.
456+
*
457+
* @param {!MdPanelAnimation} animation
458+
*/
459+
450460

451461
/*****************************************************************************
452462
* MdPanelPosition *
@@ -1925,6 +1935,19 @@ MdPanelRef.prototype._configureTrapFocus = function() {
19251935
};
19261936

19271937

1938+
/**
1939+
* Updates the animation of a panel.
1940+
* @param {!MdPanelAnimation} animation
1941+
*/
1942+
MdPanelRef.prototype.updateAnimation = function(animation) {
1943+
this.config['animation'] = animation;
1944+
1945+
if (this._backdropRef) {
1946+
this._backdropRef.config.animation.duration(animation._rawDuration);
1947+
}
1948+
};
1949+
1950+
19281951
/**
19291952
* Animate the panel opening.
19301953
* @returns {!angular.$q.Promise} A promise that is resolved when the panel has

src/components/panel/panel.spec.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,6 +2641,20 @@ describe('$mdPanel', function() {
26412641
expect(panelRef.panelContainer).toHaveClass(HIDDEN_CLASS);
26422642
});
26432643

2644+
it('should match the backdrop animation with the panel', function() {
2645+
mdPanelAnimation.duration(500);
2646+
2647+
openPanel({
2648+
hasBackdrop: true,
2649+
animation: mdPanelAnimation
2650+
});
2651+
2652+
var backdropAnimation = panelRef._backdropRef.config.animation;
2653+
2654+
expect(backdropAnimation._openDuration).toBe(mdPanelAnimation._openDuration);
2655+
expect(backdropAnimation._closeDuration).toBe(mdPanelAnimation._closeDuration);
2656+
});
2657+
26442658
describe('should determine openFrom when', function() {
26452659
it('provided a selector', function() {
26462660
var animation = mdPanelAnimation.openFrom('button');
@@ -2730,6 +2744,34 @@ describe('$mdPanel', function() {
27302744
expect(animation._closeDuration).toBeFalsy();
27312745
});
27322746
});
2747+
2748+
describe('updating the animation of a panel', function() {
2749+
it('should change the animation config of an open panel', function() {
2750+
var newAnimation = $mdPanel.newPanelAnimation();
2751+
2752+
openPanel();
2753+
2754+
panelRef.updateAnimation(newAnimation);
2755+
2756+
expect(panelRef.config.animation).toBe(newAnimation);
2757+
});
2758+
2759+
it('should update the duration of the backdrop animation', function() {
2760+
var newAnimation = $mdPanel.newPanelAnimation().duration({
2761+
open: 1000,
2762+
close: 2000
2763+
});
2764+
2765+
openPanel({ hasBackdrop: true });
2766+
2767+
panelRef.updateAnimation(newAnimation);
2768+
2769+
var backdropAnimation = panelRef._backdropRef.config.animation;
2770+
2771+
expect(backdropAnimation._openDuration).toBe(newAnimation._openDuration);
2772+
expect(backdropAnimation._closeDuration).toBe(newAnimation._closeDuration);
2773+
});
2774+
});
27332775
});
27342776

27352777
describe('interceptor logic: ', function() {

0 commit comments

Comments
 (0)