@faststore/ui 1.6.27 → 1.7.1
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 +30 -0
- package/dist/molecules/Dropdown/hooks/useDropdownPosition.d.ts +2 -5
- package/dist/ui.cjs.development.js +12 -6
- package/dist/ui.cjs.development.js.map +1 -1
- package/dist/ui.cjs.production.min.js +1 -1
- package/dist/ui.cjs.production.min.js.map +1 -1
- package/dist/ui.esm.js +12 -6
- package/dist/ui.esm.js.map +1 -1
- package/package.json +3 -3
- package/src/molecules/Dropdown/Dropdown.test.tsx +10 -5
- package/src/molecules/Dropdown/DropdownMenu.tsx +3 -3
- package/src/molecules/Dropdown/hooks/useDropdownPosition.ts +16 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faststore/ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.1",
|
|
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.
|
|
79
|
+
"@vtex/theme-b2c-tailwind": "^1.7.1",
|
|
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": "
|
|
92
|
+
"gitHead": "b2ab391a18bbb0d1c8dd777712c31b6d88edf687"
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
const
|
|
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
|
|
17
|
-
const topOffset
|
|
18
|
-
const
|
|
19
|
-
|
|
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',
|