From 6f5404f7540dda9e799dee2cb1bded0102e17650 Mon Sep 17 00:00:00 2001
From: quentin <quentin.torck@aiso.com>
Date: Wed, 18 Mar 2020 08:35:47 +0100
Subject: [PATCH] navigate between popup

---
 package-lock.json                             | 76 ++++++++-----------
 package.json                                  |  2 +-
 .../shared-abstract-content.presentational.ts | 15 ++--
 ...ed-abstract-multi-select.presentational.ts | 30 +++-----
 ...d-multi-select-content.presentational.html |  5 +-
 ...-default-value-content.presentational.html |  5 +-
 ...e-multi-select-content.presentational.html |  6 +-
 ...-single-select-content.presentational.html |  5 +-
 src/app/shared/services/tabulation.service.ts |  2 +-
 src/app/shared/utils/number.util.ts           | 18 -----
 10 files changed, 62 insertions(+), 102 deletions(-)
 delete mode 100644 src/app/shared/utils/number.util.ts

diff --git a/package-lock.json b/package-lock.json
index 8696ea7a2..1fe3c87a2 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1559,6 +1559,7 @@
         "@angular/compiler": "^8.1.3",
         "boxen": "^4.1.0",
         "colorette": "^1.1.0",
+        "flat": "git://github.com/lenchvolodymyr/flat.git#ffe77efe8c33bc80ffb2f7a465537610dea4f611",
         "gettext-parser": "^4.0.1",
         "glob": "^7.1.4",
         "mkdirp": "^0.5.1",
@@ -1591,24 +1592,12 @@
           "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==",
           "dev": true
         },
-        "flat": {
-          "version": "git://github.com/lenchvolodymyr/flat.git#ffe77efe8c33bc80ffb2f7a465537610dea4f611",
-          "from": "git://github.com/lenchvolodymyr/flat.git#ffe77efe8c33bc80ffb2f7a465537610dea4f611",
-          "requires": {
-            "is-buffer": "~2.0.3"
-          }
-        },
         "get-caller-file": {
           "version": "2.0.5",
           "resolved": "https://packages.dlcm.ch/repository/npm-group/get-caller-file/-/get-caller-file-2.0.5.tgz",
           "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==",
           "dev": true
         },
-        "is-buffer": {
-          "version": "2.0.4",
-          "resolved": "https://nexus.unige.ch/repository/npm-all/is-buffer/-/is-buffer-2.0.4.tgz",
-          "integrity": "sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A=="
-        },
         "require-main-filename": {
           "version": "2.0.0",
           "resolved": "https://packages.dlcm.ch/repository/npm-group/require-main-filename/-/require-main-filename-2.0.0.tgz",
@@ -5399,6 +5388,22 @@
         "locate-path": "^3.0.0"
       }
     },
+    "flat": {
+      "version": "git://github.com/lenchvolodymyr/flat.git#ffe77efe8c33bc80ffb2f7a465537610dea4f611",
+      "from": "git://github.com/lenchvolodymyr/flat.git#ffe77ef",
+      "dev": true,
+      "requires": {
+        "is-buffer": "~2.0.3"
+      },
+      "dependencies": {
+        "is-buffer": {
+          "version": "2.0.4",
+          "resolved": "https://nexus.unige.ch/repository/npm-all/is-buffer/-/is-buffer-2.0.4.tgz",
+          "integrity": "sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A==",
+          "dev": true
+        }
+      }
+    },
     "flatted": {
       "version": "2.0.1",
       "resolved": "https://registry.npmjs.org/flatted/-/flatted-2.0.1.tgz",
@@ -5558,8 +5563,7 @@
         },
         "ansi-regex": {
           "version": "2.1.1",
-          "bundled": true,
-          "optional": true
+          "bundled": true
         },
         "aproba": {
           "version": "1.2.0",
@@ -5577,13 +5581,11 @@
         },
         "balanced-match": {
           "version": "1.0.0",
-          "bundled": true,
-          "optional": true
+          "bundled": true
         },
         "brace-expansion": {
           "version": "1.1.11",
           "bundled": true,
-          "optional": true,
           "requires": {
             "balanced-match": "^1.0.0",
             "concat-map": "0.0.1"
@@ -5596,18 +5598,15 @@
         },
         "code-point-at": {
           "version": "1.1.0",
-          "bundled": true,
-          "optional": true
+          "bundled": true
         },
         "concat-map": {
           "version": "0.0.1",
-          "bundled": true,
-          "optional": true
+          "bundled": true
         },
         "console-control-strings": {
           "version": "1.1.0",
-          "bundled": true,
-          "optional": true
+          "bundled": true
         },
         "core-util-is": {
           "version": "1.0.2",
@@ -5710,8 +5709,7 @@
         },
         "inherits": {
           "version": "2.0.3",
-          "bundled": true,
-          "optional": true
+          "bundled": true
         },
         "ini": {
           "version": "1.3.5",
@@ -5721,7 +5719,6 @@
         "is-fullwidth-code-point": {
           "version": "1.0.0",
           "bundled": true,
-          "optional": true,
           "requires": {
             "number-is-nan": "^1.0.0"
           }
@@ -5734,20 +5731,17 @@
         "minimatch": {
           "version": "3.0.4",
           "bundled": true,
-          "optional": true,
           "requires": {
             "brace-expansion": "^1.1.7"
           }
         },
         "minimist": {
           "version": "0.0.8",
-          "bundled": true,
-          "optional": true
+          "bundled": true
         },
         "minipass": {
           "version": "2.3.5",
           "bundled": true,
-          "optional": true,
           "requires": {
             "safe-buffer": "^5.1.2",
             "yallist": "^3.0.0"
@@ -5764,7 +5758,6 @@
         "mkdirp": {
           "version": "0.5.1",
           "bundled": true,
-          "optional": true,
           "requires": {
             "minimist": "0.0.8"
           }
@@ -5837,8 +5830,7 @@
         },
         "number-is-nan": {
           "version": "1.0.1",
-          "bundled": true,
-          "optional": true
+          "bundled": true
         },
         "object-assign": {
           "version": "4.1.1",
@@ -5848,7 +5840,6 @@
         "once": {
           "version": "1.4.0",
           "bundled": true,
-          "optional": true,
           "requires": {
             "wrappy": "1"
           }
@@ -5924,8 +5915,7 @@
         },
         "safe-buffer": {
           "version": "5.1.2",
-          "bundled": true,
-          "optional": true
+          "bundled": true
         },
         "safer-buffer": {
           "version": "2.1.2",
@@ -5955,7 +5945,6 @@
         "string-width": {
           "version": "1.0.2",
           "bundled": true,
-          "optional": true,
           "requires": {
             "code-point-at": "^1.0.0",
             "is-fullwidth-code-point": "^1.0.0",
@@ -5973,7 +5962,6 @@
         "strip-ansi": {
           "version": "3.0.1",
           "bundled": true,
-          "optional": true,
           "requires": {
             "ansi-regex": "^2.0.0"
           }
@@ -6012,13 +6000,11 @@
         },
         "wrappy": {
           "version": "1.0.2",
-          "bundled": true,
-          "optional": true
+          "bundled": true
         },
         "yallist": {
           "version": "3.0.3",
-          "bundled": true,
-          "optional": true
+          "bundled": true
         }
       }
     },
@@ -11346,9 +11332,9 @@
       }
     },
     "solidify-frontend": {
-      "version": "0.3.9",
-      "resolved": "https://nexus.unige.ch/repository/npm-all/solidify-frontend/-/solidify-frontend-0.3.9.tgz",
-      "integrity": "sha512-CxEF2Q2WwCXPNCtDTOkwGa3yjxA3CkQe+Fz9tngrWPzUBc62vm+K3sr9Yi8v+Badr5X0EaKDRK5oaqkK9xyQlA==",
+      "version": "0.3.10",
+      "resolved": "https://nexus.unige.ch/repository/npm-all/solidify-frontend/-/solidify-frontend-0.3.10.tgz",
+      "integrity": "sha512-GhhP+Co8D+3BOy+W6i6ibI35RBR6VWTIwgNRQjCtBrMTe/36eon0IsCmfUJokZH1TuDmA6RpdrePGNDTOdhS7g==",
       "requires": {
         "tslib": "^1.9.0"
       }
diff --git a/package.json b/package.json
index d60bc878c..73cb4bc40 100644
--- a/package.json
+++ b/package.json
@@ -79,7 +79,7 @@
     "primeicons": "2.0.0",
     "primeng": "8.0.4",
     "rxjs": "6.5.3",
-    "solidify-frontend": "0.3.9",
+    "solidify-frontend": "0.3.10",
     "streamsaver": "2.0.3",
     "sync-pom-version-to-package": "1.3.1",
     "ts-key-enum": "2.0.0",
diff --git a/src/app/shared/components/presentationals/shared-abstract-content/shared-abstract-content.presentational.ts b/src/app/shared/components/presentationals/shared-abstract-content/shared-abstract-content.presentational.ts
index 89f21b724..a7e7570fa 100644
--- a/src/app/shared/components/presentationals/shared-abstract-content/shared-abstract-content.presentational.ts
+++ b/src/app/shared/components/presentationals/shared-abstract-content/shared-abstract-content.presentational.ts
@@ -38,12 +38,18 @@ export abstract class SharedAbstractContentPresentational<TResource extends Base
     super();
   }
 
-  closeByTab(): void {
-    this._closeByTabBS.next();
+  closeByTab(keyEvent: KeyboardEvent): void {
+    if (!keyEvent.defaultPrevented) {
+      keyEvent.preventDefault();
+      this._closeByTabBS.next();
+    }
   }
 
-  closeByShiftTab(): void {
-    this._closeByShiftTabBS.next();
+  closeByShiftTab(keyEvent: KeyboardEvent): void {
+    if (!keyEvent.defaultPrevented) {
+      keyEvent.preventDefault();
+      this._closeByShiftTabBS.next();
+    }
   }
 
   ngOnInit(): void {
@@ -70,7 +76,6 @@ export abstract class SharedAbstractContentPresentational<TResource extends Base
   }
 
   selectNextResource(): void {
-    debugger
     const val = this.host.list;
     let activeValIndex = -1;
     for (let index = 0; index < val.length; index++) {
diff --git a/src/app/shared/components/presentationals/shared-abstract-multi-select/shared-abstract-multi-select.presentational.ts b/src/app/shared/components/presentationals/shared-abstract-multi-select/shared-abstract-multi-select.presentational.ts
index efd8a77d5..797571a4d 100644
--- a/src/app/shared/components/presentationals/shared-abstract-multi-select/shared-abstract-multi-select.presentational.ts
+++ b/src/app/shared/components/presentationals/shared-abstract-multi-select/shared-abstract-multi-select.presentational.ts
@@ -183,6 +183,7 @@ export abstract class SharedAbstractMultiSelectPresentational<TResource extends
         this.formControl.markAsTouched();
         if (this.closeAfterValueSelected) {
           this._closeOverlay(overlayRef);
+          this._tabulationService.focusNext(this._elementToReFocus);
         } else {
           overlayRef.updatePosition();
         }
@@ -196,6 +197,7 @@ export abstract class SharedAbstractMultiSelectPresentational<TResource extends
         this.formControl.markAsTouched();
         if (this.closeAfterValueSelected) {
           this._closeOverlay(overlayRef);
+          this._tabulationService.focusNext(this._elementToReFocus);
         } else {
           overlayRef.updatePosition();
         }
@@ -207,6 +209,7 @@ export abstract class SharedAbstractMultiSelectPresentational<TResource extends
     this.subscribe(componentRef.instance.closeObs.pipe(
       tap(() => {
         this._closeOverlay(overlayRef);
+        this._tabulationService.focusNext(this._elementToReFocus);
       }),
     ));
   }
@@ -216,45 +219,30 @@ export abstract class SharedAbstractMultiSelectPresentational<TResource extends
     this.subscribe(overlayRef.backdropClick().pipe(
       tap(() => {
         this._closeOverlay(overlayRef);
+        this._tabulationService.focusNext(this._elementToReFocus);
       }),
     ));
     this.subscribe(componentRef.instance.closeByTabObs.pipe(
       tap(() => {
-          debugger
-          this._closeOverlay(overlayRef, true);
+        this._closeOverlay(overlayRef);
+        this._tabulationService.focusNext(this._elementToReFocus);
         },
       )));
     this.subscribe(componentRef.instance.closeByShiftTabObs.pipe(
       tap(() => {
-          debugger
-          this._closeOverlay(overlayRef, false);
+        this._closeOverlay(overlayRef);
+        this._tabulationService.focusPrev(this._elementToReFocus);
         },
       )));
   }
 
-  private _closeOverlay(overlayRef: OverlayRef, isByTab: boolean = true, keepInOverlayRefs?: boolean): void {
-    debugger
+  private _closeOverlay(overlayRef: OverlayRef, keepInOverlayRefs?: boolean): void {
     overlayRef.detach();
     if (!keepInOverlayRefs) {
       this._overlayRefs.delete(overlayRef);
     }
     this.formControl.markAsTouched();
     this._changeDetector.detectChanges();
-    if (isByTab) {
-      this._tabulationService.focusNext(this._elementToReFocus);
-    } else {
-      this._tabulationService.focusPrev(this._elementToReFocus);
-    }
-  }
-
-  private _closeOverlays(isByTab: boolean = true): void {
-    this._overlayRefs.forEach(overlayRef => this._closeOverlay(overlayRef, isByTab, true));
-    this._overlayRefs.clear();
-  }
-
-  closeOverlays(keyEvent: KeyboardEvent, isByTab: boolean = true): void {
-    keyEvent.preventDefault();
-    this._closeOverlays(isByTab);
   }
 
   private _getPosition(elementToConnectTo: ElementRef): FlexibleConnectedPositionStrategy {
diff --git a/src/app/shared/components/presentationals/shared-multi-select-content/shared-multi-select-content.presentational.html b/src/app/shared/components/presentationals/shared-multi-select-content/shared-multi-select-content.presentational.html
index 4d08f8c19..bce05e876 100644
--- a/src/app/shared/components/presentationals/shared-multi-select-content/shared-multi-select-content.presentational.html
+++ b/src/app/shared/components/presentationals/shared-multi-select-content/shared-multi-select-content.presentational.html
@@ -1,8 +1,7 @@
 <lib-empty-container solidifyShortCuts
-                     cdkTrapFocus
                      [solidifyFocusFirstElement]="true"
-                     (keydown.tab)="closeByTab()"
-                     (keydown.shift.tab)="closeByShiftTab()"
+                     (keydown.tab)="closeByTab($event)"
+                     (keydown.shift.tab)="closeByShiftTab($event)"
                      (onEscape)="close()"
                      (keydown.enter)="select(host.list[indexSelected])"
 >
diff --git a/src/app/shared/components/presentationals/shared-multi-select-default-value-content/shared-multi-select-default-value-content.presentational.html b/src/app/shared/components/presentationals/shared-multi-select-default-value-content/shared-multi-select-default-value-content.presentational.html
index df8cd9fa6..128d60be6 100644
--- a/src/app/shared/components/presentationals/shared-multi-select-default-value-content/shared-multi-select-default-value-content.presentational.html
+++ b/src/app/shared/components/presentationals/shared-multi-select-default-value-content/shared-multi-select-default-value-content.presentational.html
@@ -1,8 +1,7 @@
 <lib-empty-container [solidifyFocusFirstElement]="true"
                      solidifyShortCuts
-                     cdkTrapFocus
-                     (keydown.tab)="closeByTab()"
-                     (keydown.shift.tab)="closeByShiftTab()"
+                     (keydown.tab)="closeByTab($event)"
+                     (keydown.shift.tab)="closeByShiftTab($event)"
                      (onEscape)="close()"
                      (onEnter)="select(host.list[indexSelected])"
 >
diff --git a/src/app/shared/components/presentationals/shared-searchable-multi-select-content/shared-searchable-multi-select-content.presentational.html b/src/app/shared/components/presentationals/shared-searchable-multi-select-content/shared-searchable-multi-select-content.presentational.html
index 6b574c752..7cece37a4 100644
--- a/src/app/shared/components/presentationals/shared-searchable-multi-select-content/shared-searchable-multi-select-content.presentational.html
+++ b/src/app/shared/components/presentationals/shared-searchable-multi-select-content/shared-searchable-multi-select-content.presentational.html
@@ -1,8 +1,8 @@
 <form [formGroup]="form"
       [dlcmAutoScrollIntoView]="!navigationResId"
-      (keydown.tab)="closeByTab()"
-      (keydown.escape)="closeByTab()"
-      (keydown.shift.tab)="closeByShiftTab()"
+      (keydown.tab)="closeByTab($event)"
+      (keydown.escape)="closeByTab($event)"
+      (keydown.shift.tab)="closeByShiftTab($event)"
 >
   <div class="input">
     <mat-form-field class="form-field">
diff --git a/src/app/shared/components/presentationals/shared-searchable-single-select-content/shared-searchable-single-select-content.presentational.html b/src/app/shared/components/presentationals/shared-searchable-single-select-content/shared-searchable-single-select-content.presentational.html
index 19b18d5ce..ead3672a3 100644
--- a/src/app/shared/components/presentationals/shared-searchable-single-select-content/shared-searchable-single-select-content.presentational.html
+++ b/src/app/shared/components/presentationals/shared-searchable-single-select-content/shared-searchable-single-select-content.presentational.html
@@ -1,8 +1,9 @@
 <form [formGroup]="form"
       [dlcmAutoScrollIntoView]="!navigationResId"
-      (keydown.shift.tab)="closeByShiftTab()"
+      (keydown.shift.tab)="closeByShiftTab($event)"
       (keydown.enter)="select(getFocusedResource())"
-      (keydown.tab)="closeByTab()">
+      (keydown.tab)="closeByTab($event)"
+>
   <div class="input">
     <mat-form-field class="form-field">
       <input #input
diff --git a/src/app/shared/services/tabulation.service.ts b/src/app/shared/services/tabulation.service.ts
index 99b5e17e5..606746769 100644
--- a/src/app/shared/services/tabulation.service.ts
+++ b/src/app/shared/services/tabulation.service.ts
@@ -5,12 +5,12 @@ import {
   Inject,
   Injectable,
 } from "@angular/core";
-import {NumberUtil} from "@shared/utils/number.util";
 import {
   isElement,
   isFunction,
   isHtmlElement,
   isTruthyObject,
+  NumberUtil,
 } from "solidify-frontend";
 
 @Injectable({providedIn: "root"})
diff --git a/src/app/shared/utils/number.util.ts b/src/app/shared/utils/number.util.ts
deleted file mode 100644
index 121f0e02b..000000000
--- a/src/app/shared/utils/number.util.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-import {isNumber} from "solidify-frontend";
-
-export class NumberUtil {
-  static isBetween(value: number,
-                   lowerBound: number = -Infinity,
-                   upperBound: number = Infinity,
-                   orEqualLowerBound?: boolean,
-                   orEqualUpperBound: boolean = orEqualLowerBound): boolean {
-    if (!isNumber(value) || !isNumber(lowerBound) || !isNumber(upperBound)) {
-      return false;
-    }
-    if (lowerBound > upperBound) {
-      return false;
-    }
-    return (orEqualLowerBound ? value >= lowerBound : value > lowerBound)
-      && (orEqualUpperBound ? value <= upperBound : value < upperBound);
-  }
-}
-- 
GitLab