Fix regression my-account menu overflow-x on screen width < 800px (#2707)
authorKim <1877318+kimsible@users.noreply.github.com>
Mon, 11 May 2020 09:12:58 +0000 (11:12 +0200)
committerGitHub <noreply@github.com>
Mon, 11 May 2020 09:12:58 +0000 (11:12 +0200)
* Fix: correct my-account menu overflow-x on touchscreens

* Add menuLeftDisplayed support for account-sub-menu

* Handle menu in screen service + clean top-menu-dropdown

* Add comment on menuWidth menu service to allow backtracking

Co-authored-by: Rigel Kent <par@rigelk.eu>
Co-authored-by: kimsible <kimsible@users.noreply.github.com>
Co-authored-by: Rigel Kent <par@rigelk.eu>
client/src/app/core/menu/menu.service.ts
client/src/app/shared/menu/top-menu-dropdown.component.html
client/src/app/shared/menu/top-menu-dropdown.component.ts
client/src/app/shared/misc/screen.service.ts
client/src/sass/application.scss

index ecb2bceb7d4768fcf3cb5bd148ffb10c77111574..81093c6663c5cd4daccbe8de0bb1090068a7cc75 100644 (file)
@@ -7,6 +7,7 @@ import { debounceTime } from 'rxjs/operators'
 export class MenuService {
   isMenuDisplayed = true
   isMenuChangedByUser = false
+  menuWidth = 240  // should be kept equal to $menu-width
 
   constructor (
     private screenService: ScreenService
index d577f757d0bcd1a7893c348b7011120204583d39..07ec1ac979fd255f1908d1410e8677cbd1a2b1dd 100644 (file)
@@ -3,7 +3,7 @@
 
     <a *ngIf="menuEntry.routerLink" [routerLink]="menuEntry.routerLink" routerLinkActive="active" class="title-page title-page-settings">{{ menuEntry.label }}</a>
 
-    <div *ngIf="!menuEntry.routerLink" ngbDropdown [container]="container" class="parent-entry"
+    <div *ngIf="!menuEntry.routerLink" ngbDropdown container="body" class="parent-entry"
       #dropdown="ngbDropdown" (mouseleave)="closeDropdownIfHovered(dropdown)">
       <span
         *ngIf="isInSmallView"
index f982408046e93c777f868fde80fd6282a841705c..3f121e785b63a7e48242ce376d707dc8214b05d1 100644 (file)
@@ -11,6 +11,7 @@ import { Subscription } from 'rxjs'
 import { NgbDropdown, NgbModal } from '@ng-bootstrap/ng-bootstrap'
 import { GlobalIconName } from '@app/shared/images/global-icon.component'
 import { ScreenService } from '@app/shared/misc/screen.service'
+import { MenuService } from '@app/core/menu'
 
 export type TopMenuDropdownParam = {
   label: string
@@ -36,7 +37,6 @@ export class TopMenuDropdownComponent implements OnInit, OnDestroy {
 
   suffixLabels: { [ parentLabel: string ]: string }
   hasIcons = false
-  container: undefined | 'body' = undefined
   isModalOpened = false
   currentMenuEntryIndex: number
 
@@ -46,11 +46,17 @@ export class TopMenuDropdownComponent implements OnInit, OnDestroy {
   constructor (
     private router: Router,
     private modalService: NgbModal,
-    private screen: ScreenService
+    private screen: ScreenService,
+    private menuService: MenuService
   ) { }
 
   get isInSmallView () {
-    return this.screen.isInSmallView()
+    let marginLeft = 0
+    if (this.menuService.isMenuDisplayed) {
+      marginLeft = this.menuService.menuWidth
+    }
+
+    return this.screen.isInSmallView(marginLeft)
   }
 
   ngOnInit () {
@@ -63,11 +69,6 @@ export class TopMenuDropdownComponent implements OnInit, OnDestroy {
     this.hasIcons = this.menuEntries.some(
       e => e.children && e.children.some(c => !!c.iconName)
     )
-
-    // We have to set body for the container to avoid scroll overflow on mobile and small views
-    if (this.isInSmallView) {
-      this.container = 'body'
-    }
   }
 
   ngOnDestroy () {
index 9c71a8c831587a5df2d7136145f9b537be039b8e..fa9c71e5bfd94800f228d4054838133be41f1ae9 100644 (file)
@@ -10,7 +10,12 @@ export class ScreenService {
     this.refreshWindowInnerWidth()
   }
 
-  isInSmallView () {
+  isInSmallView (marginLeft = 0) {
+    if (marginLeft > 0) {
+      const contentWidth = this.getWindowInnerWidth() - marginLeft
+      return contentWidth < 800
+    }
+
     return this.getWindowInnerWidth() < 800
   }
 
index bbecd8ba803e94fc2cd35c232182b4532bf1b3dd..d637c94d98274d988527ab17de7e41237a6f29c8 100644 (file)
@@ -320,6 +320,7 @@ table {
         padding-left: 15px;
         padding-right: 15px;
         margin-bottom: $sub-menu-margin-bottom-small-view;
+        overflow-x: auto;
       }
 
       .admin-sub-header {
@@ -388,6 +389,11 @@ table {
       .admin-sub-header {
         @include admin-sub-header-responsive($expanded-horizontal-margins/3 + $menu-width/2);
       }
+
+      .sub-menu {
+        overflow-x: auto;
+        width: calc(100vw - #{$menu-width});
+      }
     }
   }
 }