Skip to content

Commit 7d5b243

Browse files
authored
feat: tab support classnames and styles (#786)
* feat: add content for classnames and styles * add header
1 parent 1bc44a5 commit 7d5b243

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

src/TabNavList/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,8 @@ const TabNavList = React.forwardRef<HTMLDivElement, TabNavListProps>((props, ref
573573
ref={useComposeRef(ref, containerRef)}
574574
role="tablist"
575575
aria-orientation={tabPositionTopOrBottom ? 'horizontal' : 'vertical'}
576-
className={classNames(`${prefixCls}-nav`, className)}
577-
style={style}
576+
className={classNames(`${prefixCls}-nav`, className, tabsClassNames?.header)}
577+
style={{ ...styles?.header, ...style }}
578578
onKeyDown={() => {
579579
// No need animation when use keyboard
580580
doLockAnimation();

src/TabPanelList/index.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,20 @@ export interface TabPanelListProps {
1111
animated?: AnimatedConfig;
1212
tabPosition?: TabPosition;
1313
destroyInactiveTabPane?: boolean;
14+
contentStyle?: React.CSSProperties;
15+
contentClassName?: string;
1416
}
1517

1618
const TabPanelList: React.FC<TabPanelListProps> = props => {
17-
const { id, activeKey, animated, tabPosition, destroyInactiveTabPane } = props;
19+
const {
20+
id,
21+
activeKey,
22+
animated,
23+
tabPosition,
24+
destroyInactiveTabPane,
25+
contentStyle,
26+
contentClassName,
27+
} = props;
1828
const { prefixCls, tabs } = React.useContext(TabContext);
1929
const tabPaneAnimated = animated.tabPane;
2030

@@ -54,8 +64,8 @@ const TabPanelList: React.FC<TabPanelListProps> = props => {
5464
tabKey={key}
5565
animated={tabPaneAnimated}
5666
active={active}
57-
style={{ ...paneStyle, ...motionStyle }}
58-
className={classNames(paneClassName, motionClassName)}
67+
style={{ ...contentStyle, ...paneStyle, ...motionStyle }}
68+
className={classNames(contentClassName, paneClassName, motionClassName)}
5969
ref={ref}
6070
/>
6171
)}

src/Tabs.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import type {
3434
// Used for accessibility
3535
let uuid = 0;
3636

37-
export type SemanticName = 'popup' | 'item' | 'indicator';
37+
export type SemanticName = 'popup' | 'item' | 'indicator' | 'content' | 'header';
3838

3939
export interface TabsProps
4040
extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange' | 'children'> {
@@ -186,9 +186,9 @@ const Tabs = React.forwardRef<HTMLDivElement, TabsProps>((props, ref) => {
186186
style: tabBarStyle,
187187
getPopupContainer,
188188
popupClassName: classNames(popupClassName, tabsClassNames?.popup),
189+
indicator,
189190
styles,
190191
classNames: tabsClassNames,
191-
indicator,
192192
};
193193

194194
return (
@@ -212,6 +212,8 @@ const Tabs = React.forwardRef<HTMLDivElement, TabsProps>((props, ref) => {
212212
<TabPanelList
213213
destroyInactiveTabPane={destroyInactiveTabPane}
214214
{...sharedProps}
215+
contentStyle={styles?.content}
216+
contentClassName={tabsClassNames?.content}
215217
animated={mergedAnimated}
216218
/>
217219
</div>

tests/index.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,10 +693,14 @@ describe('Tabs.Basic', () => {
693693
const customClassNames = {
694694
indicator: 'custom-indicator',
695695
item: 'custom-item',
696+
content: 'custom-content',
697+
header: 'custom-header',
696698
};
697699
const customStyles = {
698700
indicator: { background: 'red' },
699701
item: { color: 'blue' },
702+
content: { background: 'green' },
703+
header: { background: 'yellow' },
700704
};
701705
const { container } = render(
702706
<Tabs
@@ -708,10 +712,17 @@ describe('Tabs.Basic', () => {
708712
);
709713
const indicator = container.querySelector('.rc-tabs-ink-bar') as HTMLElement;
710714
const item = container.querySelector('.rc-tabs-tab') as HTMLElement;
715+
const content = container.querySelector('.rc-tabs-tabpane') as HTMLElement;
716+
const header = container.querySelector('.rc-tabs-nav') as HTMLElement;
711717

712718
expect(indicator).toHaveClass('custom-indicator');
713719
expect(item).toHaveClass('custom-item');
720+
expect(content).toHaveClass('custom-content');
721+
expect(header).toHaveClass('custom-header');
722+
714723
expect(indicator).toHaveStyle({ background: 'red' });
715724
expect(item).toHaveStyle({ color: 'blue' });
725+
expect(content).toHaveStyle({ background: 'green' });
726+
expect(header).toHaveStyle({ background: 'yellow' });
716727
});
717728
});

0 commit comments

Comments
 (0)