Skip to content

Commit

Permalink
fix: popover re-click position bug & drag panel drag bug (#165)
Browse files Browse the repository at this point in the history
* fix: popover reClick position bug

* fix: drag event lose when drag over iframe
  • Loading branch information
BoBoooooo authored May 29, 2024
1 parent bb92210 commit f83c6bc
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 4 deletions.
2 changes: 1 addition & 1 deletion apps/playground/src/helpers/mock-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const tangoConfigJson = {
},
'@music163/antd': {
description: '云音乐低代码中后台应用基础物料',
version: '0.2.5',
version: '0.2.6',
library: 'TangoAntd',
type: 'baseDependency',
resources: [
Expand Down
43 changes: 43 additions & 0 deletions apps/storybook/src/ui/drag-panel.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from 'react';
import { DragPanel } from '@music163/tango-ui';
import { Box, Text } from 'coral-system';
import { Button } from 'antd';

export default {
title: 'UI/DragPanel',
};

export function Basic() {
return (
<DragPanel
title="弹层标题"
extra="右上角内容"
width={350}
body={<Box p="m">内容</Box>}
footer={<Text>底部信息</Text>}
>
<Button>点击唤起浮层</Button>
</DragPanel>
);
}

export function FooterCustom() {
return (
<DragPanel
title="弹层标题"
extra="右上角内容"
width={350}
body={<Box p="m">内容</Box>}
footer={(close) => (
<Box display="flex" justifyContent="space-between">
<Text>底部信息</Text>
<Button size="small" onClick={() => close()}>
点此关闭
</Button>
</Box>
)}
>
<Button>点击唤起浮层</Button>
</DragPanel>
);
}
27 changes: 25 additions & 2 deletions packages/ui/src/drag-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ import Draggable from 'react-draggable';
import { CloseOutlined } from '@ant-design/icons';
import { noop } from '@music163/tango-helpers';

// Dragging over an iframe stops dragging when moving the mouse too fast #613
// https://github.com/react-grid-layout/react-draggable/issues/613
const injectStyleToBody = () => {
const id = 'react-draggable-transparent-selection';
if (document.getElementById(id)) {
return;
}
const style = document.createElement('style');
style.id = id;
style.innerHTML = `
/* Prevent iframes from stealing drag events */
.react-draggable-transparent-selection iframe {
pointer-events: none;
}
`;
document.head.appendChild(style);
};

const CloseIcon = styled(CloseOutlined)`
cursor: pointer;
margin-left: 10px;
Expand All @@ -17,7 +35,7 @@ const CloseIcon = styled(CloseOutlined)`
}
`;

interface DragPanelProps extends Omit<PopoverProps, 'overlay'> {
interface DragPanelProps extends Omit<PopoverProps, 'overlay' | 'open'> {
// 标题
title?: React.ReactNode | string;
// 内容
Expand Down Expand Up @@ -59,7 +77,12 @@ export function DragPanel({
onOpenChange(innerOpen);
}}
overlay={
<Draggable handle=".selection-drag-bar">
<Draggable
handle=".selection-drag-bar"
onStart={() => {
injectStyleToBody();
}}
>
<Box
bg="#FFF"
borderRadius="m"
Expand Down
7 changes: 6 additions & 1 deletion packages/ui/src/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,19 @@ export const Popover: React.FC<PopoverProps> = ({
const handleClick = useCallback(
(e: React.MouseEvent) => {
e.preventDefault();
if (visible) {
setVisible(false);
onOpenChange(false);
return;
}
const x = e.clientX;
const y = e.clientY;
setLeft(x);
setTop(y + 10);
setVisible(true);
onOpenChange(true);
},
[onOpenChange],
[visible, onOpenChange],
);

useEffect(() => {
Expand Down

0 comments on commit f83c6bc

Please sign in to comment.