Skip to content

Commit 5941cae

Browse files
committed
fix: 修复顶部 Tab 无法滚动的问题
1 parent 856b72b commit 5941cae

3 files changed

Lines changed: 29 additions & 4 deletions

File tree

apps/electron/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@proma/electron",
3-
"version": "0.9.18",
3+
"version": "0.9.19",
44
"description": "Proma next gen ai software with general agents - Electron App",
55
"main": "dist/main.cjs",
66
"author": {

apps/electron/src/renderer/components/tabs/TabBar.tsx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* - 点击切换标签
66
* - 中键关闭标签
77
* - 拖拽重排序
8-
* - Chrome 风格等分宽度(不滚动
8+
* - Chrome 风格等分宽度(溢出时可横向滚动
99
*/
1010

1111
import * as React from 'react'
@@ -156,6 +156,27 @@ function TabBarInner({
156156
const leaveTimerRef = React.useRef<ReturnType<typeof setTimeout>>()
157157
const fadeTimerRef = React.useRef<ReturnType<typeof setTimeout>>()
158158
const isWindows = React.useMemo(() => detectIsWindows(), [])
159+
160+
// 滚动容器 ref
161+
const scrollRef = React.useRef<HTMLDivElement>(null)
162+
163+
// 鼠标滚轮横向滚动
164+
const handleWheel = React.useCallback((e: React.WheelEvent) => {
165+
if (scrollRef.current) {
166+
e.preventDefault()
167+
scrollRef.current.scrollLeft += e.deltaY || e.deltaX
168+
}
169+
}, [])
170+
171+
// 新增 tab 时自动滚动到最右
172+
const prevTabCount = React.useRef(tabs.length)
173+
React.useEffect(() => {
174+
if (tabs.length > prevTabCount.current && scrollRef.current) {
175+
scrollRef.current.scrollTo({ left: scrollRef.current.scrollWidth, behavior: 'smooth' })
176+
}
177+
prevTabCount.current = tabs.length
178+
}, [tabs.length])
179+
159180
React.useEffect(() => {
160181
return () => {
161182
if (enterTimerRef.current) clearTimeout(enterTimerRef.current)
@@ -205,7 +226,11 @@ function TabBarInner({
205226
需要交互的单个 Tab 会在 TabBarItem 内部自己声明 titlebar-no-drag。 */}
206227
<div className="absolute inset-0 titlebar-drag-region" />
207228

208-
<div className={cn("relative flex items-end flex-1 min-w-0 overflow-x-clip titlebar-drag-region", isWindows && "pr-[140px]")}>
229+
<div
230+
ref={scrollRef}
231+
onWheel={handleWheel}
232+
className={cn("relative flex items-end flex-1 min-w-0 overflow-x-auto scrollbar-none titlebar-drag-region", isWindows && "pr-[140px]")}
233+
>
209234
{tabs.map((tab) => (
210235
<TabBarItem
211236
key={tab.id}

apps/electron/src/renderer/components/tabs/TabBarItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export function TabBarItem({
101101

102102
return (
103103
<div
104-
className="relative flex-1 min-w-[48px] max-w-[200px] titlebar-no-drag"
104+
className="relative min-w-[120px] max-w-[200px] flex-[1_0_120px] titlebar-no-drag"
105105
onMouseEnter={onHoverEnter}
106106
onMouseLeave={onHoverLeave}
107107
>

0 commit comments

Comments
 (0)