Skip to content

Commit

Permalink
fix: add span tag to label (#681)
Browse files Browse the repository at this point in the history
* fix: add span tag to label

* fix: fix

* update snap

* fix: fix

* test: add test case

* Update tests/index.test.tsx

Co-authored-by: MadCcc <[email protected]>

---------

Co-authored-by: MadCcc <[email protected]>
  • Loading branch information
li-jia-nan and MadCcc authored Nov 28, 2023
1 parent ee145ae commit f2bd7a6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
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);
});
});

1 comment on commit f2bd7a6

@vercel
Copy link

@vercel vercel bot commented on f2bd7a6 Nov 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deployment failed with the following error:

Resource is limited - try again in 11 minutes (more than 100, code: "api-deployments-free-per-day").

Please sign in to comment.