Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update message content with a unique key and cancel manually #19967

Merged
merged 1 commit into from Nov 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions components/message/__tests__/index.test.js
Expand Up @@ -169,4 +169,24 @@ describe('message', () => {
jest.runAllTimers();
expect(document.querySelectorAll('.ant-message-notice').length).toBe(0);
});

it('update message content with a unique key and cancel manually', () => {
const key = 'updatable';
class Test extends React.Component {
componentDidMount() {
const hideLoading = message.loading({ content: 'Loading...', key, duration: 0 });
// Testing that content of the message should be cancel manually.
setTimeout(hideLoading, 1000);
}

render() {
return <div>test</div>;
}
}

mount(<Test />);
expect(document.querySelectorAll('.ant-message-notice').length).toBe(1);
jest.advanceTimersByTime(1500);
expect(document.querySelectorAll('.ant-message-notice').length).toBe(0);
});
});
2 changes: 1 addition & 1 deletion components/message/demo/update.md
Expand Up @@ -22,7 +22,7 @@ const openMessage = () => {
message.loading({ content: 'Loading...', key });
setTimeout(() => {
message.success({ content: 'Loaded!', key, duration: 2 });
});
}, 1000);
};

ReactDOM.render(
Expand Down
4 changes: 2 additions & 2 deletions components/message/index.tsx
Expand Up @@ -66,7 +66,7 @@ function notice(args: ArgsProps): MessageType {
loading: 'loading',
}[args.type];

const target = key++;
const target = args.key || key++;
const closePromise = new Promise(resolve => {
const callback = () => {
if (typeof args.onClose === 'function') {
Expand All @@ -80,7 +80,7 @@ function notice(args: ArgsProps): MessageType {
);
const switchIconNode = iconType ? iconNode : '';
instance.notice({
key: args.key || target,
key: target,
duration,
style: {},
content: (
Expand Down