Skip to content

Commit

Permalink
fix one test
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Aug 21, 2020
1 parent 23b450c commit d9604fa
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 24 deletions.
3 changes: 0 additions & 3 deletions index.js

This file was deleted.

52 changes: 34 additions & 18 deletions src/Dialog.tsx
Expand Up @@ -4,7 +4,7 @@ import KeyCode from 'rc-util/lib/KeyCode';
import contains from 'rc-util/lib/Dom/contains';
import Animate from 'rc-animate';
import LazyRenderBox from './LazyRenderBox';
import IDialogPropTypes from './IDialogPropTypes';
import { IDialogPropTypes } from './IDialogPropTypes';

let uuid = 0;

Expand Down Expand Up @@ -80,7 +80,7 @@ export default class Dialog extends React.Component<IDialogChildProps, any> {

private dialogMouseDown: boolean;

private timeoutId: number;
private timeoutId: any;

private switchScrollingEffect: () => void;

Expand All @@ -106,7 +106,7 @@ export default class Dialog extends React.Component<IDialogChildProps, any> {
}

componentDidUpdate(prevProps: IDialogPropTypes) {
const {visible, mask, focusTriggerAfterClose} = this.props;
const { visible, mask, focusTriggerAfterClose } = this.props;
const { mousePosition } = this.props;
if (visible) {
// first show
Expand Down Expand Up @@ -169,19 +169,19 @@ export default class Dialog extends React.Component<IDialogChildProps, any> {
if (afterClose) {
afterClose();
}
}
};

onDialogMouseDown = () => {
this.dialogMouseDown = true;
}
};

onMaskMouseUp: React.MouseEventHandler<HTMLDivElement> = () => {
if (this.dialogMouseDown) {
this.timeoutId = setTimeout(() => {
this.dialogMouseDown = false;
}, 0);
}
}
};

onMaskClick = (e: React.MouseEvent<HTMLDivElement>) => {
// android trigger click on open (fastclick??)
Expand All @@ -191,7 +191,7 @@ export default class Dialog extends React.Component<IDialogChildProps, any> {
if (e.target === e.currentTarget && !this.dialogMouseDown) {
this.close(e);
}
}
};

onKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {
const { keyboard, visible } = this.props;
Expand All @@ -213,10 +213,26 @@ export default class Dialog extends React.Component<IDialogChildProps, any> {
}
}
}
}
};

getDialogElement = () => {
const { closable, prefixCls, width, height, footer, title, closeIcon, style, className, visible, forceRender, bodyStyle, bodyProps, children, destroyOnClose } = this.props;
const {
closable,
prefixCls,
width,
height,
footer,
title,
closeIcon,
style,
className,
visible,
forceRender,
bodyStyle,
bodyProps,
children,
destroyOnClose,
} = this.props;
const dest: any = {};
if (width !== undefined) {
dest.width = width;
Expand Down Expand Up @@ -313,7 +329,7 @@ export default class Dialog extends React.Component<IDialogChildProps, any> {
{visible || !destroyOnClose ? dialogElement : null}
</Animate>
);
}
};

getZIndexStyle = () => {
const style: any = {};
Expand All @@ -322,15 +338,15 @@ export default class Dialog extends React.Component<IDialogChildProps, any> {
style.zIndex = zIndex;
}
return style;
}
};

getWrapStyle = (): any => {
return { ...this.getZIndexStyle(), ...this.props.wrapStyle };
}
};

getMaskStyle = () => {
return { ...this.getZIndexStyle(), ...this.props.maskStyle };
}
};

getMaskElement = () => {
const { mask, prefixCls, visible, maskProps } = this.props;
Expand Down Expand Up @@ -362,7 +378,7 @@ export default class Dialog extends React.Component<IDialogChildProps, any> {
}
}
return maskElement;
}
};

getMaskTransitionName = () => {
const { maskTransitionName, maskAnimation, prefixCls } = this.props;
Expand All @@ -373,7 +389,7 @@ export default class Dialog extends React.Component<IDialogChildProps, any> {
}

return transitionName;
}
};

getTransitionName = () => {
const { transitionName, animation, prefixCls } = this.props;
Expand All @@ -382,18 +398,18 @@ export default class Dialog extends React.Component<IDialogChildProps, any> {
transitionNameResult = `${prefixCls}-${animation}`;
}
return transitionNameResult;
}
};

close = (e: any) => {
const { onClose } = this.props;
if (onClose) {
onClose(e);
}
}
};

saveRef = (name: string) => (node: any) => {
(this as any)[name] = node;
}
};

render() {
const { props } = this;
Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
@@ -0,0 +1,5 @@
import Dialog, { IDialogChildProps as DialogProps } from './Dialog';

export { DialogProps };

export default Dialog;
6 changes: 3 additions & 3 deletions tests/index.spec.js
Expand Up @@ -6,7 +6,7 @@ import { mount } from 'enzyme';
import async from 'async';
import KeyCode from 'rc-util/lib/KeyCode';

import Dialog from '../index';
import Dialog from '../src';
import '../assets/bootstrap.less';

describe('dialog', () => {
Expand Down Expand Up @@ -40,7 +40,7 @@ describe('dialog', () => {
dialog.setState({ visible: true });
jest.runAllTimers();
dialog.update();
expect(dialog.find('.rc-dialog-wrap').props().style.display).toEqual('block');
expect(dialog.find('.rc-dialog-wrap').props().style.display).toEqual(null);
});

// it('close', () => {
Expand All @@ -54,7 +54,7 @@ describe('dialog', () => {
// // jest.runAllTimers();
// expect(dialog.find('.rc-dialog-wrap').props().style.display).toEqual('none');
// // setTimeout(() => {

// // }, 10);
// });

Expand Down

0 comments on commit d9604fa

Please sign in to comment.