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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add span tag to label #681

Merged
merged 7 commits into from
Nov 28, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/TabNavList/TabNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ const TabNode: React.FC<TabNodeProps> = props => {
editable.onEdit('remove', { key, event });
}

const labelNode = React.useMemo<React.ReactNode>(
() => (icon && typeof label === 'string' ? <span>{label}</span> : label),
[label, icon],
);

const node: React.ReactElement = (
<div
key={key}
Expand Down Expand Up @@ -86,7 +91,7 @@ const TabNode: React.FC<TabNodeProps> = props => {
onFocus={onFocus}
>
{icon && <span className={`${tabPrefix}-icon`}>{icon}</span>}
{label}
{label && labelNode}
</div>

{/* Remove Button */}
Expand Down
10 changes: 10 additions & 0 deletions tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -638,4 +638,14 @@ describe('Tabs.Basic', () => {
await waitFakeTimer();
expect(container.querySelector('.rc-tabs-ink-bar')).toHaveStyle({ width: '18px' });
});

it('Add span to text label when have icon', () => {
const selectors = '.rc-tabs-tab .rc-tabs-tab-btn span';
const { container, rerender } = render(
<Tabs items={[{ key: 'key', label: 'test', icon: 'test' }]} />,
);
expect(container.querySelectorAll<HTMLSpanElement>(selectors).length).toBe(2);
rerender(<Tabs items={[{ key: 'key', label: <div>test</div>, icon: 'test' }]} />);
expect(container.querySelectorAll<HTMLSpanElement>(selectors).length).toBe(1);
});
});
Loading