Skip to content

Commit b5453f4

Browse files
authored
Merge pull request #1184 from GetStream/setText-function
add setText to message input context
2 parents faba4e3 + 2b5cc4a commit b5453f4

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

docusaurus/docs/React/contexts/message-input-context.mdx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ Opens the `EmojiPicker` component on Enter or Spacebar key down.
202202

203203
Function that runs onSubmit to the underlying `textarea` component.
204204

205-
| Type |
206-
| --------------------------------------------------------------------- |
205+
| Type |
206+
| ---------------------------------------------------------------------- |
207207
| (event: React.BaseSyntheticEvent, customMessageData?: Message) => void |
208208

209209
### imageOrder
@@ -401,6 +401,14 @@ React state hook function that sets the `cooldownRemaining` value.
401401
| --------------------------------------------- |
402402
| React.Dispatch<React.SetStateAction<number\>> |
403403

404+
### setText
405+
406+
Function that overrides and sets the text value of the underlying `textarea` component.
407+
408+
| Type |
409+
| ---------------------- |
410+
| (text: string) => void |
411+
404412
### showCommandsList
405413

406414
If true, show the list of supported slash commands above the text input.
@@ -447,4 +455,4 @@ If true, will use an optional dependency to support transliteration in the input
447455

448456
| Type | Default |
449457
| ------- | ------- |
450-
| boolean | false |
458+
| boolean | false |

src/components/MessageInput/hooks/useMessageInputState.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export type MessageInputState<
6363
imageOrder: string[];
6464
imageUploads: { [id: string]: ImageUpload };
6565
mentioned_users: UserResponse<Us>[];
66+
setText: (text: string) => void;
6667
text: string;
6768
};
6869

@@ -177,6 +178,7 @@ const initState = <
177178
imageOrder: [],
178179
imageUploads: { ...emptyImageUploads },
179180
mentioned_users: [],
181+
setText: () => null,
180182
text: '',
181183
};
182184
}
@@ -233,6 +235,7 @@ const initState = <
233235
imageOrder,
234236
imageUploads,
235237
mentioned_users,
238+
setText: () => null,
236239
text: message.text || '',
237240
};
238241
};
@@ -418,6 +421,10 @@ export const useMessageInputState = <
418421
dispatch({ type: 'addMentionedUser', user: item });
419422
}, []);
420423

424+
const setText = useCallback((text: string) => {
425+
dispatch({ getNewText: () => text, type: 'setText' });
426+
}, []);
427+
421428
return {
422429
...state,
423430
closeCommandsList,
@@ -442,6 +449,7 @@ export const useMessageInputState = <
442449
openEmojiPicker,
443450
removeFile,
444451
removeImage,
452+
setText,
445453
showCommandsList,
446454
textareaRef,
447455
uploadFile,

0 commit comments

Comments
 (0)