Skip to content

Commit bbccfa8

Browse files
committed
feat: scrollbar optimize
1 parent 56c7824 commit bbccfa8

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

playground/src/Chat.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { InputCount, Sender } from "@matechat/react/sender";
1111
import type { MessageParam } from "@matechat/react/utils";
1212
import { useChat } from "@matechat/react/utils/chat";
1313
import { useMateChat } from "@matechat/react/utils/core";
14+
import clsx from "clsx";
1415
import { MessageSquarePlus } from "lucide-react";
1516
import { useMemo, useState } from "react";
1617

@@ -84,7 +85,13 @@ export function Chat() {
8485
<div className="flex flex-col items-center justify-center min-h-screen bg-gray-100">
8586
<main className="flex flex-col items-center justify-center h-[80vh] w-full max-w-3xl p-4 bg-white rounded-lg shadow-md gap-5">
8687
<BubbleList
87-
className="px-4 w-full max-w-full"
88+
className={clsx(
89+
"px-4 w-full max-w-full",
90+
"[scrollbar-gutter:stable] [&::-webkit-scrollbar]:w-2 [&::-webkit-scrollbar-thumb]:rounded-full",
91+
"[&::-webkit-scrollbar-thumb]:cursor-auto",
92+
"[&::-webkit-scrollbar-thumb]:bg-gray-300 dark:[&::-webkit-scrollbar-thumb]:bg-gray-600",
93+
"[&::-webkit-scrollbar-thumb:hover]:bg-gray-400 dark:[&::-webkit-scrollbar-thumb:hover]:bg-gray-500",
94+
)}
8895
messages={messages}
8996
background="right-solid"
9097
isPending={pending}

src/sender.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ export function Sender({
122122
const [isSending, setIsSending] = useState(false);
123123

124124
useEffect(() => {
125-
onMessageChange?.(message);
126125
if (textareaRef.current) {
127126
textareaRef.current.style.height = "auto";
128127
textareaRef.current.style.height = `${textareaRef.current.scrollHeight}px`;
129128
}
129+
onMessageChange?.(message);
130130
}, [message, onMessageChange]);
131131

132132
const [controller, setController] = useState<AbortController | null>(null);
@@ -180,7 +180,7 @@ export function Sender({
180180
data-slot="sender"
181181
className={twMerge(
182182
clsx(
183-
"flex flex-col items-center border rounded-2xl",
183+
"px-1 flex flex-col items-center border rounded-2xl",
184184
"border-gray-200 dark:border-gray-700 shadow-sm transition-all duration-300 hover:shadow-md",
185185
"focus-within:ring-2 focus-within:ring-blue-500 focus-within:border-blue-500",
186186
className,
@@ -195,9 +195,14 @@ export function Sender({
195195
onKeyDown={handleKeyDown}
196196
placeholder={placeholder}
197197
className={clsx(
198-
"w-full pt-4 px-4 border-0 rounded-2xl !resize-none",
198+
"w-full pt-4 px-4 border-0 rounded-2xl !resize-none bg-transparent",
199199
"focus:ring-0 focus:outline-none text-gray-700 placeholder-gray-400",
200200
"overflow-y-auto max-h-32",
201+
"[scrollbar-gutter:stable] [&::-webkit-scrollbar]:w-1.5 [&::-webkit-scrollbar-thumb]:rounded-full",
202+
"[&::-webkit-scrollbar-thumb]:cursor-auto",
203+
"[&::-webkit-scrollbar-thumb]:bg-gray-300 dark:[&::-webkit-scrollbar-thumb]:bg-gray-600",
204+
"[&::-webkit-scrollbar-thumb:hover]:bg-gray-400 dark:[&::-webkit-scrollbar-thumb:hover]:bg-gray-500",
205+
"[&::-webkit-scrollbar-track]:mt-3"
201206
)}
202207
rows={2}
203208
/>

0 commit comments

Comments
 (0)