Skip to content

Commit 5a4cbe2

Browse files
author
Dan Carbonell
committed
add slice to no ref case
1 parent afc7e72 commit 5a4cbe2

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/components/MessageInput/hooks/messageInput.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,15 +262,22 @@ export default function useMessageInput(props) {
262262

263263
const insertText = useCallback(
264264
(textToInsert) => {
265+
const { maxLength } = additionalTextareaProps;
266+
265267
if (!textareaRef.current) {
266268
dispatch({
267269
type: 'setText',
268-
getNewText: (t) => t + textToInsert,
270+
getNewText: (t) => {
271+
const updatedText = t + textToInsert;
272+
if (updatedText.length > maxLength) {
273+
return updatedText.slice(0, maxLength);
274+
}
275+
return updatedText;
276+
},
269277
});
270278
return;
271279
}
272280

273-
const { maxLength } = additionalTextareaProps;
274281
const { selectionStart, selectionEnd } = textareaRef.current;
275282
newCursorPosition.current = selectionStart + textToInsert.length;
276283

0 commit comments

Comments
 (0)