Skip to content

Commit c7c1825

Browse files
authored
fix: focus message composer textarea on suggestion item selection (#2782)
1 parent 3eaa469 commit c7c1825

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/components/TextareaComposer/SuggestionList/SuggestionListItem.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { TextComposerSuggestion } from 'stream-chat';
66
import type { UserItemProps } from './UserItem';
77
import type { CommandItemProps } from './CommandItem';
88
import type { EmoticonItemProps } from './EmoticonItem';
9+
import { useMessageInputContext } from '../../../context';
910

1011
export type DefaultSuggestionListItemEntity =
1112
| UserItemProps['entity']
@@ -33,11 +34,13 @@ export const SuggestionListItem = React.forwardRef<
3334
innerRef: Ref<HTMLButtonElement>,
3435
) {
3536
const { textComposer } = useMessageComposer();
37+
const { textareaRef } = useMessageInputContext();
3638
const containerRef = useRef<HTMLLIElement>(null);
3739

3840
const handleSelect = useCallback(() => {
3941
textComposer.handleSelect(item);
40-
}, [item, textComposer]);
42+
textareaRef.current?.focus();
43+
}, [item, textareaRef, textComposer]);
4144

4245
useLayoutEffect(() => {
4346
if (!focused) return;

0 commit comments

Comments
 (0)