@topconsultnpm/sdkui-react-beta 6.14.142 → 6.14.143

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.
@@ -409,25 +409,26 @@ const TMBlogs = (props) => {
409
409
  handleFocusedBlog(blogPosts[blogPosts.length - 1]);
410
410
  }
411
411
  }, [shouldSelectLastBlog, blogPosts]);
412
- // Scroll the focused blog post into view
413
- useEffect(() => {
414
- if (focusedBlog && focusedBlog.id && containerRef.current) {
415
- const focusedElement = document.getElementById(id + "-" + uiId + "-" + focusedBlog.id.toString());
416
- if (focusedElement) {
417
- focusedElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
418
- }
419
- }
420
- }, [focusedBlog]);
421
412
  const ThumbnailView = () => {
422
413
  const scrollRef = useRef(null);
423
414
  useEffect(() => {
424
- if (focusedBlog && focusedBlog.id) { // containerRef.current
415
+ // Check if there's a focused blog post, its ID is valid, and the scroll container exists
416
+ if (focusedBlog && focusedBlog.id && scrollRef.current) {
417
+ const container = scrollRef.current;
418
+ // Find the DOM element for the focused blog using its composed ID
425
419
  const focusedElement = document.getElementById(id + "-" + uiId + "-" + focusedBlog.id.toString());
426
420
  if (focusedElement) {
427
- focusedElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
421
+ // Get the position of the container and the focused element
422
+ const containerRect = container.getBoundingClientRect();
423
+ const elRect = focusedElement.getBoundingClientRect();
424
+ // Calculate the offset needed to center the focused element in the container
425
+ const offset = elRect.top - containerRect.top - container.clientHeight / 2 + focusedElement.clientHeight / 2;
426
+ // Scroll the container to center the focused element smoothly
427
+ container.scrollTo({ top: container.scrollTop + offset, behavior: 'smooth', });
428
428
  }
429
429
  }
430
430
  else {
431
+ // If there's no focused blog and the user didn't right-click on the background, and the scroll flag is set, scroll to the bottom of the container
431
432
  if (!rightClickedOnBackground && scrollToBottom && scrollRef.current) {
432
433
  scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
433
434
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@topconsultnpm/sdkui-react-beta",
3
- "version": "6.14.142",
3
+ "version": "6.14.143",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",