Skip to content

Commit 5a32bc3

Browse files
committed
refactor: remove disabled from MessageInputProps
1 parent 53e4f1f commit 5a32bc3

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

src/components/MessageInput/MessageInput.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ export type MessageInputProps = {
5252
audioRecordingEnabled?: boolean;
5353
/** Function to clear the editing state while editing a message */
5454
clearEditingState?: () => void;
55-
/** If true, disables the text input */
56-
disabled?: boolean;
5755
/** Mechanism to be used with autocomplete and text replace features of the `MessageInput` component, see [emoji-mart `SearchIndex`](https://github.com/missive/emoji-mart#%EF%B8%8F%EF%B8%8F-headless-search) */
5856
emojiSearchIndex?: ComponentContextValue['emojiSearchIndex'];
5957
/** If true, focuses the text input on component mount */

src/components/MessageInput/hooks/useCreateMessageInputContext.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export const useCreateMessageInputContext = (value: MessageInputContextValue) =>
1010
clearEditingState,
1111
cooldownInterval,
1212
cooldownRemaining,
13-
disabled,
1413
emojiSearchIndex,
1514
focus,
1615
grow,
@@ -40,7 +39,6 @@ export const useCreateMessageInputContext = (value: MessageInputContextValue) =>
4039
clearEditingState,
4140
cooldownInterval,
4241
cooldownRemaining,
43-
disabled,
4442
emojiSearchIndex,
4543
focus,
4644
grow,

src/components/TextareaComposer/TextareaComposer.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import type { ChangeEventHandler, TextareaHTMLAttributes, UIEventHandler } from
33
import React, { useCallback, useEffect, useRef, useState } from 'react';
44
import Textarea from 'react-textarea-autosize';
55
import { useMessageComposer } from '../MessageInput';
6-
import type { SearchSourceState, TextComposerState } from 'stream-chat';
6+
import type {
7+
MessageComposerConfig,
8+
SearchSourceState,
9+
TextComposerState,
10+
} from 'stream-chat';
711
import {
812
useComponentContext,
913
useMessageInputContext,
@@ -23,6 +27,10 @@ const searchSourceStateSelector = (state: SearchSourceState) => ({
2327
items: state.items,
2428
});
2529

30+
const configStateSelector = (state: MessageComposerConfig) => ({
31+
enabled: state.text.enabled,
32+
});
33+
2634
/**
2735
* isComposing prevents double submissions in Korean and other languages.
2836
* starting point for a read:
@@ -34,7 +42,7 @@ const defaultShouldSubmit = (event: React.KeyboardEvent<HTMLTextAreaElement>) =>
3442

3543
export type TextComposerProps = Omit<
3644
TextareaHTMLAttributes<HTMLTextAreaElement>,
37-
'style' | 'defaultValue'
45+
'style' | 'defaultValue' | 'disabled'
3846
> & {
3947
closeSuggestionsOnClickOutside?: boolean;
4048
containerClassName?: string;
@@ -50,7 +58,6 @@ export const TextareaComposer = ({
5058
className,
5159
closeSuggestionsOnClickOutside,
5260
containerClassName,
53-
disabled,
5461
// dropdownClassName, // todo: X find a different way to prevent prop drilling
5562
grow: growProp,
5663
// itemClassName, // todo: X find a different way to prevent prop drilling
@@ -89,6 +96,8 @@ export const TextareaComposer = ({
8996
textComposerStateSelector,
9097
);
9198

99+
const { enabled } = useStateStore(messageComposer.configState, configStateSelector);
100+
92101
const { isLoadingItems } =
93102
useStateStore(suggestions?.searchSource.state, searchSourceStateSelector) ?? {};
94103

@@ -234,7 +243,7 @@ export const TextareaComposer = ({
234243
className,
235244
)}
236245
data-testid='message-input'
237-
disabled={disabled || !!cooldownRemaining}
246+
disabled={!enabled || !!cooldownRemaining}
238247
maxRows={grow ? maxRows : 1}
239248
onBlur={onBlur}
240249
onChange={changeHandler}

0 commit comments

Comments
 (0)