@cratis/components 2.6.1 → 2.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,19 +5,31 @@ var React = require('react');
5
5
  // Copyright (c) Cratis. All rights reserved.
6
6
  // Licensed under the MIT license. See LICENSE file in the project root for full license information.
7
7
  /**
8
- * Hook to force a specific z-index on PrimeReact overlay components.
9
- * This is a workaround for PrimeReact's automatic z-index calculation
10
- * which can cause overlays to appear behind dialogs.
8
+ * Hook that keeps a PrimeReact overlay panel at or above a minimum z-index.
9
+ *
10
+ * PrimeReact computes overlay z-indexes relative to whatever is currently open — in an application that
11
+ * configures the PrimeReact z-index tiers this already stacks panels above dialogs correctly. This hook is
12
+ * the safety net for applications that do not: when PrimeReact's computed value is *below* the floor, the
13
+ * panel is raised to it.
14
+ *
15
+ * It is strictly raise-only. It must never lower a value PrimeReact computed, for two reasons: the computed
16
+ * value is what stacks the panel above an open dialog's mask, and PrimeReact's `ZIndexUtils.clear()`
17
+ * un-registers an overlay by reading its inline z-index back — overwriting it with a different number makes
18
+ * that lookup miss, leaks the registry entry, and every dialog opened afterwards escalates its mask's
19
+ * z-index further above the panels until dropdowns render behind the very dialogs that host them.
11
20
  *
12
21
  * @param className - The CSS class name to target (e.g., 'location-autocomplete-overlay')
13
- * @param zIndex - The desired z-index value (default: 10000)
22
+ * @param minimumZIndex - The floor the panel must not sit below (default: 10000)
14
23
  */
15
- function useOverlayZIndex(className, zIndex = 10000) {
24
+ function useOverlayZIndex(className, minimumZIndex = 10000) {
16
25
  React.useEffect(() => {
17
26
  const observer = new MutationObserver(() => {
18
27
  const panel = document.querySelector(`.${className}`);
19
- if (panel instanceof HTMLElement && panel.style.zIndex !== zIndex.toString()) {
20
- panel.style.zIndex = zIndex.toString();
28
+ if (!(panel instanceof HTMLElement))
29
+ return;
30
+ const raised = raisedOverlayZIndex(panel.style.zIndex, minimumZIndex);
31
+ if (raised !== undefined) {
32
+ panel.style.zIndex = raised;
21
33
  }
22
34
  });
23
35
  observer.observe(document.body, {
@@ -27,8 +39,27 @@ function useOverlayZIndex(className, zIndex = 10000) {
27
39
  attributeFilter: ['style']
28
40
  });
29
41
  return () => observer.disconnect();
30
- }, [className, zIndex]);
42
+ }, [className, minimumZIndex]);
43
+ }
44
+ /**
45
+ * Decides whether an overlay panel's inline z-index must be raised to the floor.
46
+ *
47
+ * Raise-only by design: a value PrimeReact computed at or above the floor is left untouched, both because
48
+ * it is what stacks the panel above an open dialog and because PrimeReact reads it back to un-register the
49
+ * overlay when it closes.
50
+ *
51
+ * @param currentZIndex - The panel's current inline z-index value, possibly empty.
52
+ * @param minimumZIndex - The floor the panel must not sit below.
53
+ * @returns The value to assign, or undefined when the current value must be left alone.
54
+ */
55
+ function raisedOverlayZIndex(currentZIndex, minimumZIndex) {
56
+ const current = Number.parseInt(currentZIndex, 10);
57
+ if (Number.isNaN(current) || current < minimumZIndex) {
58
+ return minimumZIndex.toString();
59
+ }
60
+ return undefined;
31
61
  }
32
62
 
63
+ exports.raisedOverlayZIndex = raisedOverlayZIndex;
33
64
  exports.useOverlayZIndex = useOverlayZIndex;
34
65
  //# sourceMappingURL=useOverlayZIndex.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useOverlayZIndex.js","sources":["../../useOverlayZIndex.ts"],"sourcesContent":[null],"names":["useEffect"],"mappings":";;;;AAAA;AACA;AAIA;;;;;;;AAOG;SACa,gBAAgB,CAAC,SAAiB,EAAE,SAAiB,KAAK,EAAA;IACtEA,eAAS,CAAC,MAAK;AACX,QAAA,MAAM,QAAQ,GAAG,IAAI,gBAAgB,CAAC,MAAK;YACvC,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,CAAA,CAAA,EAAI,SAAS,CAAA,CAAE,CAAC;AACrD,YAAA,IAAI,KAAK,YAAY,WAAW,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC,QAAQ,EAAE,EAAE;gBAC1E,KAAK,CA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