Skip to content

Commit

Permalink
fix: replace onOpenChange with afterOpenChange
Browse files Browse the repository at this point in the history
  • Loading branch information
MuxinFeng committed Feb 28, 2023
1 parent e24b8d1 commit 3bd603f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
14 changes: 7 additions & 7 deletions src/Dialog/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as React from 'react';
import { useRef, useEffect } from 'react';
import classNames from 'classnames';
import KeyCode from 'rc-util/lib/KeyCode';
import useId from 'rc-util/lib/hooks/useId';
import contains from 'rc-util/lib/Dom/contains';
import useId from 'rc-util/lib/hooks/useId';
import KeyCode from 'rc-util/lib/KeyCode';
import pickAttrs from 'rc-util/lib/pickAttrs';
import * as React from 'react';
import { useEffect, useRef } from 'react';
import type { IDialogPropTypes } from '../IDialogPropTypes';
import Mask from './Mask';
import { getMotionName } from '../util';
import Content from './Content';
import type { ContentRef } from './Content/Panel';
import Mask from './Mask';

export default function Dialog(props: IDialogPropTypes) {
const {
Expand All @@ -25,7 +25,7 @@ export default function Dialog(props: IDialogPropTypes) {
wrapClassName,
wrapProps,
onClose,
onOpenChange,
afterOpenChange,
afterClose,

// Dialog
Expand Down Expand Up @@ -87,7 +87,7 @@ export default function Dialog(props: IDialogPropTypes) {
afterClose?.();
}
}
onOpenChange?.(newVisible);
afterOpenChange?.(newVisible);
}

function onInternalClose(e: React.SyntheticEvent) {
Expand Down
2 changes: 1 addition & 1 deletion src/IDialogPropTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type IDialogPropTypes = {
mask?: boolean;
children?: any;
afterClose?: () => any;
onOpenChange?: (open: boolean) => void;
afterOpenChange?: (open: boolean) => void;
onClose?: (e: SyntheticEvent) => any;
closable?: boolean;
maskClosable?: boolean;
Expand Down
14 changes: 7 additions & 7 deletions tests/index.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable react/no-render-return-value, max-classes-per-file, func-names, no-console */
import React, { cloneElement, useEffect } from 'react';
import { act } from 'react-dom/test-utils';
import { render } from '@testing-library/react';
import type { ReactWrapper } from 'enzyme';
import { mount } from 'enzyme';
import KeyCode from 'rc-util/lib/KeyCode';
import React, { cloneElement, useEffect } from 'react';
import { act } from 'react-dom/test-utils';
import type { DialogProps } from '../src';
import Dialog from '../src';

Expand Down Expand Up @@ -506,17 +506,17 @@ describe('dialog', () => {
});
});

describe('onOpenChange', () => {
it('should trigger onOpenChange when visible changed', () => {
const onOpenChange = jest.fn();
describe('afterOpenChange', () => {
it('should trigger afterOpenChange when visible changed', () => {
const afterOpenChange = jest.fn();

const wrapper = mount(<Dialog onOpenChange={onOpenChange} visible />);
const wrapper = mount(<Dialog afterOpenChange={afterOpenChange} visible />);
jest.runAllTimers();

wrapper.setProps({ visible: false });
jest.runAllTimers();

expect(onOpenChange).toHaveBeenCalledTimes(2);
expect(afterOpenChange).toHaveBeenCalledTimes(2);
});
});
});

0 comments on commit 3bd603f

Please sign in to comment.