Skip to content

Commit

Permalink
chore: merge master into feature
Browse files Browse the repository at this point in the history
  • Loading branch information
li-jia-nan committed Sep 5, 2023
2 parents ee8cf22 + dff3c63 commit 70466b0
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 24 deletions.
4 changes: 4 additions & 0 deletions README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ npm install antd --save
yarn add antd
```

```bash
pnpm add antd
```

## 🔨 示例

```jsx
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ npm install antd
yarn add antd
```

```bash
pnpm add antd
```

## 🔨 Usage

```jsx
Expand Down
4 changes: 2 additions & 2 deletions components/avatar/style/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { genComponentStyleHook, mergeToken } from '../../theme/internal';

export interface ComponentToken {
/**
* @desc 头像背景色
* @descEN Background color of Avatar
* @desc 头像尺寸
* @descEN Size of Avatar
*/
containerSize: number;
/**
Expand Down
3 changes: 2 additions & 1 deletion components/date-picker/style/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { CSSObject } from '@ant-design/cssinjs';
import { TinyColor } from '@ctrl/tinycolor';

import type { SharedComponentToken, SharedInputToken } from '../../input/style';
import {
genActiveStyle,
Expand Down Expand Up @@ -682,7 +683,7 @@ export const genPanelStyle = (token: SharedPickerToken): CSSObject => {
textAlign: 'center',

'&-extra': {
padding: `0 ${paddingSM}`,
padding: `0 ${paddingSM}px`,
lineHeight: `${textHeight - 2 * lineWidth}px`,
textAlign: 'start',

Expand Down
6 changes: 5 additions & 1 deletion components/modal/ConfirmDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ const ConfirmDialog: React.FC<ConfirmDialogProps> = (props) => {
closeIcon,
modalRender,
focusTriggerAfterClose,
onConfirm,
} = props;

if (process.env.NODE_ENV !== 'production') {
Expand Down Expand Up @@ -220,7 +221,10 @@ const ConfirmDialog: React.FC<ConfirmDialogProps> = (props) => {
{ [`${confirmPrefixCls}-centered`]: !!props.centered },
wrapClassName,
)}
onCancel={() => close?.({ triggerCancel: true })}
onCancel={() => {
close?.({ triggerCancel: true });
onConfirm?.(false);
}}
open={open}
title=""
footer={null}
Expand Down
74 changes: 55 additions & 19 deletions components/modal/__tests__/hook.test.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React from 'react';
import CSSMotion from 'rc-motion';
import { genCSSMotion } from 'rc-motion/lib/CSSMotion';
import KeyCode from 'rc-util/lib/KeyCode';
import React from 'react';
import { act } from 'react-dom/test-utils';

import Modal from '..';
import zhCN from '../../locale/zh_CN';
import { fireEvent, render, waitFakeTimer } from '../../../tests/utils';
import Button from '../../button';
import ConfigProvider from '../../config-provider';
import Input from '../../input';
import zhCN from '../../locale/zh_CN';
import type { ModalFunc } from '../confirm';

jest.mock('rc-util/lib/Portal');
Expand Down Expand Up @@ -410,10 +410,55 @@ describe('Modal.hook', () => {
jest.useRealTimers();
});

it('support await', async () => {
describe('support await', () => {
it('click', async () => {
jest.useFakeTimers();

let notReady = true;
let lastResult: boolean | null = null;

const Demo: React.FC = () => {
const [modal, contextHolder] = Modal.useModal();

React.useEffect(() => {
(async () => {
lastResult = await modal.confirm({
content: <Input />,
onOk: async () => {
if (notReady) {
notReady = false;
return Promise.reject();
}
},
});
})();
}, []);

return contextHolder;
};

render(<Demo />);

// Wait for modal show
await waitFakeTimer();

// First time click should not close
fireEvent.click(document.querySelector('.ant-btn-primary')!);
await waitFakeTimer();
expect(lastResult).toBeFalsy();

// Second time click to close
fireEvent.click(document.querySelector('.ant-btn-primary')!);
await waitFakeTimer();
expect(lastResult).toBeTruthy();

jest.useRealTimers();
});
});

it('esc', async () => {
jest.useFakeTimers();

let notReady = true;
let lastResult: boolean | null = null;

const Demo: React.FC = () => {
Expand All @@ -423,12 +468,6 @@ describe('Modal.hook', () => {
(async () => {
lastResult = await modal.confirm({
content: <Input />,
onOk: async () => {
if (notReady) {
notReady = false;
return Promise.reject();
}
},
});
})();
}, []);
Expand All @@ -441,16 +480,13 @@ describe('Modal.hook', () => {
// Wait for modal show
await waitFakeTimer();

// First time click should not close
fireEvent.click(document.querySelector('.ant-btn-primary')!);
await waitFakeTimer();
expect(lastResult).toBeFalsy();

// Second time click to close
fireEvent.click(document.querySelector('.ant-btn-primary')!);
// ESC to close
fireEvent.keyDown(document.querySelector('.ant-modal')!, {
key: 'Esc',
keyCode: KeyCode.ESC,
});
await waitFakeTimer();
expect(lastResult).toBeTruthy();

jest.useRealTimers();
expect(lastResult).toBe(false);
});
});
2 changes: 1 addition & 1 deletion components/tree/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type {
AntdTreeNodeAttribute,
TreeProps,
} from './Tree';
export type { DataNode };
export type { DataNode, BasicDataNode };

type CompoundedComponent = (<T extends BasicDataNode | DataNode = DataNode>(
props: React.PropsWithChildren<TreeProps<T>> & { ref?: React.Ref<RcTree> },
Expand Down

0 comments on commit 70466b0

Please sign in to comment.