Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 17 additions & 7 deletions src/TabNavList/TabNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ export interface TabNodeProps {
onMouseUp: React.MouseEventHandler;
onFocus: React.FocusEventHandler;
onBlur: React.FocusEventHandler;
style?: React.CSSProperties;
className?: string;
styles?: {
root?: React.CSSProperties;
icon?: React.CSSProperties;
};
classNames?: {
root?: string;
icon?: string;
};
}

const TabNode: React.FC<TabNodeProps> = props => {
Expand All @@ -44,8 +50,8 @@ const TabNode: React.FC<TabNodeProps> = props => {
onKeyDown,
onMouseDown,
onMouseUp,
style,
className,
styles,
classNames,
tabCount,
currentPosition,
} = props;
Expand Down Expand Up @@ -83,13 +89,13 @@ const TabNode: React.FC<TabNodeProps> = props => {
<div
key={key}
data-node-key={genDataNodeKey(key)}
className={clsx(tabPrefix, className, {
className={clsx(tabPrefix, classNames?.root, {
[`${tabPrefix}-with-remove`]: removable,
[`${tabPrefix}-active`]: active,
[`${tabPrefix}-disabled`]: disabled,
[`${tabPrefix}-focus`]: focus,
})}
style={style}
style={styles.root}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The styles prop is defined as optional in TabNodeProps, but styles.root is accessed directly here. This could lead to a runtime error if styles is undefined. Please use optional chaining (styles?.root) to safely access the property.

Suggested change
style={styles.root}
style={styles?.root}

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
onClick={onInternalClick}
>
{/* Primary Tab Button */}
Expand Down Expand Up @@ -120,7 +126,11 @@ const TabNode: React.FC<TabNodeProps> = props => {
{`Tab ${currentPosition} of ${tabCount}`}
</div>
)}
{icon && <span className={`${tabPrefix}-icon`}>{icon}</span>}
{icon && (
<span className={clsx(`${tabPrefix}-icon`, classNames?.icon)} style={styles.icon}>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Similar to the root style, the styles prop is optional, but styles.icon is accessed directly. This could cause a runtime error if styles is undefined. Please use optional chaining (styles?.icon).

Suggested change
<span className={clsx(`${tabPrefix}-icon`, classNames?.icon)} style={styles.icon}>
<span className={clsx(`${tabPrefix}-icon`, classNames?.icon)} style={styles?.icon}>

{icon}
</span>
)}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
{label && labelNode}
</div>

Expand Down
12 changes: 9 additions & 3 deletions src/TabNavList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,15 @@ const TabNavList = React.forwardRef<HTMLDivElement, TabNavListProps>((props, ref
prefixCls={prefixCls}
key={key}
tab={tab}
className={tabsClassNames?.item}
/* first node should not have margin left */
style={i === 0 ? styles?.item : { ...tabNodeStyle, ...styles?.item }}
classNames={{
root: tabsClassNames?.item,
icon: tabsClassNames?.icon,
}}
styles={{
/* first node should not have margin left */
root: i === 0 ? styles?.item : { ...tabNodeStyle, ...styles?.item },
icon: styles?.icon,
}}
closable={tab.closable}
editable={editable}
active={key === activeKey}
Expand Down
8 changes: 5 additions & 3 deletions src/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ import type {
// Used for accessibility
let uuid = 0;

export type SemanticName = 'popup' | 'item' | 'indicator' | 'content' | 'header';
export type SemanticName = 'popup' | 'item' | 'indicator' | 'content' | 'header' | 'icon';

export interface TabsProps
extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange' | 'children'> {
export interface TabsProps extends Omit<
React.HTMLAttributes<HTMLDivElement>,
'onChange' | 'children'
> {
prefixCls?: string;
className?: string;
style?: React.CSSProperties;
Expand Down
5 changes: 5 additions & 0 deletions tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -745,12 +745,14 @@ describe('Tabs.Basic', () => {
item: 'custom-item',
content: 'custom-content',
header: 'custom-header',
icon: 'custom-icon',
};
const customStyles = {
indicator: { background: 'red' },
item: { color: 'blue' },
content: { background: 'green' },
header: { background: 'yellow' },
icon: { color: 'pink' },
};
const { container } = render(
<Tabs
Expand All @@ -764,15 +766,18 @@ describe('Tabs.Basic', () => {
const item = container.querySelector('.rc-tabs-tab') as HTMLElement;
const content = container.querySelector('.rc-tabs-tabpane') as HTMLElement;
const header = container.querySelector('.rc-tabs-nav') as HTMLElement;
const icon = container.querySelector('.rc-tabs-tab-icon') as HTMLElement;

expect(indicator).toHaveClass('custom-indicator');
expect(item).toHaveClass('custom-item');
expect(content).toHaveClass('custom-content');
expect(header).toHaveClass('custom-header');
expect(icon).toHaveClass('custom-icon');

expect(indicator).toHaveStyle({ background: 'red' });
expect(item).toHaveStyle({ color: 'blue' });
expect(content).toHaveStyle({ background: 'green' });
expect(header).toHaveStyle({ background: 'yellow' });
expect(icon).toHaveStyle({ color: 'pink' });
});
});