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

Commit 4649240

Browse files
committed
fix(panel): positions panel offscreen when calculating height/width
Closes #8405
1 parent 0e2e60f commit 4649240

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/components/panel/panel.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -738,9 +738,11 @@ MdPanelService.prototype.newPanelAnimation = function() {
738738
MdPanelService.prototype._wrapTemplate = function(origTemplate) {
739739
var template = origTemplate || '';
740740

741+
// The panel should be initially rendered offscreen so we can calculate
742+
// height and width for positioning.
741743
return '' +
742744
'<div class="md-panel-outer-wrapper">' +
743-
' <div class="md-panel">' + template + '</div>' +
745+
' <div class="md-panel" style="left: -9999px;">' + template + '</div>' +
744746
'</div>';
745747
};
746748

@@ -1137,7 +1139,6 @@ MdPanelRef.prototype._createPanel = function() {
11371139

11381140
self._configureTrapFocus();
11391141
self._addStyles().then(function() {
1140-
self._panelContainer.addClass(MD_PANEL_HIDDEN);
11411142
resolve(self);
11421143
}, reject);
11431144
}, reject);
@@ -1156,23 +1157,30 @@ MdPanelRef.prototype._addStyles = function() {
11561157
self._panelContainer.css('z-index', self._config['zIndex']);
11571158
self._panelEl.css('z-index', self._config['zIndex'] + 1);
11581159

1160+
var hideAndResolve = function() {
1161+
// Remove left: -9999px and add hidden class.
1162+
self._panelEl.css('left', '');
1163+
self._panelContainer.addClass(MD_PANEL_HIDDEN);
1164+
resolve(self);
1165+
};
1166+
11591167
if (self._config['fullscreen']) {
11601168
self._panelEl.addClass('_md-panel-fullscreen');
1161-
resolve(self);
1169+
hideAndResolve();
11621170
return; // Don't setup positioning.
11631171
}
11641172

11651173
var positionConfig = self._config['position'];
11661174
if (!positionConfig) {
1167-
resolve(self);
1175+
hideAndResolve();
11681176
return; // Don't setup positioning.
11691177
}
11701178

11711179
// Wait for angular to finish processing the template, then position it
11721180
// correctly. This is necessary so that the panel will have a defined height
11731181
// and width.
11741182
self._$rootScope['$$postDigest'](function() {
1175-
self._updatePosition();
1183+
self._updatePosition(true);
11761184
resolve(self);
11771185
});
11781186
});
@@ -1181,13 +1189,20 @@ MdPanelRef.prototype._addStyles = function() {
11811189

11821190
/**
11831191
* Calculates and updates the position of the panel.
1192+
* @param {boolean=} opt_init
11841193
* @private
11851194
*/
1186-
MdPanelRef.prototype._updatePosition = function() {
1195+
MdPanelRef.prototype._updatePosition = function(opt_init) {
11871196
var positionConfig = this._config['position'];
11881197

11891198
if (positionConfig) {
11901199
positionConfig._setPanelPosition(this._panelEl);
1200+
1201+
// Hide the panel now that position is known.
1202+
if (opt_init) {
1203+
this._panelContainer.addClass(MD_PANEL_HIDDEN);
1204+
}
1205+
11911206
this._panelEl.css('top', positionConfig.getTop());
11921207
this._panelEl.css('bottom', positionConfig.getBottom());
11931208
this._panelEl.css('left', positionConfig.getLeft());

0 commit comments

Comments
 (0)