mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
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:
@@ -51,6 +51,7 @@ export const RenameModal = ({
|
||||
sideOffset: -12,
|
||||
onClick: e => e.stopPropagation(),
|
||||
style: { borderRadius: 10, padding: 8 },
|
||||
role: 'rename-modal',
|
||||
}}
|
||||
items={
|
||||
<Input
|
||||
|
||||
@@ -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(() => {
|
||||
if (menuElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.clientX > width + 20) {
|
||||
appSidebarService.setHovering(false);
|
||||
}, [appSidebarService]);
|
||||
}
|
||||
};
|
||||
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}
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -92,8 +92,10 @@ test('Collapse Sidebar', async ({ page }) => {
|
||||
await page
|
||||
.locator('[data-testid=app-sidebar-arrow-button-collapse][data-show=true]')
|
||||
.click();
|
||||
await page.mouse.move(500, 500);
|
||||
const sliderBarArea = page.getByTestId('app-sidebar');
|
||||
await sliderBarArea.hover();
|
||||
await page.mouse.move(600, 500);
|
||||
await page.waitForTimeout(5000);
|
||||
await expect(sliderBarArea).not.toBeInViewport();
|
||||
});
|
||||
|
||||
@@ -101,8 +103,10 @@ test('Expand Sidebar', async ({ page }) => {
|
||||
await page
|
||||
.locator('[data-testid=app-sidebar-arrow-button-collapse][data-show=true]')
|
||||
.click();
|
||||
await page.mouse.move(500, 500);
|
||||
const sliderBarArea = page.getByTestId('sliderBar-inner');
|
||||
const sliderBarArea = page.getByTestId('app-sidebar');
|
||||
await sliderBarArea.hover();
|
||||
await page.mouse.move(600, 500);
|
||||
await page.waitForTimeout(5000);
|
||||
await expect(sliderBarArea).not.toBeInViewport();
|
||||
|
||||
await page
|
||||
|
||||
Reference in New Issue
Block a user