Skip to content

Commit bba9b7c

Browse files
committed
v4.8.18
1 parent 3322492 commit bba9b7c

File tree

2 files changed

+15
-39
lines changed

2 files changed

+15
-39
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@netdata/netdata-ui",
3-
"version": "4.8.17",
3+
"version": "4.8.18",
44
"description": "netdata UI kit",
55
"main": "dist/index.js",
66
"module": "dist/es6/index.js",
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
import { useCallback, useRef } from "react"
22

3-
const initialRect = {
4-
width: -1,
5-
tabRight: -1,
6-
}
7-
8-
const hasChanged = (prevValues, values) => {
9-
if (prevValues.width === initialRect.width) return true
10-
if (prevValues.width === values.width && prevValues.tabRight !== values.tabRight) return true
11-
return prevValues.width !== values.width
12-
}
3+
const initialScrollWidth = -1
4+
const initialClientWidth = -1
135

146
export default (parentRef, ref, target, callback, deps) => {
15-
const prevValuesRef = useRef(initialRect)
7+
const prevScrollWidthRef = useRef(initialScrollWidth)
8+
const prevClientWidthRef = useRef(initialClientWidth)
169

1710
return useCallback(() => {
1811
if (!ref.current || !target.current || !parentRef || !parentRef.current) return
@@ -24,42 +17,25 @@ export default (parentRef, ref, target, callback, deps) => {
2417
const container = parentRef.current
2518
const { right: containerRight, left: containerLeft } = container.getBoundingClientRect()
2619

27-
if (!prevValuesRef.current.expandedStaticWidth) {
28-
prevValuesRef.current.expandedStaticWidth = draggableLeft - containerLeft
29-
}
30-
3120
const { right: tabRight, width: tabWidth } = target.current.getBoundingClientRect()
3221

33-
if (!hasChanged(prevValuesRef.current, { width, tabRight })) return
22+
if (
23+
prevScrollWidthRef.current === draggableTabs.scrollWidth &&
24+
prevClientWidthRef.current === width
25+
)
26+
return
27+
prevScrollWidthRef.current = draggableTabs.scrollWidth
28+
prevClientWidthRef.current = width
3429

3530
const padRight = width - containerRight
3631
if (
3732
tabRight < width - padRight &&
38-
containerLeft +
39-
prevValuesRef.current.expandedStaticWidth +
40-
(tabRight - draggableLeft) +
41-
padRight >
33+
containerLeft + (draggableLeft - containerLeft) + (tabRight - draggableLeft) + padRight >
4234
width
4335
)
4436
return
4537

46-
prevValuesRef.current = {
47-
...prevValuesRef.current,
48-
width,
49-
tabRight,
50-
containerRight,
51-
}
52-
53-
if (tabRight >= containerRight && !prevValuesRef.current.collapse) {
54-
prevValuesRef.current.collapse = true
55-
return callback(true)
56-
}
57-
if (
58-
tabRight + tabWidth < containerRight &&
59-
(prevValuesRef.current.collapse || typeof prevValuesRef.current.collapse === "undefined")
60-
) {
61-
prevValuesRef.current.collapse = false
62-
return callback(false)
63-
}
38+
if (tabRight >= containerRight) return callback(true)
39+
if (tabRight + tabWidth < containerRight) return callback(false)
6440
}, deps)
6541
}

0 commit comments

Comments
 (0)