Skip to content

Commit 7496fde

Browse files
authored
Merge pull request #14254 from IgniteUI/simeonoff/navdrawer-flexBasis
fix(navdrawer): pinned mini drawer should work with position fixed
2 parents 137a100 + bbb4792 commit 7496fde

File tree

2 files changed

+79
-3
lines changed

2 files changed

+79
-3
lines changed

projects/igniteui-angular/src/lib/navigation-drawer/navigation-drawer.component.spec.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import { IgxNavigationService } from '../core/navigation/nav.service';
77
import { PlatformUtil } from '../core/utils';
88
import { IgxNavDrawerMiniTemplateDirective, IgxNavDrawerTemplateDirective } from './navigation-drawer.directives';
99
import { NgIf } from '@angular/common';
10+
import { IgxLayoutModule } from '../directives/layout/layout.module';
11+
import { IgxNavbarModule } from '../navbar/navbar.module';
12+
import { IgxNavbarComponent } from '../navbar/navbar.component';
1013

1114
// HammerJS simulator from https://github.com/hammerjs/simulator, manual typings TODO
1215
declare let Simulator: any;
@@ -567,6 +570,37 @@ describe('Navigation Drawer', () => {
567570
expect(fix.componentInstance.navDrawer.element.classList.contains('igx-nav-drawer')).toBeTruthy();
568571
});
569572

573+
it('should maintain size when mini pinned has `fixed` position', async () => {
574+
const fix = TestBed.createComponent(TestFixedMiniComponent);
575+
fix.detectChanges();
576+
577+
fix.componentInstance.navDrawer.pin = true;
578+
fix.detectChanges();
579+
580+
// Account for transition duration
581+
await wait(350);
582+
583+
const drawerEl = fix.debugElement.query(By.directive(IgxNavigationDrawerComponent)).nativeElement;
584+
const navbarEl = fix.debugElement.query(By.directive(IgxNavbarComponent)).nativeElement;
585+
586+
let flexBasis = getComputedStyle(drawerEl).getPropertyValue('flex-basis');
587+
588+
// Mini variant pinned by default
589+
expect(flexBasis).toEqual('68px');;
590+
expect(navbarEl.offsetLeft).toEqual(parseInt(flexBasis));
591+
592+
fix.componentInstance.navDrawer.toggle();
593+
fix.detectChanges();
594+
595+
// Account for transition duration
596+
await wait(350);
597+
598+
flexBasis = getComputedStyle(drawerEl).getPropertyValue('flex-basis');
599+
600+
expect(flexBasis).toEqual('240px');;
601+
expect(navbarEl.offsetLeft).toEqual(parseInt(flexBasis));
602+
});
603+
570604
const swipe = (element, posX, posY, duration, deltaX, deltaY) => {
571605
const swipeOptions = {
572606
deltaX,
@@ -650,3 +684,45 @@ class TestComponentPinComponent extends TestComponentDIComponent {
650684
class TestComponentMiniComponent extends TestComponentDIComponent {
651685
public miniView = true;
652686
}
687+
688+
@Component({
689+
selector: 'igx--test-fixed-mini',
690+
providers: [IgxNavigationService],
691+
standalone: true,
692+
imports: [
693+
IgxLayoutModule,
694+
IgxNavbarModule,
695+
IgxNavigationDrawerComponent,
696+
IgxNavDrawerTemplateDirective,
697+
IgxNavDrawerMiniTemplateDirective,
698+
NgIf,
699+
],
700+
styles: `
701+
.igx-nav-drawer__aside--pinned {
702+
position: fixed;
703+
}
704+
`,
705+
template: `
706+
<div igxLayout>
707+
<igx-nav-drawer #nav>
708+
<ng-template igxDrawer>
709+
<span igxDrawerItem>Item</span>
710+
</ng-template>
711+
712+
<ng-template igxDrawerMini *ngIf="nav.pin">
713+
<nav>
714+
<span igxDrawerItem>Item</span>
715+
</nav>
716+
</ng-template>
717+
</igx-nav-drawer>
718+
719+
<div igxFlex igxLayout igxLayoutDir="columns">
720+
<igx-navbar title="Navbar" actionButtonIcon="menu" (action)="nav.toggle()">
721+
</igx-navbar>
722+
<div class="main"></div>
723+
</div>
724+
</div>
725+
`,
726+
})
727+
class TestFixedMiniComponent extends TestComponentDIComponent {
728+
}

projects/igniteui-angular/src/lib/navigation-drawer/navigation-drawer.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,17 +320,17 @@ export class IgxNavigationDrawerComponent implements
320320
*/
321321
@HostBinding('style.flexBasis')
322322
public get flexWidth() {
323-
if (!this.pin) {
323+
if (!this.pin || (!this.isOpen && !this.miniTemplate)) {
324324
return '0px';
325325
}
326+
326327
if (this.isOpen) {
327328
return this.width;
328329
}
330+
329331
if (this.miniTemplate && this.miniWidth) {
330332
return this.miniWidth;
331333
}
332-
333-
return '0px';
334334
}
335335

336336
/** @hidden */

0 commit comments

Comments
 (0)