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

Commit

Permalink
fix(drawer): Fixes an issue of width-drift when closing the drawer.
Browse files Browse the repository at this point in the history
With a lot of content in the drawer-content, the drawer-body was changing size due to the flex container around it.

Keeping track of the width when closing and setting it as a min and max width boundary, keeps the drawer-body from relayouting and prevents the drift.

Fixes APM-266068
  • Loading branch information
tomheller committed Nov 10, 2020
1 parent 76a8247 commit 0208470
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
All options in the filter field above
</dt-quick-filter-sub-title>

my content
<div>
my contentmy contentmy contentmy contentmy contentmy contentmy contentmy
contentmy contentmy contentmy contentmy contentmy contentmy contentmy
contentmy contentmy contentmy contentmy contentmy contentmy contentmy
contentmy contentmy contentmy contentmy contentmy contentmy content
</div>
</dt-quick-filter>

<button id="switchToFirstDatasource" (click)="switchToDataSource(0)">
Expand Down
6 changes: 5 additions & 1 deletion libs/barista-components/drawer/src/drawer.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<div class="dt-drawer-body">
<div
class="dt-drawer-body"
[style.min-width.px]="_closedWidth"
[style.max-width.px]="_closedWidth"
>
<ng-content></ng-content>
</div>
18 changes: 18 additions & 0 deletions libs/barista-components/drawer/src/drawer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ export class DtDrawer implements OnInit, AfterContentChecked, OnDestroy {
*/
_animationEnd = new Subject<AnimationEvent>();

/**
* @internal
* Width that will be set when the Drawer is closing to keep
* the drawer from relayouting and adjusting it's size
* due to the flex container.
*/
_closedWidth: number | null;

/** Used to skip the initial animation */
private _enableAnimations = false;

Expand Down Expand Up @@ -265,6 +273,16 @@ export class DtDrawer implements OnInit, AfterContentChecked, OnDestroy {
toggle(opened: boolean = !this.opened): void {
this._opened = opened;

// When the drawer is closed, we need to fix
// it's width to the original size to prevent relayout
// If the drawer would change size during this process,
// a drift would appear like in APM-266068
if (this._opened === false) {
this._closedWidth = this._width;
} else {
this._closedWidth = null;
}

this._animationState = opened
? this._enableAnimations
? 'open'
Expand Down

0 comments on commit 0208470

Please sign in to comment.