Browse Source

fix(message): call onClose after removeNotice (#38669)

* fix: call onClose after removeNotice

* feat: update demo and snapshots

* feat: update test case
pull/38833/head
kiner-tang(文辉) 2 years ago
committed by GitHub
parent
commit
934804763a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 35
      components/message/__tests__/__snapshots__/demo-extend.test.ts.snap
  2. 35
      components/message/__tests__/__snapshots__/demo.test.ts.snap
  3. 12
      components/message/__tests__/type.test.tsx
  4. 19
      components/message/demo/loading.md
  5. 1
      components/message/index.tsx

35
components/message/__tests__/__snapshots__/demo-extend.test.ts.snap

@ -45,14 +45,35 @@ exports[`renders ./components/message/demo/info.md extend context correctly 1`]
`;
exports[`renders ./components/message/demo/loading.md extend context correctly 1`] = `
<button
class="ant-btn ant-btn-default"
type="button"
<div
class="ant-space ant-space-horizontal ant-space-align-center"
>
<span>
Display a loading indicator
</span>
</button>
<div
class="ant-space-item"
style="margin-right:8px"
>
<button
class="ant-btn ant-btn-default"
type="button"
>
<span>
Display a loading indicator
</span>
</button>
</div>
<div
class="ant-space-item"
>
<button
class="ant-btn ant-btn-default"
type="button"
>
<span>
Display a loading and auto hide
</span>
</button>
</div>
</div>
`;
exports[`renders ./components/message/demo/other.md extend context correctly 1`] = `

35
components/message/__tests__/__snapshots__/demo.test.ts.snap

@ -45,14 +45,35 @@ exports[`renders ./components/message/demo/info.md correctly 1`] = `
`;
exports[`renders ./components/message/demo/loading.md correctly 1`] = `
<button
class="ant-btn ant-btn-default"
type="button"
<div
class="ant-space ant-space-horizontal ant-space-align-center"
>
<span>
Display a loading indicator
</span>
</button>
<div
class="ant-space-item"
style="margin-right:8px"
>
<button
class="ant-btn ant-btn-default"
type="button"
>
<span>
Display a loading indicator
</span>
</button>
</div>
<div
class="ant-space-item"
>
<button
class="ant-btn ant-btn-default"
type="button"
>
<span>
Display a loading and auto hide
</span>
</button>
</div>
</div>
`;
exports[`renders ./components/message/demo/other.md correctly 1`] = `

12
components/message/__tests__/type.test.tsx

@ -24,8 +24,16 @@ describe('message.typescript', () => {
);
});
it('hide', () => {
const hide = message.loading('doing...');
it('hide', (done) => {
const onClose = jest.fn();
const onClose2 = jest.fn();
const hide = message.loading('doing...', 0, onClose);
hide();
expect(onClose).toHaveBeenCalled();
message.loading('doing', 0.1, onClose2);
setTimeout(() => {
expect(onClose2).toHaveBeenCalled();
done();
}, 110);
});
});

19
components/message/demo/loading.md

@ -14,16 +14,29 @@ title:
Display a global loading indicator, which is dismissed by itself asynchronously.
```tsx
import { Button, message } from 'antd';
import { Button, message, Space } from 'antd';
import React from 'react';
const success = () => {
const hide = message.loading('Action in progress..', 0);
const hide = message.loading('Action in progress..', 0, () => {
message.success('loading had closed');
});
// Dismiss manually and asynchronously
setTimeout(hide, 2500);
};
const App: React.FC = () => <Button onClick={success}>Display a loading indicator</Button>;
const success2 = () => {
message.loading('Action in progress..', 3, () => {
message.success('loading had closed');
});
};
const App: React.FC = () => (
<Space>
<Button onClick={success}>Display a loading indicator</Button>
<Button onClick={success2}>Display a loading and auto hide</Button>
</Space>
);
export default App;
```

1
components/message/index.tsx

@ -194,6 +194,7 @@ function notice(args: ArgsProps): MessageType {
const result: any = () => {
if (messageInstance) {
messageInstance.removeNotice(target);
args.onClose?.();
}
};
result.then = (filled: ThenableArgument, rejected: ThenableArgument) =>

Loading…
Cancel
Save