Skip to content

Commit

Permalink
CW-instant-chat-message-edit
Browse files Browse the repository at this point in the history
Fix scroll behaviour
  • Loading branch information
MeyerPV committed Oct 10, 2024
1 parent 193847d commit 44eef1d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

.editedTimeWrapper {
font-size: $xxsmall;
min-width: 5rem;
}

.creationTimeWrapper {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useMemo, useState } from "react";
import React, { useEffect, useMemo, useState, useRef } from "react";
import classNames from "classnames";
import { useCommonMembers } from "@/pages/OldCommon/hooks";
import { Loader } from "@/shared/components";
Expand Down Expand Up @@ -29,6 +29,7 @@ export default function EditMessageInput({
isLoading,
updateMessage,
}: Props) {
const inputContainerRef = useRef<HTMLDivElement>(null);
const [message, setMessage] = useState(() =>
parseStringToTextEditorValue(discussionMessage.text),
);
Expand All @@ -53,7 +54,7 @@ export default function EditMessageInput({
}, [commonMember, commonMembers]);

return (
<div className={styles.container}>
<div ref={inputContainerRef} className={styles.container}>
<BaseTextEditor
className={styles.input}
emojiPickerContainerClassName={styles.pickerContainer}
Expand All @@ -64,6 +65,7 @@ export default function EditMessageInput({
shouldReinitializeEditor={false}
onClearFinished={emptyFunction}
size={TextEditorSize.Auto}
inputContainerRef={inputContainerRef}
/>

<div className={styles.buttonContainer}>
Expand Down
1 change: 1 addition & 0 deletions src/shared/ui-kit/TextEditor/BaseTextEditor.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
position: relative;
width: 100%;
height: 100%;
scroll-behavior: smooth;
}
15 changes: 13 additions & 2 deletions src/shared/ui-kit/TextEditor/BaseTextEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ const BaseTextEditor = forwardRef<BaseTextEditorHandles, TextEditorProps>((props
event.preventDefault();
setShouldFocusTarget(true);
} else {
onKeyDown && onKeyDown(event);
// event.stopPropagation();
onKeyDown && onKeyDown(event); // Call any custom onKeyDown handler
if (event.key === KeyboardKeys.Enter && !isMobile()) {
onToggleIsMessageSent();
}
Expand Down Expand Up @@ -340,6 +341,16 @@ const BaseTextEditor = forwardRef<BaseTextEditorHandles, TextEditorProps>((props
[onChange, value, handleMentionSelectionChange],
);

const customScrollSelectionIntoView = ( ) => {
if (inputContainerRef && 'current' in inputContainerRef && inputContainerRef?.current) {
inputContainerRef.current?.scrollIntoView({
behavior: "smooth",
block: "end",
inline: "nearest",
});
}
}

return (
<div ref={inputContainerRef} className={styles.container}>
<Slate editor={editor} initialValue={value} onChange={handleOnChange}>
Expand All @@ -358,7 +369,7 @@ const BaseTextEditor = forwardRef<BaseTextEditorHandles, TextEditorProps>((props
disabled={disabled}
onBlur={onBlur}
onKeyDown={handleKeyDown}
scrollSelectionIntoView={scrollSelectionIntoView}
scrollSelectionIntoView={scrollSelectionIntoView ?? customScrollSelectionIntoView}
elementStyles={elementStyles}
/>
<EmojiPicker
Expand Down

0 comments on commit 44eef1d

Please sign in to comment.