fix: Tour onClose wrong current argument (#49124)

* fix: Tour onClose wrong current argument

* test: add test case

* Update components/tour/panelRender.tsx

Signed-off-by: afc163 <afc163@gmail.com>

---------

Signed-off-by: afc163 <afc163@gmail.com>
This commit is contained in:
afc163 2024-05-30 18:07:39 +08:00 committed by GitHub
parent 6e8c441fc8
commit 3464fafe15
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 13 deletions

View File

@ -565,6 +565,31 @@ describe('Tour', () => {
expect(document.querySelector('.should-be-primary')).toHaveClass('ant-tour-primary');
});
// https://github.com/ant-design/ant-design/issues/49117
it('onClose current is correct', () => {
const onClose = jest.fn();
const { container } = render(
<Tour
onClose={onClose}
open
steps={[
{
title: '',
description: '',
type: 'primary',
className: 'should-be-primary',
},
{
title: '',
},
]}
/>,
);
fireEvent.click(container.querySelector('.ant-tour-next-btn')!);
fireEvent.click(container.querySelector('.ant-tour-close-icon')!);
expect(onClose).toHaveBeenLastCalledWith(1);
});
// This test is for PurePanel which means safe to remove.
describe('PurePanel', () => {
const PurePanel = Tour._InternalPanelDoNotUseOrYouWillBeFired;

View File

@ -44,19 +44,11 @@ const TourPanel: React.FC<TourPanelProps> = (props) => {
const mergedType = stepType ?? type;
const mergedCloseIcon = React.useMemo(() => {
let defaultCloseIcon: React.ReactNode = <CloseOutlined className={`${prefixCls}-close-icon`} />;
if (closable && closable.closeIcon) {
defaultCloseIcon = closable.closeIcon;
}
return (
<button type="button" onClick={onClose} className={`${prefixCls}-close`}>
{defaultCloseIcon}
</button>
);
}, [closable]);
const mergedCloseIcon = (
<button type="button" onClick={onClose} className={`${prefixCls}-close`}>
{closable?.closeIcon || <CloseOutlined className={`${prefixCls}-close-icon`} />}
</button>
);
const isLastStep = current === total - 1;