Skip to content

Commit 079a695

Browse files
committed
feat: enhance OperationNode to support custom classNames and styles for close button
1 parent f0f7e8c commit 079a695

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

src/TabNavList/OperationNode.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { useEffect, useState } from 'react';
77
import type { EditableConfig, Tab, TabsLocale, MoreProps } from '../interface';
88
import { getRemovable } from '../util';
99
import AddButton from './AddButton';
10+
import { SemanticName } from '../Tabs';
1011

1112
export interface OperationNodeProps {
1213
prefixCls: string;
@@ -27,6 +28,8 @@ export interface OperationNodeProps {
2728
getPopupContainer?: (node: HTMLElement) => HTMLElement;
2829
popupClassName?: string;
2930
popupStyle?: React.CSSProperties;
31+
styles?: Pick<Partial<Record<SemanticName, React.CSSProperties>>, 'close'>;
32+
classNames?: Pick<Partial<Record<SemanticName, string>>, 'close'>;
3033
}
3134

3235
const OperationNode = React.forwardRef<HTMLDivElement, OperationNodeProps>((props, ref) => {
@@ -47,6 +50,8 @@ const OperationNode = React.forwardRef<HTMLDivElement, OperationNodeProps>((prop
4750
getPopupContainer,
4851
popupClassName,
4952
popupStyle,
53+
classNames,
54+
styles,
5055
} = props;
5156
// ======================== Dropdown ========================
5257
const [open, setOpen] = useState(false);
@@ -98,7 +103,8 @@ const OperationNode = React.forwardRef<HTMLDivElement, OperationNodeProps>((prop
98103
type="button"
99104
aria-label={removeAriaLabel || 'remove'}
100105
tabIndex={0}
101-
className={`${dropdownPrefix}-menu-item-remove`}
106+
className={clsx(`${dropdownPrefix}-menu-item-remove`, classNames?.close)}
107+
style={styles?.close}
102108
onClick={e => {
103109
e.stopPropagation();
104110
onRemoveTab(e, key);

tests/index.test.tsx

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ describe('Tabs.Basic', () => {
776776
expect(header).toHaveStyle({ background: 'yellow' });
777777
});
778778

779-
it('support classnames and styles for editable', () => {
779+
it('support classnames and styles for editable close button', () => {
780780
const customClassNames = {
781781
close: 'custom-close',
782782
};
@@ -785,17 +785,30 @@ describe('Tabs.Basic', () => {
785785
};
786786

787787
const { container } = render(
788-
<Tabs
789-
editable={{
790-
onEdit: () => {},
791-
}}
792-
tabPosition="left"
793-
items={[{ key: 'test', label: 'test', icon: 'test' }]}
794-
styles={customStyles}
795-
classNames={customClassNames}
796-
/>,
788+
<div style={{ width: 100 }}>
789+
<Tabs
790+
editable={{
791+
onEdit: () => {},
792+
}}
793+
tabPosition="left"
794+
items={Array.from({ length: 10 }).map((_, index) => ({
795+
key: `test-${index}`,
796+
label: `test-${index}`,
797+
icon: 'test',
798+
}))}
799+
styles={customStyles}
800+
classNames={customClassNames}
801+
getPopupContainer={() => document.querySelector('.rc-tabs') as HTMLElement}
802+
/>
803+
</div>,
797804
);
798805

806+
expect(container.querySelector('.rc-tabs-dropdown-menu-item-remove')).toHaveClass(
807+
'custom-close',
808+
);
809+
expect(container.querySelector('.rc-tabs-dropdown-menu-item-remove')).toHaveStyle({
810+
background: 'red',
811+
});
799812
expect(container.querySelector('.rc-tabs-tab-remove')).toHaveClass('custom-close');
800813
expect(container.querySelector('.rc-tabs-tab-remove')).toHaveStyle({ background: 'red' });
801814
});

0 commit comments

Comments
 (0)