diff --git a/src/TabNavList/TabNode.tsx b/src/TabNavList/TabNode.tsx index 8e076898..1ee1e049 100644 --- a/src/TabNavList/TabNode.tsx +++ b/src/TabNavList/TabNode.tsx @@ -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; @@ -23,8 +24,8 @@ export interface TabNodeProps { onMouseUp: React.MouseEventHandler; onFocus: React.FocusEventHandler; onBlur: React.FocusEventHandler; - style?: React.CSSProperties; - className?: string; + styles?: Pick>, 'item' | 'close'>; + classNames?: Pick>, 'item' | 'close'>; } const TabNode: React.FC = props => { @@ -44,8 +45,8 @@ const TabNode: React.FC = props => { onKeyDown, onMouseDown, onMouseUp, - style, - className, + styles, + classNames: tabNodeClassNames, tabCount, currentPosition, } = props; @@ -83,13 +84,13 @@ const TabNode: React.FC = props => {
{/* Primary Tab Button */} @@ -130,7 +131,8 @@ const TabNode: React.FC = 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); diff --git a/src/TabNavList/index.tsx b/src/TabNavList/index.tsx index 39ea7cac..1a9f4254 100644 --- a/src/TabNavList/index.tsx +++ b/src/TabNavList/index.tsx @@ -435,9 +435,15 @@ const TabNavList = React.forwardRef((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} diff --git a/src/Tabs.tsx b/src/Tabs.tsx index 2dce753a..e90d9a0c 100644 --- a/src/Tabs.tsx +++ b/src/Tabs.tsx @@ -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, 'onChange' | 'children'> { diff --git a/tests/index.test.tsx b/tests/index.test.tsx index 606b4cfe..04948f41 100644 --- a/tests/index.test.tsx +++ b/tests/index.test.tsx @@ -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( + {}, + }} + 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' }); + }); });