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

Commit a3c533f

Browse files
oliversalzburgSplaktar
authored andcommitted
fix(panel): invisble after hide/show cycle
When an mdPanel instance is hidden through an animation, the "leave" animation classes remain on the panel after it was hidden. This causes it to remain hidden if it is requested to be shown a second time. We resolve this by ensuring the relevant animation classes are removed properly when hiding the panel. Fixes #11291
1 parent e2af2a3 commit a3c533f

File tree

5 files changed

+165
-4
lines changed

5 files changed

+165
-4
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<div class="md-padding" ng-controller="ReuseDemoCtrl as ctrl">
2+
<p>
3+
Panels can be reused to avoid re-creating resources.
4+
</p>
5+
6+
<div flex="25">
7+
<h3>AnimationType:</h3>
8+
<md-radio-group ng-model="ctrl.animationType">
9+
<md-radio-button value="slide">Slide</md-radio-button>
10+
<md-radio-button value="scale">Scale</md-radio-button>
11+
<md-radio-button value="fade">Fade</md-radio-button>
12+
<md-radio-button value="custom">Custom</md-radio-button>
13+
</md-radio-group>
14+
</div>
15+
16+
<div>
17+
<md-button class="md-primary md-raised demo-dialog-reuse-button"
18+
ng-click="ctrl.showDialog($event, 'Ahoi')">
19+
Open Dialog
20+
</md-button>
21+
<md-button class="md-accent md-raised demo-dialog-reuse-button"
22+
ng-click="ctrl.showDialog($event, 'Hello')">
23+
Also open Dialog
24+
</md-button>
25+
<md-button class="md-warning md-raised demo-dialog-reuse-button"
26+
ng-click="ctrl.showDialog($event, 'Greetings')">
27+
Open Here
28+
</md-button>
29+
</div>
30+
</div>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<div role="dialog" aria-label="Eat me!" layout="column" layout-align="center center">
2+
<md-toolbar>
3+
<div class="md-toolbar-tools">
4+
<h2>Surprise!</h2>
5+
</div>
6+
</md-toolbar>
7+
8+
<div class="demo-dialog-content">
9+
<p>{{ctrl.text}}</p>
10+
11+
<div layout="row" >
12+
<img flex alt="Delicious donut" src="img/donut.jpg">
13+
</div>
14+
</div>
15+
16+
<div layout="row" class="demo-dialog-button">
17+
<md-button md-autofocus flex class="md-primary" ng-click="ctrl.closeDialog()">
18+
Close
19+
</md-button>
20+
</div>
21+
</div>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
(function() {
2+
'use strict';
3+
4+
angular.module('panelReuseDemo', ['ngMaterial'])
5+
.controller('ReuseDemoCtrl', ReuseDemoCtrl)
6+
.controller('ReusePanelCtrl', ReusePanelCtrl);
7+
8+
function ReuseDemoCtrl($mdPanel) {
9+
this._mdPanel = $mdPanel;
10+
11+
this.animationType = 'scale';
12+
13+
var position = this._mdPanel.newPanelPosition()
14+
.absolute()
15+
.center();
16+
17+
var animation = this._mdPanel.newPanelAnimation()
18+
.openFrom('.demo-dialog-reuse-button')
19+
.duration(300)
20+
.withAnimation(this._mdPanel.animation.SCALE);
21+
22+
var config = {
23+
attachTo: angular.element(document.body),
24+
controller: ReusePanelCtrl,
25+
controllerAs: 'ctrl',
26+
disableParentScroll: this.disableParentScroll,
27+
templateUrl: 'panel.tmpl.html',
28+
hasBackdrop: true,
29+
panelClass: 'demo-dialog-example',
30+
position: position,
31+
animation: animation,
32+
trapFocus: true,
33+
zIndex: 150,
34+
clickOutsideToClose: false,
35+
escapeToClose: false,
36+
focusOnOpen: true,
37+
locals: {
38+
_demoCtrl: this
39+
}
40+
};
41+
42+
this._mdPanelRef = this._mdPanel.create(config);
43+
this._mdPanelRef.attach();
44+
}
45+
46+
ReuseDemoCtrl.prototype.showDialog = function($event, text) {
47+
var position = this._mdPanel.newPanelPosition()
48+
.absolute()
49+
.center();
50+
51+
this._mdPanelRef.updatePosition(position);
52+
53+
var animation = this._mdPanel.newPanelAnimation()
54+
.openFrom($event)
55+
.duration(300);
56+
57+
switch (this.animationType) {
58+
case 'custom':
59+
animation.withAnimation({
60+
open: 'demo-dialog-custom-animation-open',
61+
close: 'demo-dialog-custom-animation-close'
62+
});
63+
break;
64+
case 'slide':
65+
animation.withAnimation(this._mdPanel.animation.SLIDE);
66+
break;
67+
case 'scale':
68+
animation.withAnimation(this._mdPanel.animation.SCALE);
69+
break;
70+
case 'fade':
71+
animation.withAnimation(this._mdPanel.animation.FADE);
72+
break;
73+
}
74+
75+
this._mdPanelRef.updateAnimation(animation);
76+
77+
this._mdPanelRefCtrl.text = text;
78+
this._mdPanelRef.show();
79+
};
80+
81+
82+
function ReusePanelCtrl(mdPanelRef, _demoCtrl) {
83+
this._mdPanelRef = mdPanelRef;
84+
85+
// Register the controller for this panel with the parent controller.
86+
_demoCtrl._mdPanelRefCtrl = this;
87+
}
88+
89+
ReusePanelCtrl.prototype.closeDialog = function() {
90+
this._mdPanelRef && this._mdPanelRef.hide();
91+
};
92+
93+
})();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.demo-dialog-content {
2+
padding: 0 15px;
3+
width: 100%;
4+
}
5+
6+
.demo-dialog-content img {
7+
height: 300px;
8+
margin: auto;
9+
}
10+
11+
.demo-dialog-button {
12+
width: 100%;
13+
}

src/components/panel/panel.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3356,7 +3356,8 @@ MdPanelAnimation.prototype.animateOpen = function(panelEl) {
33563356
panelEl.css('opacity', '1');
33573357

33583358
animationOptions = {
3359-
transitionInClass: '_md-panel-animate-enter'
3359+
transitionInClass: '_md-panel-animate-enter',
3360+
transitionOutClass: '_md-panel-animate-leave',
33603361
};
33613362

33623363
var openSlide = animator.calculateSlideToOrigin(
@@ -3421,7 +3422,8 @@ MdPanelAnimation.prototype.animateClose = function(panelEl) {
34213422
// Slide should start with opacity: 1.
34223423
panelEl.css('opacity', '1');
34233424
reverseAnimationOptions = {
3424-
transitionInClass: '_md-panel-animate-leave'
3425+
transitionInClass: '_md-panel-animate-leave',
3426+
transitionOutClass: '_md-panel-animate-enter _md-panel-animate-leave'
34253427
};
34263428

34273429
var closeSlide = animator.calculateSlideToOrigin(
@@ -3431,7 +3433,8 @@ MdPanelAnimation.prototype.animateClose = function(panelEl) {
34313433

34323434
case MdPanelAnimation.animation.SCALE:
34333435
reverseAnimationOptions = {
3434-
transitionInClass: '_md-panel-animate-scale-out _md-panel-animate-leave'
3436+
transitionInClass: '_md-panel-animate-scale-out _md-panel-animate-leave',
3437+
transitionOutClass: '_md-panel-animate-scale-out _md-panel-animate-enter _md-panel-animate-leave'
34353438
};
34363439

34373440
var closeScale = animator.calculateZoomToOrigin(
@@ -3441,7 +3444,8 @@ MdPanelAnimation.prototype.animateClose = function(panelEl) {
34413444

34423445
case MdPanelAnimation.animation.FADE:
34433446
reverseAnimationOptions = {
3444-
transitionInClass: '_md-panel-animate-fade-out _md-panel-animate-leave'
3447+
transitionInClass: '_md-panel-animate-fade-out _md-panel-animate-leave',
3448+
transitionOutClass: '_md-panel-animate-fade-out _md-panel-animate-enter _md-panel-animate-leave'
34453449
};
34463450
break;
34473451

0 commit comments

Comments
 (0)