fix(core): prevent floating sidebar from disappearing unexpectedly (#8477)

close AF-1475

Fixed an issue where you couldn't create collection or use the rename function in the floating sidebar.

https://github.com/user-attachments/assets/41c2b6a8-8fc9-4f8b-ab51-bd7ce2a58738
This commit is contained in:
JimmFly
2024-10-19 13:24:07 +00:00
parent 01c3a3b4c0
commit 675a010dfc
4 changed files with 29 additions and 16 deletions

View File

@@ -51,6 +51,7 @@ export const RenameModal = ({
sideOffset: -12,
onClick: e => e.stopPropagation(),
style: { borderRadius: 10, padding: 8 },
role: 'rename-modal',
}}
items={
<Input

View File

@@ -124,13 +124,28 @@ export function AppSidebar({ children }: PropsWithChildren) {
appSidebarService.setOpen(false);
}, [appSidebarService]);
const onMouseEnter = useCallback(() => {
appSidebarService.setHovering(true);
}, [appSidebarService]);
useEffect(() => {
if (sidebarState !== 'floating' || resizing) {
return;
}
const onMouseMove = (e: MouseEvent) => {
const menuElement = document.querySelector(
'body > [data-radix-popper-content-wrapper] > [data-radix-menu-content]'
);
const onMouseLeave = useCallback(() => {
appSidebarService.setHovering(false);
}, [appSidebarService]);
if (menuElement) {
return;
}
if (e.clientX > width + 20) {
appSidebarService.setHovering(false);
}
};
document.addEventListener('mousemove', onMouseMove);
return () => {
document.removeEventListener('mousemove', onMouseMove);
};
}, [appSidebarService, resizing, sidebarState, width]);
return (
<>
@@ -152,8 +167,6 @@ export function AppSidebar({ children }: PropsWithChildren) {
})}
resizeHandleOffset={0}
resizeHandleVerticalPadding={clientBorder ? 16 : 0}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
data-transparent
data-open={sidebarState !== 'close'}
data-has-border={hasRightBorder}

View File

@@ -26,10 +26,6 @@ export const SidebarSwitch = ({
appSidebarService.toggleSidebar();
}, [appSidebarService]);
const handleMouseLeave = useCallback(() => {
appSidebarService.setHovering(false);
}, [appSidebarService]);
const t = useI18n();
const tooltipContent = open
? t['com.affine.sidebarSwitch.collapse']()
@@ -42,7 +38,6 @@ export const SidebarSwitch = ({
className={styles.sidebarSwitchClip}
data-testid={`app-sidebar-arrow-button-${open ? 'collapse' : 'expand'}`}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>
<IconButton
tooltip={tooltipContent}