diff --git a/projects/dxc-ngx-cdk/src/lib/dxc-application-layout/dxc-application-layout-sidenav/dxc-application-layout-sidenav.component.html b/projects/dxc-ngx-cdk/src/lib/dxc-application-layout/dxc-application-layout-sidenav/dxc-application-layout-sidenav.component.html
index 4917bf47d..0574a31b1 100644
--- a/projects/dxc-ngx-cdk/src/lib/dxc-application-layout/dxc-application-layout-sidenav/dxc-application-layout-sidenav.component.html
+++ b/projects/dxc-ngx-cdk/src/lib/dxc-application-layout/dxc-application-layout-sidenav/dxc-application-layout-sidenav.component.html
@@ -4,7 +4,7 @@
{
+ beforeAll(() => {
+ Object.defineProperty(window, "matchMedia", {
+ writable: true,
+ value: jest.fn().mockImplementation(() => ({
+ matches: false,
+ })),
+ });
+ });
+
test("should render dxc-header", async () => {
await render(``, {
imports: [PipesModule, BackgroundProviderInnerModule],
@@ -42,6 +51,12 @@ describe("DxcHeader tests", () => {
configurable: true,
value: 375,
});
+ Object.defineProperty(window, "matchMedia", {
+ writable: true,
+ value: jest.fn().mockImplementation(() => ({
+ matches: true,
+ })),
+ });
TestBed.overrideComponent(DxcHeaderComponent, {
set: { selector: "header" },
});
diff --git a/projects/dxc-ngx-cdk/src/lib/dxc-header/dxc-header.component.ts b/projects/dxc-ngx-cdk/src/lib/dxc-header/dxc-header.component.ts
index d8aa4c0b5..0d6279ac1 100644
--- a/projects/dxc-ngx-cdk/src/lib/dxc-header/dxc-header.component.ts
+++ b/projects/dxc-ngx-cdk/src/lib/dxc-header/dxc-header.component.ts
@@ -83,8 +83,6 @@ export class DxcHeaderComponent implements OnChanges {
isResponsive = false;
isMenuVisible = false;
- innerWidth;
- innerHeight;
responsiveMenu: string;
isClickDefined = false;
@@ -99,14 +97,10 @@ export class DxcHeaderComponent implements OnChanges {
padding: null,
});
- @HostListener("window:resize", ["$event"])
- onResize(event) {
- this.innerWidth = event.target.innerWidth;
- this.innerHeight = event.target.innerHeight;
- if (this.innerWidth <= responsiveSizes.tablet) {
- this.isResponsive = true;
- } else {
- this.isResponsive = false;
+ @HostListener('window:resize', ['$event'])
+ onResize() {
+ this.isResponsive = window.matchMedia(`(max-width: ${responsiveSizes.medium}rem)`).matches;
+ if(!this.isResponsive) {
this.isMenuVisible = false;
}
this.updateCss();
@@ -115,40 +109,26 @@ export class DxcHeaderComponent implements OnChanges {
constructor(private utils: CssUtils, private elRef: ElementRef) {}
updateCss() {
- if (this.isMenuVisible) {
- this.elRef.nativeElement.ownerDocument.body.style.overflow = "hidden";
- } else {
- this.elRef.nativeElement.ownerDocument.body.style.overflow = null;
- }
+
this.currentBackgroundColor = this.utils.readProperty(
"--header-backgroundColor"
);
this.className = `${this.getDynamicStyle({
...this.defaultInputs.getValue(),
isMenuVisible: this.isMenuVisible,
- isResponsive: this.isResponsive,
- innerWidth: this.innerWidth,
- innerHeight: this.innerHeight,
+ isResponsive: this.isResponsive
})}`;
this.responsiveMenu = `${this.getResponsiveMenuStyle({
...this.defaultInputs.getValue(),
isMenuVisible: this.isMenuVisible,
- isResponsive: this.isResponsive,
- innerWidth: this.innerWidth,
- innerHeight: this.innerHeight,
+ isResponsive: this.isResponsive
})}`;
}
public ngOnInit() {
this.isClickDefined = this.onClick.observers?.length > 0;
- this.innerWidth = window.innerWidth;
- this.innerHeight = window.innerHeight;
- if (this.innerWidth <= responsiveSizes.tablet && !this.isResponsive) {
- this.isResponsive = true;
- } else {
- this.isResponsive = false;
- }
+ this.isResponsive = window.matchMedia(`(max-width: ${responsiveSizes.medium}rem)`).matches;
this.updateCss();
}
@@ -298,12 +278,12 @@ export class DxcHeaderComponent implements OnChanges {
top: 0;
left: 0;
width: 100vw;
- height: ${inputs.innerHeight}px;
+ height: 100vh;
background-color: var(--header-overlayColor);
opacity: var(--header-overlayOpacity) !important;
- display: ${inputs.innerWidth <= responsiveSizes.mobileLarge
- ? "none"
- : ""};
+ @media (max-width: ${responsiveSizes.small}rem) {
+ display: none;
+ }
transition: opacity 0.2s 0.2s ease-in-out;
z-index: var(--header-overlayZindex);
}
@@ -322,11 +302,15 @@ export class DxcHeaderComponent implements OnChanges {
right: 0;
z-index: var(--header-menuZindex);
- width: ${inputs.innerWidth <= responsiveSizes.laptop &&
- inputs.innerWidth > responsiveSizes.mobileLarge
- ? "var(--header-menuTabletWidth)"
- : "var(--header-menuMobileWidth)"};
- height: ${inputs.innerHeight}px;
+
+ @media (max-width: ${responsiveSizes.large}rem) and (min-width: ${responsiveSizes.small}rem) {
+ width: "var(--header-menuTabletWidth)";
+ }
+ @media not((max-width: ${responsiveSizes.large}rem) and (min-width: ${responsiveSizes.small}rem)) {
+ width: "var(--header-menuMobileWidth)"};
+ }
+
+ height: 100vh;
padding: 20px;
${this.checkMenuVisible(inputs.isMenuVisible)}
diff --git a/projects/dxc-ngx-cdk/src/lib/variables.ts b/projects/dxc-ngx-cdk/src/lib/variables.ts
index 47bf7a98d..6b743e911 100644
--- a/projects/dxc-ngx-cdk/src/lib/variables.ts
+++ b/projects/dxc-ngx-cdk/src/lib/variables.ts
@@ -26,10 +26,9 @@ export const colors = {
};
export const responsiveSizes = {
- mobileSmall: 320,
- mobileMedium: 375,
- mobileLarge: 425,
- tablet: 768,
- laptop: 1024,
- desktop: 1440
+ xsmall: "20",
+ small: "30",
+ medium: "45",
+ large: "66",
+ xlarge: "90",
}
\ No newline at end of file