-
Notifications
You must be signed in to change notification settings - Fork 219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/auto hide tab bar #1527
base: main
Are you sure you want to change the base?
Changes from all commits
f824cd7
9a9a1dc
0da0a75
b3720b3
3fd9d97
98107e5
3223c8d
bce3106
1ef2d68
7320420
2af5c02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import { deleteLayoutModelForTab } from "@/layout/index"; | |
import { atoms, createTab, getApi, globalStore, isDev, PLATFORM, setActiveTab } from "@/store/global"; | ||
import { fireAndForget } from "@/util/util"; | ||
import { useAtomValue } from "jotai"; | ||
import clsx from "clsx"; | ||
import { OverlayScrollbars } from "overlayscrollbars"; | ||
import { createRef, memo, useCallback, useEffect, useRef, useState } from "react"; | ||
import { debounce } from "throttle-debounce"; | ||
|
@@ -174,10 +175,44 @@ const TabBar = memo(({ workspace }: TabBarProps) => { | |
const isFullScreen = useAtomValue(atoms.isFullScreen); | ||
|
||
const settings = useAtomValue(atoms.settingsAtom); | ||
const autoHideTabBar = settings?.["window:autohidetabbar"] ?? false; | ||
|
||
let prevDelta: number; | ||
let prevDragDirection: string; | ||
|
||
const handleAutoHideTabBar = (event: MouseEvent) => { | ||
const tabBar = tabbarWrapperRef.current; | ||
const tabBarHeight = tabBar?.clientHeight + 1; | ||
|
||
if (event.type === 'mouseenter') { | ||
tabBar.style.top = '0px'; | ||
tabBar.addEventListener("mouseleave", handleAutoHideTabBar); | ||
tabBar.classList.add('tab-bar-wrapper-auto-hide-visible') | ||
} | ||
|
||
if (event.type === 'mouseleave') { | ||
tabBar.style.top = `-${tabBarHeight - 10}px`; | ||
tabBar.removeEventListener("mouseleave", handleAutoHideTabBar); | ||
tabBar.classList.remove('tab-bar-wrapper-auto-hide-visible') | ||
} | ||
}; | ||
Comment on lines
+183
to
+198
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Refactor to use CSS transforms instead of direct style manipulation. The current implementation uses direct style manipulation which can cause unnecessary reflows. Consider using CSS transforms for better performance. Apply this diff to use CSS transforms: const handleAutoHideTabBar = (event: MouseEvent) => {
const tabBar = tabbarWrapperRef.current;
- const tabBarHeight = tabBar?.clientHeight + 1;
if (event.type === 'mouseenter') {
- tabBar.style.top = '0px';
- tabBar.addEventListener("mouseleave", handleAutoHideTabBar);
tabBar.classList.add('tab-bar-wrapper-auto-hide-visible')
}
if (event.type === 'mouseleave') {
- tabBar.style.top = `-${tabBarHeight - 10}px`;
- tabBar.removeEventListener("mouseleave", handleAutoHideTabBar);
tabBar.classList.remove('tab-bar-wrapper-auto-hide-visible')
}
}; Add these CSS classes to your stylesheet: .tab-bar-wrapper-auto-hide {
transform: translateY(-100%);
transition: transform 0.2s ease;
}
.tab-bar-wrapper-auto-hide-visible {
transform: translateY(0);
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a good suggestion @rritik772 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
useEffect(() => { | ||
const tabBar = tabbarWrapperRef.current; | ||
if (!autoHideTabBar) { | ||
tabBar.style.top = '0px'; | ||
return; | ||
} | ||
|
||
const tabBarHeight = tabBar?.clientHeight + 1; | ||
if (autoHideTabBar) { | ||
tabbarWrapperRef.current.style.top = `-${tabBarHeight - 10}px` | ||
} | ||
|
||
tabbarWrapperRef.current.addEventListener("mouseenter", handleAutoHideTabBar); | ||
return () => tabbarWrapperRef.current.removeEventListener("mouseenter", handleAutoHideTabBar); | ||
}, [autoHideTabBar]) | ||
Comment on lines
+200
to
+214
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve event listener management. The current implementation could lead to memory leaks if the component unmounts while listeners are still attached. Also, the cleanup function might fail if Apply this diff to improve event listener management: useEffect(() => {
const tabBar = tabbarWrapperRef.current;
if (!autoHideTabBar || !tabBar) {
- tabBar.style.top = '0px';
return;
}
- const tabBarHeight = tabBar?.clientHeight + 1;
- if (autoHideTabBar) {
- tabbarWrapperRef.current.style.top = `-${tabBarHeight - 10}px`
- }
- tabbarWrapperRef.current.addEventListener("mouseenter", handleAutoHideTabBar);
+ const handleMouseEnter = (e: MouseEvent) => {
+ tabBar.classList.add('tab-bar-wrapper-auto-hide-visible');
+ tabBar.addEventListener('mouseleave', handleMouseLeave);
+ };
+ const handleMouseLeave = (e: MouseEvent) => {
+ tabBar.classList.remove('tab-bar-wrapper-auto-hide-visible');
+ tabBar.removeEventListener('mouseleave', handleMouseLeave);
+ };
+ tabBar.addEventListener("mouseenter", handleMouseEnter);
- return () => tabbarWrapperRef.current.removeEventListener("mouseenter", handleAutoHideTabBar);
+ return () => {
+ tabBar.removeEventListener("mouseenter", handleMouseEnter);
+ tabBar.removeEventListener("mouseleave", handleMouseLeave);
+ };
}, [autoHideTabBar]);
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is also a good suggestion, just in case the mouseleave handler is still attached There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @esimkowitz, glad to hear you find the suggestion helpful! By attaching and detaching the listeners in a more localized manner, we reduce the risk of orphaned event handlers if the component unmounts prematurely. Let me know if you need further refinements to the approach. |
||
|
||
// Update refs when tabIds change | ||
useEffect(() => { | ||
tabRefs.current = tabIds.map((_, index) => tabRefs.current[index] || createRef()); | ||
|
@@ -654,7 +689,7 @@ const TabBar = memo(({ workspace }: TabBarProps) => { | |
title: "Add Tab", | ||
}; | ||
return ( | ||
<div ref={tabbarWrapperRef} className="tab-bar-wrapper"> | ||
<div ref={tabbarWrapperRef} className={clsx('tab-bar-wrapper', {'tab-bar-wrapper-auto-hide': autoHideTabBar, 'tab-bar-wrapper-always-visible': !autoHideTabBar})}> | ||
<WindowDrag ref={draggerLeftRef} className="left" /> | ||
{appMenuButton} | ||
{devLabel} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Z-index value needs adjustment to follow established system
The z-index value of 1000 in tabbar.scss does not align with the established z-index system in theme.scss. The highest z-index value defined in the theme is 550 (for flash-error-container), and most UI components use values between 1-100. The tabbar should use a themed z-index variable that fits within this hierarchy.
z-index: 1000
to use a themed variable like--zindex-tabbar
that should be defined in theme.scss with an appropriate value (likely between 100-500 based on other component values)🔗 Analysis chain
Verify z-index value in the component hierarchy
The z-index value of 1000 seems arbitrary. Please verify that this value:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 171
Script:
Length of output: 119041
Script:
Length of output: 2818
Script:
Length of output: 55
Script:
Length of output: 1103
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@esimkowitz Thank you for confirming. Let me know if there's anything else you need!