Skip to content

Commit 6000ac0

Browse files
authored
Keep horizontal option for drop (#387)
* v2.3.21 * add an option to drop to not change style.x after initial setting (helps avoiding jumping when origin has dynamic position)
1 parent 6c17b8f commit 6000ac0

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@netdata/netdata-ui",
3-
"version": "2.3.20",
3+
"version": "2.3.21",
44
"description": "netdata UI kit",
55
"main": "./lib/index.js",
66
"files": [

src/components/drops/drop/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,21 @@ const Drop = forwardRef(
3232
onEsc,
3333
children,
3434
canHideTarget = true,
35+
keepHorizontal,
3536
...rest
3637
},
3738
parentRef
3839
) => {
3940
const [ref, setRef] = useForwardRef(parentRef)
4041

41-
const updatePosition = useMakeUpdatePosition(target, ref, align, stretch, canHideTarget)
42+
const updatePosition = useMakeUpdatePosition(
43+
target,
44+
ref,
45+
align,
46+
stretch,
47+
canHideTarget,
48+
keepHorizontal
49+
)
4250

4351
useEffect(() => {
4452
const id = requestAnimationFrame(updatePosition)

src/components/drops/drop/useMakeUpdatePosition.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const getWidth = (stretch, targetRect, dropRect) => {
6666

6767
const styles = ["top", "right", "bottom", "right", "width"]
6868

69-
export default (target, dropRef, align, stretch, canHideTarget) =>
69+
export default (target, dropRef, align, stretch, canHideTarget, keepHorizontal) =>
7070
useCallback(() => {
7171
if (!dropRef.current) return
7272

@@ -81,7 +81,9 @@ export default (target, dropRef, align, stretch, canHideTarget) =>
8181
const x = getXPosition(align, targetRect, dropRect, canHideTarget)
8282
const y = getYPosition(align, targetRect, dropRect, canHideTarget)
8383

84-
dropRef.current.style.left = `${x}px`
84+
if (!keepHorizontal || !dropRef.current.style.left) {
85+
dropRef.current.style.left = `${x}px`
86+
}
8587
dropRef.current.style.top = `${y}px`
8688
if (stretch) {
8789
dropRef.current.style.width = `${width}px`

0 commit comments

Comments
 (0)