如果事件阻止了,不关闭

This commit is contained in:
2betop 2020-05-09 09:54:04 +08:00
parent 3fb4114461
commit c89994e64a
3 changed files with 9 additions and 6 deletions

View File

@ -24,7 +24,7 @@ export interface DrawerProps {
bodyClassName?: string;
size: any;
overlay: boolean;
onHide: () => void;
onHide: (e: any) => void;
closeOnEsc?: boolean;
container: any;
show?: boolean;
@ -109,10 +109,13 @@ export class Drawer extends React.Component<DrawerProps, DrawerState> {
@autobind
handleRootClick(e: MouseEvent) {
const {classPrefix: ns, closeOnOutside, onHide, show} = this.props;
if ((e.target as HTMLElement).closest(`.${ns}Drawer-content`)) {
if (
e.defaultPrevented ||
(e.target as HTMLElement).closest(`.${ns}Drawer-content`)
) {
return;
}
closeOnOutside && show && onHide && onHide();
closeOnOutside && show && onHide && onHide(e);
}
render() {

View File

@ -20,7 +20,7 @@ export interface ModalProps {
contentClassName?: string;
size?: any;
overlay?: boolean;
onHide: () => void;
onHide: (e: any) => void;
closeOnEsc?: boolean;
container?: any;
show?: boolean;

View File

@ -8,7 +8,7 @@ import keycode from 'keycode';
interface ModalComponent
extends React.Component<{
onHide: () => void;
onHide: (e: any) => void;
disabled?: boolean;
closeOnEsc?: boolean;
}> {}
@ -44,6 +44,6 @@ function handleWindowKeyDown(e: Event) {
}
const {disabled, closeOnEsc} = modal.props;
if (closeOnEsc && !disabled) {
modal.props.onHide();
modal.props.onHide(e);
}
}