@db-ux/ngx-core-components 4.4.0 → 4.4.1-floating-components-066d296

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @db-ux/ngx-core-components
2
2
 
3
+ ## 4.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: issue with tailwind not reflecting adaptive color changes with `[data-color="xxx"]` - [see commit 936638d](https://github.com/db-ux-design-system/core-web/commit/936638d672bbb6c0f8a0ecf77bf41fafa0e31656)
8
+
9
+ - DBCustomSelect: Prevent floating label from flickering during initial render - [see commit e5ceff8](https://github.com/db-ux-design-system/core-web/commit/e5ceff861534186cf86d1f5f0a876e04aeac9e41)
10
+
3
11
  ## 4.4.0
4
12
 
5
13
  ### Minor Changes
@@ -1818,9 +1818,53 @@ const getFloatingProps = (element, parent, placement) => {
1818
1818
  innerHeight
1819
1819
  };
1820
1820
  };
1821
+ const MAX_ANCESTOR_DEPTH = 10;
1822
+ const ancestorCache = new WeakMap();
1823
+ const getAncestorHasCorrectedPlacement = (element) => {
1824
+ if (ancestorCache.has(element)) {
1825
+ return ancestorCache.get(element);
1826
+ }
1827
+ let current = element.parentElement;
1828
+ let anchor = 0;
1829
+ while (current && anchor < MAX_ANCESTOR_DEPTH) {
1830
+ if (current.dataset['correctedPlacement']) {
1831
+ ancestorCache.set(element, current);
1832
+ return current;
1833
+ }
1834
+ current = current.parentElement;
1835
+ anchor += 1;
1836
+ }
1837
+ ancestorCache.set(element, null);
1838
+ return null;
1839
+ };
1821
1840
  const handleFixedPopover = (element, parent, placement) => {
1822
- const distance = getComputedStyle(element).getPropertyValue('--db-popover-distance') ?? '0px';
1823
- const { top, height, width, childHeight, childWidth, right, left, bottom, correctedPlacement, innerWidth, innerHeight } = getFloatingProps(element, parent, placement);
1841
+ const parentComputedStyles = getComputedStyle(parent);
1842
+ const parentHasFloatingPosition = ['absolute', 'fixed'].includes(parentComputedStyles.position);
1843
+ const ancestorWithCorrectedPlacement = getAncestorHasCorrectedPlacement(element);
1844
+ const noFloatingAncestor = !ancestorWithCorrectedPlacement && !parentHasFloatingPosition;
1845
+ const distance = getComputedStyle(element)?.getPropertyValue('--db-popover-distance') ?? '0px';
1846
+ let { top, height, width, childHeight, childWidth, right, left, bottom, correctedPlacement, innerWidth, innerHeight } = getFloatingProps(element, parent, placement);
1847
+ if (ancestorWithCorrectedPlacement) {
1848
+ const ancestorRect = ancestorWithCorrectedPlacement.getBoundingClientRect();
1849
+ left = Math.abs(left - ancestorRect.left);
1850
+ right = (width + Math.abs(right - ancestorRect.right)) * 1.5; // We add a transform -50% later
1851
+ top = Math.abs(top - ancestorRect.top);
1852
+ bottom = (height + Math.abs(bottom - ancestorRect.bottom)) * 1.5; // We add a transform -50% later
1853
+ }
1854
+ if (parentHasFloatingPosition) {
1855
+ /*
1856
+ * If we have a floating element inside an element with position:absolute/fixed
1857
+ * we need to calculate with relative values
1858
+ * */
1859
+ left = 0;
1860
+ right = width;
1861
+ top = 0;
1862
+ bottom = height;
1863
+ if (['auto', 'inherit', '0'].includes(parentComputedStyles.zIndex)) {
1864
+ // We need the default zIndex for floating elements on the parent
1865
+ parent.style.zIndex = '1';
1866
+ }
1867
+ }
1824
1868
  // Tooltip arrow position
1825
1869
  if (childWidth > width && (correctedPlacement.startsWith('bottom') || correctedPlacement.startsWith('top'))) {
1826
1870
  const diff = width / 2 / childWidth * 100;
@@ -1830,6 +1874,9 @@ const handleFixedPopover = (element, parent, placement) => {
1830
1874
  else if (correctedPlacement.endsWith('end')) {
1831
1875
  element.style.setProperty('--db-tooltip-arrow-inline-start', `${100 - diff}%`);
1832
1876
  }
1877
+ else {
1878
+ element.style.setProperty('--db-tooltip-arrow-inline-start', `50%`);
1879
+ }
1833
1880
  }
1834
1881
  if (childHeight > height && (correctedPlacement.startsWith('left') || correctedPlacement.startsWith('bottom'))) {
1835
1882
  const diff = height / 2 / childHeight * 100;
@@ -1839,6 +1886,9 @@ const handleFixedPopover = (element, parent, placement) => {
1839
1886
  else if (correctedPlacement.endsWith('end')) {
1840
1887
  element.style.setProperty('--db-tooltip-arrow-block-start', `${100 - diff}%`);
1841
1888
  }
1889
+ else {
1890
+ element.style.setProperty('--db-tooltip-arrow-block-start', `50%`);
1891
+ }
1842
1892
  }
1843
1893
  // Popover position
1844
1894
  if (correctedPlacement === 'right' || correctedPlacement === 'left') {
@@ -1848,11 +1898,11 @@ const handleFixedPopover = (element, parent, placement) => {
1848
1898
  else if (correctedPlacement === 'right-start' || correctedPlacement === 'left-start') {
1849
1899
  const end = top + childHeight;
1850
1900
  element.style.insetBlockStart = `${top}px`;
1851
- element.style.insetBlockEnd = `${end > innerHeight ? innerHeight : end}px`;
1901
+ element.style.insetBlockEnd = `${!parentHasFloatingPosition && end > innerHeight ? innerHeight : end}px`;
1852
1902
  }
1853
1903
  else if (correctedPlacement === 'right-end' || correctedPlacement === 'left-end') {
1854
1904
  const start = bottom - childHeight;
1855
- element.style.insetBlockStart = `${start < 0 ? 0 : start}px`;
1905
+ element.style.insetBlockStart = `${!parentHasFloatingPosition && start < 0 ? 0 : start}px`;
1856
1906
  element.style.insetBlockEnd = `${bottom}px`;
1857
1907
  }
1858
1908
  else if (correctedPlacement === 'top' || correctedPlacement === 'bottom') {
@@ -1862,32 +1912,32 @@ const handleFixedPopover = (element, parent, placement) => {
1862
1912
  else if (correctedPlacement === 'top-start' || correctedPlacement === 'bottom-start') {
1863
1913
  const end = left + childWidth;
1864
1914
  element.style.insetInlineStart = `${left}px`;
1865
- element.style.insetInlineEnd = `${end > innerWidth ? innerWidth : end}px`;
1915
+ element.style.insetInlineEnd = `${!parentHasFloatingPosition && end > innerWidth ? innerWidth : end}px`;
1866
1916
  }
1867
1917
  else if (correctedPlacement === 'top-end' || correctedPlacement === 'bottom-end') {
1868
- const start = left - childWidth;
1869
- element.style.insetInlineStart = `${right - childWidth}px`;
1870
- element.style.insetInlineEnd = `${start < 0 ? 0 : start}px`;
1918
+ const start = right - childWidth;
1919
+ element.style.insetInlineStart = `${!parentHasFloatingPosition && start < 0 ? 0 : start}px`;
1920
+ element.style.insetInlineEnd = `${right}px`;
1871
1921
  }
1872
1922
  if (correctedPlacement?.startsWith('right')) {
1873
1923
  const end = right + childWidth;
1874
1924
  element.style.insetInlineStart = `calc(${right}px + ${distance})`;
1875
- element.style.insetInlineEnd = `calc(${end > innerWidth ? innerWidth : end}px + ${distance})`;
1925
+ element.style.insetInlineEnd = `calc(${noFloatingAncestor && end > innerWidth ? innerWidth : end}px + ${distance})`;
1876
1926
  }
1877
1927
  else if (correctedPlacement?.startsWith('left')) {
1878
1928
  const start = left - childWidth;
1879
- element.style.insetInlineStart = `calc(${start < 0 ? 0 : start}px - ${distance})`;
1929
+ element.style.insetInlineStart = `calc(${noFloatingAncestor && start < 0 ? 0 : start}px - ${distance})`;
1880
1930
  element.style.insetInlineEnd = `calc(${right}px - ${distance})`;
1881
1931
  }
1882
1932
  else if (correctedPlacement?.startsWith('top')) {
1883
1933
  const start = top - childHeight;
1884
- element.style.insetBlockStart = `calc(${start < 0 ? 0 : start}px - ${distance})`;
1885
- element.style.insetBlockEnd = `calc(${bottom}px - ${distance})`;
1934
+ element.style.insetBlockStart = `calc(${noFloatingAncestor && start < 0 ? 0 : start}px - ${distance})`;
1935
+ element.style.insetBlockEnd = `calc(${parentHasFloatingPosition ? start : bottom}px - ${distance})`;
1886
1936
  }
1887
1937
  else if (correctedPlacement?.startsWith('bottom')) {
1888
1938
  const end = bottom + childHeight;
1889
- element.style.insetBlockStart = `calc(${bottom}px + ${distance})`;
1890
- element.style.insetBlockEnd = `calc(${end > innerHeight ? innerHeight : end}px + ${distance})`;
1939
+ element.style.insetBlockStart = `calc(${parentHasFloatingPosition ? end : bottom}px + ${distance})`;
1940
+ element.style.insetBlockEnd = `calc(${noFloatingAncestor && end > innerHeight ? innerHeight : end}px + ${distance})`;
1891
1941
  }
1892
1942
  element.style.position = 'fixed';
1893
1943
  element.dataset['correctedPlacement'] = correctedPlacement;
@@ -2718,7 +2768,7 @@ class DBTooltip {
2718
2768
  return;
2719
2769
  if (this._ref()?.nativeElement) {
2720
2770
  // This is a workaround for angular
2721
- delay(() => {
2771
+ void delay(() => {
2722
2772
  // Due to race conditions we need to check for _ref again
2723
2773
  if (this._ref()?.nativeElement) {
2724
2774
  handleFixedPopover(this._ref()?.nativeElement, parent, this.placement() ?? "bottom");
@@ -2769,6 +2819,7 @@ class DBTooltip {
2769
2819
  if (this._ref()?.nativeElement && this.initialized() && this._id()) {
2770
2820
  const parent = this.getParent();
2771
2821
  if (parent) {
2822
+ this.handleAutoPlacement(parent);
2772
2823
  ["mouseenter", "focusin"].forEach((event) => {
2773
2824
  parent.addEventListener(event, () => this.handleEnter(parent));
2774
2825
  });
@@ -5902,7 +5953,7 @@ class DBPopover {
5902
5953
  const article = this._ref()?.nativeElement.querySelector("article");
5903
5954
  if (article) {
5904
5955
  // This is a workaround for angular
5905
- delay(() => {
5956
+ void delay(() => {
5906
5957
  handleFixedPopover(article, this._ref()?.nativeElement, this.placement() ?? "bottom");
5907
5958
  }, 1);
5908
5959
  }