Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"dependencies": {
"@rc-component/portal": "^2.2.0",
"@rc-component/trigger": "^3.0.0",
"@rc-component/util": "^1.11.1",
"@rc-component/util": "^1.13.0",
"clsx": "^2.1.1"
},
"devDependencies": {
Expand Down
6 changes: 4 additions & 2 deletions src/hooks/useClosable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { isReactRenderable } from '@rc-component/util';
import type { TourProps } from '../interface';
import type { TourStepInfo } from '../TourStep';

Expand Down Expand Up @@ -31,7 +32,8 @@ function getClosableConfig(
): ClosableConfig | 'empty' {
if (
closable === false ||
(closeIcon === false && (!isConfigObj(closable) || !closable.closeIcon))
(closeIcon === false &&
(!isConfigObj(closable) || !isReactRenderable(closable.closeIcon)))
) {
return null;
}
Expand All @@ -47,7 +49,7 @@ function getClosableConfig(
}

// When StepClosable no need auto fill, but RootClosable need this.
return preset || closable || closeIcon
return preset || closable || isReactRenderable(closeIcon)
? {
closeIcon: mergedCloseIcon,
}
Expand Down
27 changes: 27 additions & 0 deletions tests/renderability.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import { render } from '@testing-library/react';
import Tour from '../src';

it('uses the zero step icon instead of the root icon', () => {
const { baseElement } = render(
<Tour open closeIcon="ROOT" steps={[{ title: 'Step', closeIcon: 0 }]} />,
);
expect(baseElement.querySelector('.rc-tour-close').textContent).toBe('0');
});

it('lets a configured zero icon override closeIcon=false', () => {
const { baseElement } = render(
<Tour
open
steps={[{ title: 'Step', closeIcon: false, closable: { closeIcon: 0 } }]}
/>,
);
expect(baseElement.querySelector('.rc-tour-close').textContent).toBe('0');
});

it('preserves closable=false even with a zero icon', () => {
const { baseElement } = render(
<Tour open steps={[{ title: 'Step', closable: false, closeIcon: 0 }]} />,
);
expect(baseElement.querySelector('.rc-tour-close')).toBeNull();
});
Loading