Skip to content

Commit

Permalink
fix(design): remove overflow style on destroy of sidebar-viewport (#2779
Browse files Browse the repository at this point in the history
)
  • Loading branch information
xelaint committed Apr 30, 2024
1 parent d2ce4fd commit cadc240
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
Inject,
SkipSelf,
Optional,
OnDestroy,
} from '@angular/core';

import { hasParentViewport } from './helper/has-parent-viewport';
Expand Down Expand Up @@ -74,7 +75,7 @@ import { DaffSidebarComponent } from '../sidebar/sidebar.component';
{ provide: DAFF_SIDEBAR_SCROLL_TOKEN, useFactory: daffSidebarViewportScrollFactory },
],
})
export class DaffSidebarViewportComponent implements AfterContentChecked {
export class DaffSidebarViewportComponent implements AfterContentChecked, OnDestroy {
@HostBinding('class.daff-sidebar-viewport') hostClass = true;

@HostBinding('class') get classes() {
Expand Down Expand Up @@ -208,6 +209,14 @@ export class DaffSidebarViewportComponent implements AfterContentChecked {
}
}

ngOnDestroy() {
if(!this.parentViewport && !hasParentViewport(this._elementRef.nativeElement)) {
this.bodyScroll.enable();
} else {
this.scroll.enable();
}
}

/**
* @docs-private
*
Expand Down
59 changes: 59 additions & 0 deletions libs/design/sidebar/src/sidebar-viewport/specs/destroy.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { A11yModule } from '@angular/cdk/a11y';
import { DOCUMENT } from '@angular/common';
import { Component } from '@angular/core';
import {
waitForAsync,
ComponentFixture,
TestBed,
} from '@angular/core/testing';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';

import { DaffSidebarViewportComponent } from './../sidebar-viewport.component';
import { DaffSidebarComponent } from '../../sidebar/sidebar.component';

@Component({
template: `
<daff-sidebar-viewport>
<daff-sidebar side="left" mode="over" [open]="true"></daff-sidebar>
</daff-sidebar-viewport>
`,
})

class WrapperOneComponent {}

describe('@daffodil/design/sidebar | DaffSidebarViewportComponent | On Destroy', () => {
let fixture: ComponentFixture<WrapperOneComponent>;
let component: WrapperOneComponent;

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [
NoopAnimationsModule,
A11yModule,
],
declarations: [
DaffSidebarViewportComponent,
DaffSidebarComponent,
WrapperOneComponent,
],
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(WrapperOneComponent);
component = fixture.componentInstance;

fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});

it('should not have `overflow: hidden` on the body when destroyed', () => {
fixture.destroy();

expect((TestBed.inject(DOCUMENT)).body.style.overflow).not.toEqual('hidden');
});
});

0 comments on commit cadc240

Please sign in to comment.