mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 02:59:58 +08:00
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:
parent
6e8c441fc8
commit
3464fafe15
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user