From 5375616558214cac89016c25f2503aa0464ff9bc Mon Sep 17 00:00:00 2001 From: martincupela Date: Mon, 3 Jun 2024 11:49:37 +0200 Subject: [PATCH] fix: allow to pass minRows prop to MessageInput --- .../components/contexts/message-input-context.mdx | 8 ++++++++ .../message-input-components/message-input.mdx | 10 +++++++++- src/components/ChatAutoComplete/ChatAutoComplete.tsx | 1 + src/components/MessageInput/MessageInput.tsx | 2 ++ .../MessageInput/hooks/useCreateMessageInputContext.ts | 3 +++ 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/docusaurus/docs/React/components/contexts/message-input-context.mdx b/docusaurus/docs/React/components/contexts/message-input-context.mdx index 3d44caddb2..d12f1bb02a 100644 --- a/docusaurus/docs/React/components/contexts/message-input-context.mdx +++ b/docusaurus/docs/React/components/contexts/message-input-context.mdx @@ -350,6 +350,14 @@ If provided, the existing message will be edited on submit. | ------ | | object | +### minRows + +Min number of rows the underlying `textarea` will start with. The [`grow`](./#grow) on MessageInput prop has to be enabled for `minRows` to take effect. + +| Type | Default | +| ------ | ------- | +| number | 1 | + ### noFiles If true, disables file uploads for all attachments except for those with type 'image'. diff --git a/docusaurus/docs/React/components/message-input-components/message-input.mdx b/docusaurus/docs/React/components/message-input-components/message-input.mdx index 3dfebe3b75..242b21ecad 100644 --- a/docusaurus/docs/React/components/message-input-components/message-input.mdx +++ b/docusaurus/docs/React/components/message-input-components/message-input.mdx @@ -128,7 +128,7 @@ If true, expands the text input vertically for new lines. Allows to hide MessageInput's send button. Used by `MessageSimple` to hide the send button in `EditMessageForm`. | Type | Default | -|---------|---------| +| ------- | ------- | | boolean | false | ### Input @@ -171,6 +171,14 @@ If provided, the existing message will be edited on submit. | ------ | | object | +### minRows + +Min number of rows the underlying `textarea` will start with. The [`grow`](./#grow) on MessageInput prop has to be enabled for `minRows` to take effect. + +| Type | Default | +| ------ | ------- | +| number | 1 | + ### noFiles If true, disables file uploads for all attachments except for those with type 'image'. diff --git a/src/components/ChatAutoComplete/ChatAutoComplete.tsx b/src/components/ChatAutoComplete/ChatAutoComplete.tsx index 8b938782e9..954ce72136 100644 --- a/src/components/ChatAutoComplete/ChatAutoComplete.tsx +++ b/src/components/ChatAutoComplete/ChatAutoComplete.tsx @@ -181,6 +181,7 @@ const UnMemoizedChatAutoComplete = < loadingComponent={LoadingIndicator} maxRows={messageInput.maxRows} minChar={0} + minRows={messageInput.minRows} onBlur={props.onBlur} onChange={props.onChange || messageInput.handleChange} onFocus={props.onFocus} diff --git a/src/components/MessageInput/MessageInput.tsx b/src/components/MessageInput/MessageInput.tsx index 5326fb8c88..7c5bd250b7 100644 --- a/src/components/MessageInput/MessageInput.tsx +++ b/src/components/MessageInput/MessageInput.tsx @@ -94,6 +94,8 @@ export type MessageInputProps< mentionQueryParams?: SearchQueryParams['userFilters']; /** If provided, the existing message will be edited on submit */ message?: StreamMessage; + /** Min number of rows the underlying `textarea` will start with. The `grow` on MessageInput prop has to be enabled for `minRows` to take effect. */ + minRows?: number; /** If true, disables file uploads for all attachments except for those with type 'image'. Default: false */ noFiles?: boolean; /** Function to override the default submit handler */ diff --git a/src/components/MessageInput/hooks/useCreateMessageInputContext.ts b/src/components/MessageInput/hooks/useCreateMessageInputContext.ts index 4ed44f4618..4fb207c367 100644 --- a/src/components/MessageInput/hooks/useCreateMessageInputContext.ts +++ b/src/components/MessageInput/hooks/useCreateMessageInputContext.ts @@ -47,6 +47,7 @@ export const useCreateMessageInputContext = < mentioned_users, mentionQueryParams, message, + minRows, noFiles, numberOfUploads, onPaste, @@ -127,6 +128,7 @@ export const useCreateMessageInputContext = < mentioned_users, mentionQueryParams, message, + minRows, noFiles, numberOfUploads, onPaste, @@ -172,6 +174,7 @@ export const useCreateMessageInputContext = < isUploadEnabled, linkPreviewsValue, mentionedUsersLength, + minRows, parentId, publishTypingEvent, recordingController,