@milktop/react-ui 0.3.3 → 0.3.4
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.
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
* - `open`, `defaultOpen`; `onOpenChange`: called with the new open state.
|
|
10
10
|
* In an `accordion` Sidebar, opening one closes the others.
|
|
11
11
|
*
|
|
12
|
+
* Opening it scrolls the sidebar just enough to show its items.
|
|
13
|
+
*
|
|
12
14
|
* In the rail only its icon shows, and its items open beside it as a flyout:
|
|
13
15
|
* on hover, or on click for keyboard and touch. Escape, leaving it or
|
|
14
16
|
* following a link closes it. It moves up when it would run past the bottom
|
package/dist/sidebar/NavGroup.js
CHANGED
|
@@ -10,6 +10,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
10
10
|
* - `open`, `defaultOpen`; `onOpenChange`: called with the new open state.
|
|
11
11
|
* In an `accordion` Sidebar, opening one closes the others.
|
|
12
12
|
*
|
|
13
|
+
* Opening it scrolls the sidebar just enough to show its items.
|
|
14
|
+
*
|
|
13
15
|
* In the rail only its icon shows, and its items open beside it as a flyout:
|
|
14
16
|
* on hover, or on click for keyboard and touch. Escape, leaving it or
|
|
15
17
|
* following a link closes it. It moves up when it would run past the bottom
|
|
@@ -64,9 +66,21 @@ export function NavGroup({ label, icon = null, open: openProp, defaultOpen = fal
|
|
|
64
66
|
setPosition({ top: box.top, left: box.right });
|
|
65
67
|
setFlyout(true);
|
|
66
68
|
}
|
|
69
|
+
// Scrolls the sidebar just enough to show the opened items (the heading
|
|
70
|
+
// stays in view when the group is taller than the sidebar).
|
|
71
|
+
const revealing = useRef(false);
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (!open || !revealing.current)
|
|
74
|
+
return;
|
|
75
|
+
revealing.current = false;
|
|
76
|
+
const reduce = matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
77
|
+
root.current?.scrollIntoView({ block: 'nearest', behavior: reduce ? 'auto' : 'smooth' });
|
|
78
|
+
}, [open]);
|
|
67
79
|
function toggle() {
|
|
68
|
-
if (!rail)
|
|
80
|
+
if (!rail) {
|
|
81
|
+
revealing.current = !open;
|
|
69
82
|
setOpen(!open);
|
|
83
|
+
}
|
|
70
84
|
else if (showing)
|
|
71
85
|
setFlyout(false);
|
|
72
86
|
else
|