io-sanita-theme 2.4.1 → 2.4.2

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.4.2](https://github.com/RedTurtle/io-sanita-theme/compare/2.4.1...2.4.2) (2025-03-04)
4
+
5
+ ### Bug Fixes
6
+
7
+ * scroll SideMenu with headersticky ([5a3e9d5](https://github.com/RedTurtle/io-sanita-theme/commit/5a3e9d531350933a2fe672ba6625bc30cb7cc5ba))
8
+
3
9
  ## [2.4.1](https://github.com/RedTurtle/io-sanita-theme/compare/2.4.0...2.4.1) (2025-03-04)
4
10
 
5
11
  ### Bug Fixes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "io-sanita-theme",
3
- "version": "2.4.1",
3
+ "version": "2.4.2",
4
4
  "description": "io-sanita-theme: Volto add-on",
5
5
  "main": "src/index.js",
6
6
  "license": "MIT",
@@ -86,8 +86,17 @@ const SideMenu = ({ data, content_uid }) => {
86
86
  (item) => item.id === activeSection,
87
87
  )?.title;
88
88
 
89
+ const getMainOffset = () => {
90
+ return isClient
91
+ ? document.querySelector('.it-header-wrapper.it-header-sticky')
92
+ ?.clientHeight + 20
93
+ : 0;
94
+ };
95
+ const mainOffset = getMainOffset();
96
+
89
97
  const handleScroll = useCallback(() => {
90
- const scrollOffset = 0.1 * window.innerHeight;
98
+ const windowHeight = window.innerHeight * 0.1;
99
+ const mainOffset = getMainOffset();
91
100
  setScrollY(window.scrollY);
92
101
  const headersHeights = headers
93
102
  .map((section) => {
@@ -97,7 +106,8 @@ const SideMenu = ({ data, content_uid }) => {
97
106
  top: element?.getBoundingClientRect()?.top,
98
107
  };
99
108
  })
100
- .filter((section) => section.top <= scrollOffset);
109
+ // .filter((section) => section.top - mainOffset + 40 <= windowHeight);
110
+ .filter((section) => section.top <= mainOffset + 20);
101
111
  if (headersHeights.length > 0) {
102
112
  const section = headersHeights.reduce(
103
113
  (prev, curr) => (prev.top > curr.top ? prev : curr),
@@ -130,6 +140,9 @@ const SideMenu = ({ data, content_uid }) => {
130
140
  }, [headers]);
131
141
 
132
142
  const throttledHandleScroll = throttle(handleScroll, 100);
143
+ const yCountEnd = isClient
144
+ ? document.querySelector('#main-content-section')
145
+ : null;
133
146
 
134
147
  const handleClickAnchor = (id) => (e) => {
135
148
  e.preventDefault();
@@ -143,17 +156,18 @@ const SideMenu = ({ data, content_uid }) => {
143
156
  // Scroll to section
144
157
  // setTimeout hack should wait for rerender after setIsNavOpen
145
158
  setTimeout(() => {
146
- document.getElementById(id)?.scrollIntoView?.({
159
+ // document.getElementById(id)?.scrollIntoView?.({
160
+ // behavior: 'smooth',
161
+ // block: 'start',
162
+ // });
163
+
164
+ window.scrollTo({
147
165
  behavior: 'smooth',
148
- block: 'start',
166
+ top: document.querySelector('#' + id).offsetTop - mainOffset,
149
167
  });
150
168
  }, 0);
151
169
  };
152
170
 
153
- const yCountEnd = isClient
154
- ? document.querySelector('#main-content-section')
155
- : null;
156
-
157
171
  const progressValue = useMemo(() => {
158
172
  if (!isClient) return 0;
159
173
  return yCountEnd
@@ -162,7 +176,10 @@ const SideMenu = ({ data, content_uid }) => {
162
176
  }, [scrollY, isClient]);
163
177
 
164
178
  return headers?.length > 0 ? (
165
- <div className="navbar-wrapper page-side-menu affix-top ">
179
+ <div
180
+ className="navbar-wrapper page-side-menu affix-top"
181
+ style={{ top: mainOffset - 20 }}
182
+ >
166
183
  <nav
167
184
  className="navbar it-navscroll-wrapper navbar-expand-lg"
168
185
  aria-label={intl.formatMessage(messages.sideMenuNavigation)}