Skip to content

Commit ce641b9

Browse files
authored
fix(chat): enforce max char limit (#422)
* fix(chat): disabled button when message is too long * fix(Chat): add character count --------- Co-authored-by: Jake Turner <jturner@cosmistack.com>
1 parent b103db5 commit ce641b9

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

client/src/components/Chat/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -369,13 +369,14 @@ const Chat: FC<Chatinterface>= ({
369369
onTextChange={(value) => setMessageCompose(value)}
370370
contentType="message"
371371
rows={1}
372+
maxLength={2000}
372373
/>
373374
</div>
374375
<div id="replycontainer-right">
375376
<Button
376377
id="replycontainer-sendbutton"
377378
color="blue"
378-
disabled={activeThread === '' || messageCompose === ''}
379+
disabled={activeThread === '' || messageCompose === '' || messageCompose.length > 2000}
379380
loading={messageSending}
380381
onClick={sendMessage}
381382
fluid

client/src/components/TextArea/index.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ interface TextAreaProps {
1212
innerRef?: React.RefObject<HTMLTextAreaElement>;
1313
className?: string;
1414
rows?: number;
15+
maxLength?: number;
1516
}
1617

1718
/**
@@ -26,7 +27,8 @@ const TextArea: React.FC<TextAreaProps> = ({
2627
error,
2728
innerRef,
2829
className,
29-
rows = 5
30+
rows = 5,
31+
maxLength
3032
}) => {
3133

3234
/**
@@ -48,11 +50,12 @@ const TextArea: React.FC<TextAreaProps> = ({
4850
rows={rows}
4951
ref={innerRef}
5052
className='!h-100'
53+
maxLength={maxLength}
5154
/>
5255
{!hideFormatMsg && (
5356
<div id={styles.format_msg}>
5457
<span id={styles.format_msg_text}>
55-
You **<strong>can</strong>** `<code>format</code>` *<em>your</em>* {contentType}!
58+
You **<strong>can</strong>** `<code>format</code>` *<em>your</em>* {contentType}! {maxLength && `${maxLength - textValue.length} characters left`}
5659
</span>
5760
</div>
5861
)}

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)