Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/classrooms/[classroomId]/chat/MessageBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export default function MessageBox({
value={value}
onChange={(e) => setValue(e.target.value)}
placeholder="Type your message..."
onEnter={handleSend}
/>
<Button
onClick={handleSend}
Expand Down
46 changes: 32 additions & 14 deletions shared/components/ui/chat/chat-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,41 @@ import * as React from "react";
import { Textarea } from "@shared/components/ui/textarea";
import { cn } from "@shared/lib/utils";

// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface ChatInputProps
extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {}
extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {
//leave as optional
onEnter?: () => void;
}

const ChatInput = React.forwardRef<HTMLTextAreaElement, ChatInputProps>(
({ className, ...props }, ref) => (
<Textarea
autoComplete="off"
ref={ref}
name="message"
className={cn(
"flex h-16 max-h-12 w-full resize-none items-center rounded-md bg-background px-4 py-3 text-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
className
)}
{...props}
/>
)
({ className, onKeyDown, onEnter, ...props }, ref) => {
const handleKeyDown = (event: React.KeyboardEvent<HTMLTextAreaElement>) => {
//if it is only the enter key
if (event.key === "Enter" && !event.shiftKey) {
//prevent new line
event.preventDefault();
if (onEnter) {
onEnter();
}
}
if (onKeyDown) {
onKeyDown(event);
}
};
return (
<Textarea
autoComplete="off"
ref={ref}
name="message"
onKeyDown={handleKeyDown}
className={cn(
"flex h-16 max-h-12 w-full resize-none items-center rounded-md bg-background px-4 py-3 text-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
className
)}
{...props}
/>
);
}
);
ChatInput.displayName = "ChatInput";

Expand Down