mirror of
https://github.com/NetEase/tango.git
synced 2026-09-01 15:03:03 +08:00
fix: popover re-click position bug & drag panel drag bug (#165)
* fix: popover reClick position bug * fix: drag event lose when drag over iframe
This commit is contained in:
@@ -56,7 +56,7 @@ const tangoConfigJson = {
|
||||
},
|
||||
'@music163/antd': {
|
||||
description: '云音乐低代码中后台应用基础物料',
|
||||
version: '0.2.5',
|
||||
version: '0.2.6',
|
||||
library: 'TangoAntd',
|
||||
type: 'baseDependency',
|
||||
resources: [
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
// 内容
|
||||
@@ -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"
|
||||
|
||||
@@ -97,6 +97,11 @@ 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);
|
||||
@@ -104,7 +109,7 @@ export const Popover: React.FC<PopoverProps> = ({
|
||||
setVisible(true);
|
||||
onOpenChange(true);
|
||||
},
|
||||
[onOpenChange],
|
||||
[visible, onOpenChange],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user