@faststore/ui 1.6.27 → 1.6.28

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
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## 1.6.28 (2022-03-31)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * fix dropdown menu position with scroll ([#1199](https://github.com/vtex/faststore/issues/1199)) ([98a228e](https://github.com/vtex/faststore/commit/98a228e364ed26e480936406c1988026f9ebaffc))
12
+
13
+
14
+
15
+
16
+
6
17
  ## 1.6.27 (2022-03-31)
7
18
 
8
19
  **Note:** Version bump only for package @faststore/ui
@@ -1,8 +1,5 @@
1
- declare type DropdownPosition = {
2
- position: 'absolute';
3
- top: number;
4
- left: number;
5
- };
1
+ /// <reference types="react" />
2
+ declare type DropdownPosition = Pick<React.CSSProperties, 'position' | 'top' | 'left'>;
6
3
  /**
7
4
  * Hook used to find the DropdownMenu position in relation to DropdownButton
8
5
  * @returns Style with positions.
@@ -1753,9 +1753,11 @@ const useDropdownPosition = () => {
1753
1753
  } = useDropdown();
1754
1754
  const buttonRect = dropdownButtonRef == null ? void 0 : (_dropdownButtonRef$cu = dropdownButtonRef.current) == null ? void 0 : _dropdownButtonRef$cu.getBoundingClientRect();
1755
1755
  const topLevel = (_buttonRect$top = buttonRect == null ? void 0 : buttonRect.top) != null ? _buttonRect$top : 0;
1756
- const topOffset = (_buttonRect$height = buttonRect == null ? void 0 : buttonRect.height) != null ? _buttonRect$height : 0;
1757
- const topPosition = topLevel + topOffset;
1758
- const leftPosition = (_buttonRect$left = buttonRect == null ? void 0 : buttonRect.left) != null ? _buttonRect$left : 0;
1756
+ const topOffset = (_buttonRect$height = buttonRect == null ? void 0 : buttonRect.height) != null ? _buttonRect$height : 0; // The scroll properties fix the position of DropdownMenu when the scroll is activated.
1757
+
1758
+ const topPosition = topLevel + topOffset + document.documentElement.scrollTop;
1759
+ const leftLevel = (_buttonRect$left = buttonRect == null ? void 0 : buttonRect.left) != null ? _buttonRect$left : 0;
1760
+ const leftPosition = leftLevel + document.documentElement.scrollLeft;
1759
1761
  return {
1760
1762
  position: 'absolute',
1761
1763
  top: topPosition,
@@ -1828,16 +1830,16 @@ const DropdownMenu = ({
1828
1830
  };
1829
1831
 
1830
1832
  const handleBackdropKeyDown = event => {
1831
- if (event.defaultPrevented) {
1833
+ if (event.defaultPrevented || event.key === 'Enter') {
1832
1834
  return;
1833
1835
  }
1834
1836
 
1837
+ event.preventDefault();
1835
1838
  event.key === 'Escape' && handleEscapePress();
1836
1839
  event.key === 'ArrowDown' && handleDownPress();
1837
1840
  event.key === 'ArrowUp' && handleUpPress();
1838
1841
  event.key === 'Home' && handleHomePress();
1839
1842
  event.key === 'End' && handleEndPress();
1840
- event.key === 'Tab' && event.preventDefault();
1841
1843
  event.stopPropagation();
1842
1844
  };
1843
1845