@faststore/ui 1.6.26 → 1.6.29

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/ui",
3
- "version": "1.6.26",
3
+ "version": "1.6.29",
4
4
  "description": "A lightweight, framework agnostic component library for React",
5
5
  "author": "emersonlaurentino",
6
6
  "license": "MIT",
@@ -76,7 +76,7 @@
76
76
  "@types/jest-axe": "^3.5.3",
77
77
  "@types/tabbable": "^3.1.1",
78
78
  "@types/testing-library__jest-dom": "^5.9.5",
79
- "@vtex/theme-b2c-tailwind": "^1.6.26",
79
+ "@vtex/theme-b2c-tailwind": "^1.6.29",
80
80
  "@vtex/tsconfig": "^0.5.0",
81
81
  "chalk": "^5.0.0",
82
82
  "jest-axe": "^5.0.1",
@@ -89,5 +89,5 @@
89
89
  "tsdx": "^0.14.1",
90
90
  "typescript": "^4.2.4"
91
91
  },
92
- "gitHead": "55979a744634e1119bab71f7363ab03ab00ae875"
92
+ "gitHead": "2b3ec1fb4f5ad90f513273e847ed287216ff28fe"
93
93
  }
@@ -40,8 +40,8 @@ describe('Dropdown', () => {
40
40
  it('Should render DropdownMenu in correct position', () => {
41
41
  const { getByText, getByTestId } = render(
42
42
  <>
43
- <div style={{ height: 200, width: 200 }}>Large element</div>
44
43
  <SimpleDropdown />
44
+ <div style={{ height: 2000, width: 200 }}>Large element</div>
45
45
  </>
46
46
  )
47
47
 
@@ -55,10 +55,15 @@ describe('Dropdown', () => {
55
55
 
56
56
  const buttonRect = dropdownButton?.getBoundingClientRect()
57
57
 
58
- const topLevel = buttonRect?.top ?? 0
59
- const topOffset = buttonRect?.height ?? 0
60
- const topPosition = topLevel + topOffset
61
- const leftPosition = buttonRect?.left ?? 0
58
+ fireEvent.scroll(window, { target: { scrollY: 300 } })
59
+
60
+ const topLevel: number = buttonRect?.top ?? 0
61
+ const topOffset: number = buttonRect?.height ?? 0
62
+ const topPosition =
63
+ topLevel + topOffset + document.documentElement.scrollTop
64
+
65
+ const leftLevel = buttonRect?.left ?? 0
66
+ const leftPosition = leftLevel + document.documentElement.scrollLeft
62
67
 
63
68
  const topMenuPosition = dropdownMenu.style.top
64
69
  const leftMenuPosition = dropdownMenu.style.left
@@ -91,10 +91,12 @@ const DropdownMenu = ({
91
91
  }
92
92
 
93
93
  const handleBackdropKeyDown = (event: KeyboardEvent) => {
94
- if (event.defaultPrevented) {
94
+ if (event.defaultPrevented || event.key === 'Enter') {
95
95
  return
96
96
  }
97
97
 
98
+ event.preventDefault()
99
+
98
100
  event.key === 'Escape' && handleEscapePress()
99
101
 
100
102
  event.key === 'ArrowDown' && handleDownPress()
@@ -105,8 +107,6 @@ const DropdownMenu = ({
105
107
 
106
108
  event.key === 'End' && handleEndPress()
107
109
 
108
- event.key === 'Tab' && event.preventDefault()
109
-
110
110
  event.stopPropagation()
111
111
  }
112
112
 
@@ -1,10 +1,6 @@
1
1
  import { useDropdown } from './useDropdown'
2
2
 
3
- type DropdownPosition = {
4
- position: 'absolute'
5
- top: number
6
- left: number
7
- }
3
+ type DropdownPosition = Pick<React.CSSProperties, 'position' | 'top' | 'left'>
8
4
 
9
5
  /**
10
6
  * Hook used to find the DropdownMenu position in relation to DropdownButton
@@ -12,11 +8,22 @@ type DropdownPosition = {
12
8
  */
13
9
  export const useDropdownPosition = (): DropdownPosition => {
14
10
  const { dropdownButtonRef } = useDropdown()
11
+
12
+ // Necessary to use this component in SSR
13
+ const isBrowser = typeof window !== 'undefined'
14
+
15
15
  const buttonRect = dropdownButtonRef?.current?.getBoundingClientRect()
16
- const topLevel: number = buttonRect?.top ?? 0
17
- const topOffset: number = buttonRect?.height ?? 0
18
- const topPosition = topLevel + topOffset
19
- const leftPosition = buttonRect?.left ?? 0
16
+ const topLevel = buttonRect?.top ?? 0
17
+ const topOffset = buttonRect?.height ?? 0
18
+ const leftLevel = buttonRect?.left ?? 0
19
+
20
+ // The scroll properties fix the position of DropdownMenu when the scroll is activated.
21
+ const scrollTop = isBrowser ? document?.documentElement?.scrollTop : 0
22
+ const scrollLeft = isBrowser ? document?.documentElement?.scrollLeft : 0
23
+
24
+ const topPosition = topLevel + topOffset + scrollTop
25
+
26
+ const leftPosition = leftLevel + scrollLeft
20
27
 
21
28
  return {
22
29
  position: 'absolute',