@selfcommunity/react-ui 0.7.0-alpha.330 → 0.7.0-alpha.332

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.
@@ -64,7 +64,7 @@ function CommentObjectReply(inProps) {
64
64
  props: inProps,
65
65
  name: PREFIX
66
66
  });
67
- const { className, elevation = 0, autoFocus = false, onReply, onSave, onCancel, editable = true, text = '', WidgetProps = { variant: 'outlined' } } = props, rest = tslib_1.__rest(props, ["className", "elevation", "autoFocus", "onReply", "onSave", "onCancel", "editable", "text", "WidgetProps"]);
67
+ const { id = 'CommentObjectReply', className, elevation = 0, autoFocus = false, onReply, onSave, onCancel, editable = true, text = '', WidgetProps = { variant: 'outlined' } } = props, rest = tslib_1.__rest(props, ["id", "className", "elevation", "autoFocus", "onReply", "onSave", "onCancel", "editable", "text", "WidgetProps"]);
68
68
  // CONTEXT
69
69
  const scUserContext = (0, react_core_1.useSCUser)();
70
70
  // RETRIEVE OBJECTS
@@ -81,6 +81,8 @@ function CommentsFeedObject(inProps) {
81
81
  // CONST
82
82
  const objId = commentsObject.feedObject ? commentsObject.feedObject.id : null;
83
83
  const commentObjId = commentObj ? commentObj.id : null;
84
+ // REFS
85
+ const commentsContainerRef = (0, react_1.useRef)();
84
86
  /**
85
87
  * Total number of comments
86
88
  */
@@ -133,10 +135,10 @@ function CommentsFeedObject(inProps) {
133
135
  // Add (window.innerHeight / 2) to scroll
134
136
  // (usually >= (topBar + offset) and in center of the screen)
135
137
  setTimeout(() => {
136
- const el = document.querySelector(`#comment_object_${comment.id}`);
138
+ // Get the comment inside commentsContainer
139
+ const el = commentsContainerRef.current ? commentsContainerRef.current.querySelector(`#comment_object_${comment.id}`) : null;
137
140
  if (el) {
138
- const y = el.getBoundingClientRect().top + window.pageYOffset - window.innerHeight / 2;
139
- window.scrollTo({ top: y, behavior: 'smooth' });
141
+ el.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'center' });
140
142
  }
141
143
  }, 300);
142
144
  }
@@ -223,7 +225,7 @@ function CommentsFeedObject(inProps) {
223
225
  /**
224
226
  * Renders root object
225
227
  */
226
- return (react_1.default.createElement(Root, Object.assign({ id: id, className: (0, classnames_1.default)(classes.root, className) }, rest),
228
+ return (react_1.default.createElement(Root, Object.assign({ id: id, className: (0, classnames_1.default)(classes.root, className) }, rest, { ref: commentsContainerRef }),
227
229
  renderTitle(),
228
230
  commentsRendered));
229
231
  }
@@ -62,7 +62,7 @@ export default function CommentObjectReply(inProps) {
62
62
  props: inProps,
63
63
  name: PREFIX
64
64
  });
65
- const { className, elevation = 0, autoFocus = false, onReply, onSave, onCancel, editable = true, text = '', WidgetProps = { variant: 'outlined' } } = props, rest = __rest(props, ["className", "elevation", "autoFocus", "onReply", "onSave", "onCancel", "editable", "text", "WidgetProps"]);
65
+ const { id = 'CommentObjectReply', className, elevation = 0, autoFocus = false, onReply, onSave, onCancel, editable = true, text = '', WidgetProps = { variant: 'outlined' } } = props, rest = __rest(props, ["id", "className", "elevation", "autoFocus", "onReply", "onSave", "onCancel", "editable", "text", "WidgetProps"]);
66
66
  // CONTEXT
67
67
  const scUserContext = useSCUser();
68
68
  // RETRIEVE OBJECTS
@@ -1,5 +1,5 @@
1
1
  import { __rest } from "tslib";
2
- import React, { useEffect, useMemo, useState } from 'react';
2
+ import React, { useEffect, useMemo, useRef, useState } from 'react';
3
3
  import { styled } from '@mui/material/styles';
4
4
  import { FormattedMessage } from 'react-intl';
5
5
  import CommentObject from '../CommentObject';
@@ -79,6 +79,8 @@ export default function CommentsFeedObject(inProps) {
79
79
  // CONST
80
80
  const objId = commentsObject.feedObject ? commentsObject.feedObject.id : null;
81
81
  const commentObjId = commentObj ? commentObj.id : null;
82
+ // REFS
83
+ const commentsContainerRef = useRef();
82
84
  /**
83
85
  * Total number of comments
84
86
  */
@@ -131,10 +133,10 @@ export default function CommentsFeedObject(inProps) {
131
133
  // Add (window.innerHeight / 2) to scroll
132
134
  // (usually >= (topBar + offset) and in center of the screen)
133
135
  setTimeout(() => {
134
- const el = document.querySelector(`#comment_object_${comment.id}`);
136
+ // Get the comment inside commentsContainer
137
+ const el = commentsContainerRef.current ? commentsContainerRef.current.querySelector(`#comment_object_${comment.id}`) : null;
135
138
  if (el) {
136
- const y = el.getBoundingClientRect().top + window.pageYOffset - window.innerHeight / 2;
137
- window.scrollTo({ top: y, behavior: 'smooth' });
139
+ el.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'center' });
138
140
  }
139
141
  }, 300);
140
142
  }
@@ -221,7 +223,7 @@ export default function CommentsFeedObject(inProps) {
221
223
  /**
222
224
  * Renders root object
223
225
  */
224
- return (React.createElement(Root, Object.assign({ id: id, className: classNames(classes.root, className) }, rest),
226
+ return (React.createElement(Root, Object.assign({ id: id, className: classNames(classes.root, className) }, rest, { ref: commentsContainerRef }),
225
227
  renderTitle(),
226
228
  commentsRendered));
227
229
  }