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
16 changes: 9 additions & 7 deletions src/TabNavList/TabNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { clsx } from 'clsx';
import * as React from 'react';
import type { EditableConfig, Tab } from '../interface';
import { genDataNodeKey, getRemovable } from '../util';
import type { SemanticName } from '@/Tabs';

export interface TabNodeProps {
id: string;
Expand All @@ -23,8 +24,8 @@ export interface TabNodeProps {
onMouseUp: React.MouseEventHandler;
onFocus: React.FocusEventHandler;
onBlur: React.FocusEventHandler;
style?: React.CSSProperties;
className?: string;
styles?: Pick<Partial<Record<SemanticName, React.CSSProperties>>, 'item' | 'close'>;
classNames?: Pick<Partial<Record<SemanticName, string>>, 'item' | 'close'>;
}

const TabNode: React.FC<TabNodeProps> = props => {
Expand All @@ -44,8 +45,8 @@ const TabNode: React.FC<TabNodeProps> = props => {
onKeyDown,
onMouseDown,
onMouseUp,
style,
className,
styles,
classNames: tabNodeClassNames,
tabCount,
currentPosition,
} = props;
Expand Down Expand Up @@ -83,13 +84,13 @@ const TabNode: React.FC<TabNodeProps> = props => {
<div
key={key}
data-node-key={genDataNodeKey(key)}
className={clsx(tabPrefix, className, {
className={clsx(tabPrefix, tabNodeClassNames?.item, {
[`${tabPrefix}-with-remove`]: removable,
[`${tabPrefix}-active`]: active,
[`${tabPrefix}-disabled`]: disabled,
[`${tabPrefix}-focus`]: focus,
})}
style={style}
style={styles?.item}
onClick={onInternalClick}
>
{/* Primary Tab Button */}
Expand Down Expand Up @@ -130,7 +131,8 @@ const TabNode: React.FC<TabNodeProps> = props => {
type="button"
aria-label={removeAriaLabel || 'remove'}
tabIndex={active ? 0 : -1}
className={`${tabPrefix}-remove`}
className={clsx(`${tabPrefix}-remove`, tabNodeClassNames?.close)}
style={styles?.close}
onClick={e => {
e.stopPropagation();
onRemoveTab(e);
Expand Down
12 changes: 9 additions & 3 deletions src/TabNavList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,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={{
item: tabsClassNames?.item,
close: tabsClassNames?.close,
}}
styles={{
/* first node should not have margin left */
item: i === 0 ? styles?.item : { ...tabNodeStyle, ...styles?.item },
close: styles?.close,
}}
closable={tab.closable}
editable={editable}
active={key === activeKey}
Expand Down
2 changes: 1 addition & 1 deletion src/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import type {
// Used for accessibility
let uuid = 0;

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

export interface TabsProps
extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange' | 'children'> {
Expand Down
24 changes: 24 additions & 0 deletions tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -775,4 +775,28 @@ describe('Tabs.Basic', () => {
expect(content).toHaveStyle({ background: 'green' });
expect(header).toHaveStyle({ background: 'yellow' });
});

it('support classnames and styles for editable', () => {
const customClassNames = {
close: 'custom-close',
};
const customStyles = {
close: { background: 'red' },
};

const { container } = render(
<Tabs
editable={{
onEdit: () => {},
}}
tabPosition="left"
items={[{ key: 'test', label: 'test', icon: 'test' }]}
styles={customStyles}
classNames={customClassNames}
/>,
);

expect(container.querySelector('.rc-tabs-tab-remove')).toHaveClass('custom-close');
expect(container.querySelector('.rc-tabs-tab-remove')).toHaveStyle({ background: 'red' });
});
});