Skip to content

Commit 771e52a

Browse files
committed
Ref instead
1 parent 34665e8 commit 771e52a

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

resources/js/Components/Comments/Commentable.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const commentsLeft = ref(props.commentsCount);
5151
const idToChildren = ref(new Map());
5252
const sortBy = ref(props.sortByInitialValue);
5353
const hasOpenedComments = ref(false);
54+
const commentRefs = ref(new Map());
5455
5556
const createdNewCommentCallback = (newComment, userData) => {
5657
console.log("Created a new comment!", newComment, userData);
@@ -59,9 +60,7 @@ const createdNewCommentCallback = (newComment, userData) => {
5960
6061
// Ensure DOM updates are complete, then scroll to the new comment
6162
nextTick(() => {
62-
const newCommentElement = document.getElementById(
63-
"comment_" + newComment.id
64-
);
63+
const newCommentElement = commentRefs.value.get(`comment_${newComment.id}`);
6564
if (newCommentElement) {
6665
newCommentElement.scrollIntoView({
6766
behavior: "smooth",
@@ -76,6 +75,7 @@ provide("commentableId", props.commentableId);
7675
provide("commentableKey", props.commentableKey);
7776
provide("users", readonly(usersMap));
7877
provide("createdNewCommentCallback", createdNewCommentCallback);
78+
provide("commentRefs", commentRefs);
7979
8080
const showEmptyState = computed(() => {
8181
return (

resources/js/Pages/Resources/Create.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ const { clearLocalStorage } = useLocalStorageSaver(
4848
4949
const showReset = ref(false);
5050
const stepperValue = ref("1");
51+
const formRef = ref(null);
5152
5253
const toast = useToast();
5354
5455
const scrollToForm = () => {
55-
const htmlForm = document.getElementById("create-resource-form");
56-
if (htmlForm) {
57-
htmlForm.scrollIntoView({
56+
if (formRef.value) {
57+
formRef.value.scrollIntoView({
5858
behavior: "smooth",
5959
block: "start",
6060
inline: "nearest",
@@ -229,6 +229,7 @@ const handleFormChange = (newFormData) => {
229229
</div>
230230
<!-- Main Form Section -->
231231
<div
232+
ref="formRef"
232233
class="bg-white h-min shadow-lg rounded-lg p-6 flex-1 max-w-full md:max-w-3xl min-w-0 md:min-w-[28rem] relative"
233234
id="create-resource-form"
234235
>

0 commit comments

Comments
 (0)