Skip to content

Commit

Permalink
fix(ui5-dialog): improved shrinking dialog when resizing (#5291)
Browse files Browse the repository at this point in the history
When resizing the dialog to its smallest possible size, the header and
footer slot now retain their height. It is assumed that the header or
footer will not change their dimensions while the user is resizing.

Fixes: #5265
  • Loading branch information
georgimkv authored Jun 3, 2022
1 parent 8eea51e commit 997f2a2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
40 changes: 27 additions & 13 deletions packages/main/src/Dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,22 @@ class Dialog extends Popup {
return this.resizable && this.onDesktop;
}

get _minHeight() {
let minHeight = Number.parseInt(window.getComputedStyle(this.contentDOM).minHeight);

const header = this._root.querySelector(".ui5-popup-header-root");
if (header) {
minHeight += header.offsetHeight;
}

const footer = this._root.querySelector(".ui5-popup-footer-root");
if (footer) {
minHeight += footer.offsetHeight;
}

return minHeight;
}

_show() {
super._show();
this._center();
Expand Down Expand Up @@ -465,7 +481,6 @@ class Dialog extends Popup {
const { top, left } = this.getBoundingClientRect(),
style = window.getComputedStyle(this),
minWidth = Number.parseFloat(style.minWidth),
minHeight = Number.parseFloat(style.minHeight),
maxWidth = window.innerWidth - left,
maxHeight = window.innerHeight - top;

Expand All @@ -488,7 +503,7 @@ class Dialog extends Popup {
}

width = clamp(width, minWidth, maxWidth);
height = clamp(height, minHeight, maxHeight);
height = clamp(height, this._minHeight, maxHeight);

Object.assign(this.style, {
width: `${width}px`,
Expand Down Expand Up @@ -523,7 +538,6 @@ class Dialog extends Popup {
width,
height,
minWidth,
minHeight,
} = window.getComputedStyle(this);

this._initialX = event.clientX;
Expand All @@ -533,7 +547,7 @@ class Dialog extends Popup {
this._initialTop = top;
this._initialLeft = left;
this._minWidth = Number.parseFloat(minWidth);
this._minHeight = Number.parseFloat(minHeight);
this._cachedMinHeight = this._minHeight;

Object.assign(this.style, {
top: `${top}px`,
Expand Down Expand Up @@ -571,7 +585,7 @@ class Dialog extends Popup {

const newHeight = clamp(
this._initialHeight + (clientY - this._initialY),
this._minHeight,
this._cachedMinHeight,
window.innerHeight - this._initialTop,
);

Expand All @@ -583,14 +597,14 @@ class Dialog extends Popup {
}

_onResizeMouseUp() {
this._initialX = null;
this._initialY = null;
this._initialWidth = null;
this._initialHeight = null;
this._initialTop = null;
this._initialLeft = null;
this._minWidth = null;
this._minHeight = null;
delete this._initialX;
delete this._initialY;
delete this._initialWidth;
delete this._initialHeight;
delete this._initialTop;
delete this._initialLeft;
delete this._minWidth;
delete this._cachedMinHeight;

this._detachMouseResizeHandlers();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/main/test/pages/Dialog.html
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@
<p>Resize this dialog by dragging it by its resize handle or use shift+arrow keys.</p>
<p>This feature is available only on Desktop.</p>

<div slot="footer" class="dialogFooter">
<div slot="footer" class="dialogFooter tallFooter">
<ui5-button id="draggable-and-resizable-close" design="Emphasized">Close</ui5-button>
</div>
</ui5-dialog>
Expand Down
4 changes: 4 additions & 0 deletions packages/main/test/pages/styles/Dialog.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@
padding-right: 0;
padding-left: 0;
}

.tallFooter {
height: 4rem;
}

0 comments on commit 997f2a2

Please sign in to comment.