fix(mobile): handle touch event correctly (#8496)
related:
radix-ui has a hack for dealing with touch event on mobile devices. we may not want to stop propagation for event that is not being handled, even for links
74b182b401/packages/react/dismissable-layer/src/DismissableLayer.tsx (L243-L261)
This commit is contained in:
@@ -302,13 +302,19 @@ export const ExplorerTreeNode = ({
|
|||||||
[onRename]
|
[onRename]
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleClick = useCallback(() => {
|
const handleClick = useCallback(
|
||||||
if (!clickForCollapse) {
|
(e: React.MouseEvent) => {
|
||||||
onClick?.();
|
if (e.defaultPrevented) {
|
||||||
} else {
|
return;
|
||||||
setCollapsed(!collapsed);
|
}
|
||||||
}
|
if (!clickForCollapse) {
|
||||||
}, [clickForCollapse, collapsed, onClick, setCollapsed]);
|
onClick?.();
|
||||||
|
} else {
|
||||||
|
setCollapsed(!collapsed);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[clickForCollapse, collapsed, onClick, setCollapsed]
|
||||||
|
);
|
||||||
|
|
||||||
const content = (
|
const content = (
|
||||||
<div
|
<div
|
||||||
@@ -346,18 +352,15 @@ export const ExplorerTreeNode = ({
|
|||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={mobile ? styles.mobileItemContent : styles.itemContent}>
|
<div className={mobile ? styles.mobileItemContent : styles.itemContent}>
|
||||||
{name}
|
{name}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{postfix}
|
{postfix}
|
||||||
{mobile ? null : (
|
{mobile ? null : (
|
||||||
<div
|
<div
|
||||||
className={styles.postfix}
|
className={styles.postfix}
|
||||||
onClick={e => {
|
onClick={e => {
|
||||||
// prevent jump to page
|
// prevent jump to page
|
||||||
e.stopPropagation();
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useCatchEventCallback } from '@affine/core/components/hooks/use-catch-event-hook';
|
import { useAsyncCallback } from '@affine/core/components/hooks/affine-async-hooks';
|
||||||
import { isNewTabTrigger } from '@affine/core/utils';
|
import { isNewTabTrigger } from '@affine/core/utils';
|
||||||
import {
|
import {
|
||||||
FeatureFlagService,
|
FeatureFlagService,
|
||||||
@@ -32,7 +32,7 @@ export const WorkbenchLink = forwardRef<HTMLAnchorElement, WorkbenchLinkProps>(
|
|||||||
const link =
|
const link =
|
||||||
basename +
|
basename +
|
||||||
(typeof to === 'string' ? to : `${to.pathname}${to.search}${to.hash}`);
|
(typeof to === 'string' ? to : `${to.pathname}${to.search}${to.hash}`);
|
||||||
const handleClick = useCatchEventCallback(
|
const handleClick = useAsyncCallback(
|
||||||
async (event: React.MouseEvent<HTMLAnchorElement>) => {
|
async (event: React.MouseEvent<HTMLAnchorElement>) => {
|
||||||
onClick?.(event);
|
onClick?.(event);
|
||||||
if (event.defaultPrevented) {
|
if (event.defaultPrevented) {
|
||||||
@@ -48,6 +48,7 @@ export const WorkbenchLink = forwardRef<HTMLAnchorElement, WorkbenchLinkProps>(
|
|||||||
})();
|
})();
|
||||||
workbench.open(to, { at, replaceHistory });
|
workbench.open(to, { at, replaceHistory });
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
},
|
},
|
||||||
[enableMultiView, onClick, replaceHistory, to, workbench]
|
[enableMultiView, onClick, replaceHistory, to, workbench]
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user