diff --git a/src/shared/ui-kit/TextEditor/BaseTextEditor.module.scss b/src/shared/ui-kit/TextEditor/BaseTextEditor.module.scss
index 7ce5c294c1..8b3d6c9539 100644
--- a/src/shared/ui-kit/TextEditor/BaseTextEditor.module.scss
+++ b/src/shared/ui-kit/TextEditor/BaseTextEditor.module.scss
@@ -2,4 +2,5 @@
position: relative;
width: 100%;
height: 100%;
+ scroll-behavior: smooth;
}
diff --git a/src/shared/ui-kit/TextEditor/BaseTextEditor.tsx b/src/shared/ui-kit/TextEditor/BaseTextEditor.tsx
index 7400b1212d..6eb3b7dde0 100644
--- a/src/shared/ui-kit/TextEditor/BaseTextEditor.tsx
+++ b/src/shared/ui-kit/TextEditor/BaseTextEditor.tsx
@@ -170,9 +170,18 @@ const BaseTextEditor = forwardRef
((props
useImperativeHandle(ref, () => ({
focus: () => {
if (editorRef) {
+ const end = EditorSlate.end(editor, []);
+
+ // Move the selection to the end
+ Transforms.select(editor, end);
+
+ // Focus the editor DOM node
const editorEl = ReactEditor.toDOMNode(editor, editor);
editorEl.focus();
- }
+
+ // Ensure the editor itself is focused programmatically
+ ReactEditor.focus(editor);
+ }
},
clear: () => {
clearInput();
@@ -256,7 +265,8 @@ const BaseTextEditor = forwardRef((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();
}
@@ -340,6 +350,16 @@ const BaseTextEditor = forwardRef((props
[onChange, value, handleMentionSelectionChange],
);
+ const customScrollSelectionIntoView = ( ) => {
+ if (inputContainerRef && 'current' in inputContainerRef && inputContainerRef?.current) {
+ inputContainerRef.current?.scrollIntoView({
+ behavior: "smooth",
+ block: "end",
+ inline: "nearest",
+ });
+ }
+ }
+
return (
@@ -358,7 +378,7 @@ const BaseTextEditor = forwardRef((props
disabled={disabled}
onBlur={onBlur}
onKeyDown={handleKeyDown}
- scrollSelectionIntoView={scrollSelectionIntoView}
+ scrollSelectionIntoView={scrollSelectionIntoView ?? customScrollSelectionIntoView}
elementStyles={elementStyles}
/>