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
4 changes: 2 additions & 2 deletions src/TabNavList/ExtraContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface ExtraContentProps {

const ExtraContent = React.forwardRef<HTMLDivElement, ExtraContentProps>((props, ref) => {
const { position, prefixCls, extra } = props;
if (!extra) {
if (!extra && extra !== 0) {
return null;
}

Expand All @@ -31,7 +31,7 @@ const ExtraContent = React.forwardRef<HTMLDivElement, ExtraContentProps>((props,
content = assertExtra.left;
}

return content ? (
return content || content === 0 ? (
<div className={`${prefixCls}-extra-content`} ref={ref}>
{content}
</div>
Expand Down
7 changes: 4 additions & 3 deletions src/TabNavList/TabNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const TabNode: React.FC<TabNodeProps> = props => {
const tabPrefix = `${prefixCls}-tab`;

const removable = getRemovable(closable, closeIcon, editable, disabled);
const hasIcon = !!icon || icon === 0;

function onInternalClick(e: React.MouseEvent | React.KeyboardEvent) {
if (disabled) {
Expand All @@ -68,8 +69,8 @@ const TabNode: React.FC<TabNodeProps> = props => {
}

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

const btnRef = React.useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -121,7 +122,7 @@ const TabNode: React.FC<TabNodeProps> = props => {
{`Tab ${currentPosition} of ${tabCount}`}
</div>
)}
{icon && <span className={`${tabPrefix}-icon`}>{icon}</span>}
{hasIcon && <span className={`${tabPrefix}-icon`}>{icon}</span>}
{label && labelNode}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
</div>

Expand Down
26 changes: 26 additions & 0 deletions tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,17 @@ describe('Tabs.Basic', () => {
);
});

it('renders numeric zero extra content', () => {
const { container, rerender } = render(getTabs({ tabBarExtraContent: 0 }));
expect(container.querySelectorAll('.rc-tabs-extra-content')).toHaveLength(1);
expect(container.querySelector('.rc-tabs-extra-content')).toHaveTextContent('0');

rerender(getTabs({ tabBarExtraContent: { left: 0, right: 0 } }));
expect(container.querySelectorAll('.rc-tabs-extra-content')).toHaveLength(2);
expect(container.querySelectorAll('.rc-tabs-extra-content')[0]).toHaveTextContent('0');
expect(container.querySelectorAll('.rc-tabs-extra-content')[1]).toHaveTextContent('0');
});

it('no break of empty object', () => {
render(getTabs({ tabBarExtraContent: {} }));
});
Expand Down Expand Up @@ -637,6 +648,21 @@ describe('Tabs.Basic', () => {
expect(container.querySelectorAll<HTMLSpanElement>(selectors).length).toBe(1);
});

it('renders numeric zero tab labels and icons', () => {
const { getAllByRole, container } = render(
<Tabs
items={[
{ key: 'zero-label', label: 0, children: 'Zero label content' },
{ key: 'zero-icon', label: 'Label', icon: 0, children: 'Zero icon content' },
]}
/>,
);

expect(getAllByRole('tab')[0]).toHaveTextContent('0');
expect(container.querySelector('.rc-tabs-tab-icon')).toHaveTextContent('0');
expect(getAllByRole('tab')[1].querySelectorAll('span')).toHaveLength(2);
});

it('support indicatorAlign', async () => {
const { container: startContainer, rerender: rerenderStart } = render(
<Tabs
Expand Down