mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
fix: 修复contextMenu阻止关闭时,需要将event.preventDefault()一起阻止 (#10378)
This commit is contained in:
parent
f850c1befc
commit
1360cc1dcf
@ -49,7 +49,7 @@ interface ContextMenuState {
|
|||||||
align?: 'left' | 'right';
|
align?: 'left' | 'right';
|
||||||
onClose?: (ctx: ContextMenu) => void;
|
onClose?: (ctx: ContextMenu) => void;
|
||||||
contentClassName?: string;
|
contentClassName?: string;
|
||||||
preventClose?: (e: Event) => boolean;
|
preventClose?: (e?: Event) => boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ContextMenu extends React.Component<
|
export class ContextMenu extends React.Component<
|
||||||
@ -131,7 +131,7 @@ export class ContextMenu extends React.Component<
|
|||||||
onClose?: (ctx: ContextMenu) => void,
|
onClose?: (ctx: ContextMenu) => void,
|
||||||
options?: {
|
options?: {
|
||||||
contentClassName?: string;
|
contentClassName?: string;
|
||||||
preventClose?: (e: Event) => boolean;
|
preventClose?: (e?: Event) => boolean;
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
if (this.state.isOpened) {
|
if (this.state.isOpened) {
|
||||||
@ -173,10 +173,11 @@ export class ContextMenu extends React.Component<
|
|||||||
}
|
}
|
||||||
|
|
||||||
@autobind
|
@autobind
|
||||||
close(e: Event) {
|
close(e?: Event) {
|
||||||
if (this.state.preventClose?.(e)) {
|
if (this.state.preventClose?.(e)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
e?.preventDefault?.();
|
||||||
this.menuEntered = false;
|
this.menuEntered = false;
|
||||||
this.resizeObserver?.disconnect();
|
this.resizeObserver?.disconnect();
|
||||||
const onClose = this.state.onClose;
|
const onClose = this.state.onClose;
|
||||||
@ -208,7 +209,6 @@ export class ContextMenu extends React.Component<
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.state.isOpened) {
|
if (this.state.isOpened) {
|
||||||
e.preventDefault();
|
|
||||||
this.close(e);
|
this.close(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -236,7 +236,6 @@ export class ContextMenu extends React.Component<
|
|||||||
@autobind
|
@autobind
|
||||||
handleKeyDown(e: KeyboardEvent) {
|
handleKeyDown(e: KeyboardEvent) {
|
||||||
if (e.keyCode === 27 && this.state.isOpened) {
|
if (e.keyCode === 27 && this.state.isOpened) {
|
||||||
e.preventDefault();
|
|
||||||
this.close(e);
|
this.close(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -394,7 +393,7 @@ export async function openContextMenus(
|
|||||||
onClose?: (ctx: ContextMenu) => void,
|
onClose?: (ctx: ContextMenu) => void,
|
||||||
options?: {
|
options?: {
|
||||||
contentClassName?: string;
|
contentClassName?: string;
|
||||||
preventClose?: (e: Event) => boolean;
|
preventClose?: (e?: Event) => boolean;
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
return ContextMenu.getInstance().then(instance =>
|
return ContextMenu.getInstance().then(instance =>
|
||||||
|
Loading…
Reference in New Issue
Block a user