Skip to content

Commit

Permalink
fix(Tabs): fix tabs action style and add test unit (#2808)
Browse files Browse the repository at this point in the history
* fix(tabs): fix tabs action style and add test unit

* test: update test snap and action render usage parseTNode

---------

Co-authored-by: Heising <heising@travelconnect.cn>
  • Loading branch information
HaixingOoO and Heising authored Mar 20, 2024
1 parent e2f4913 commit 2ce5f99
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 190 deletions.
14 changes: 13 additions & 1 deletion src/tabs/TabNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import TabBar from './TabBar';
import tabBase from '../_common/js/tabs/base';
import useGlobalIcon from '../hooks/useGlobalIcon';
import type { DragSortInnerProps } from '../_util/useDragSorter';
import parseTNode from '../_util/parseTNode';

const { moveActiveTabIntoView, calcScrollLeft, scrollToLeft, scrollToRight, calculateCanToLeft, calculateCanToRight } =
tabBase;
Expand All @@ -39,6 +40,7 @@ const TabNav: React.FC<TabNavProps> = (props) => {
onChange = noop,
activeValue,
children,
action,
getDragProps,
} = props;

Expand Down Expand Up @@ -272,7 +274,17 @@ const TabNav: React.FC<TabNavProps> = (props) => {
<AddIcon />
</div>
) : null}
{props.action}
{action ? (
<div
className={classNames(
tdTabsClassGenerator('btn'),
tdTabsClassGenerator('nav-action'),
tdSizeClassGenerator(size),
)}
>
{parseTNode(action)}
</div>
) : null}
</div>
<div
className={classNames(
Expand Down
22 changes: 22 additions & 0 deletions src/tabs/__tests__/tabs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,26 @@ describe('Tabs 组件测试', () => {
expect(onDragSort.mock.calls[0][0].target.value).toEqual('vue');
expect(container.querySelectorAll('.t-tabs__nav-item-text-wrapper').item(0).firstChild.nodeValue).toEqual('react');
});

test('Tabs action', () => {
const { container } = render(
<Tabs
action="Action"
size={'medium'}
list={[
{
label: 'a',
value: 'a',
},
{
label: 'b',
value: 'b',
},
]}
/>,
);

expect(container.querySelector('.t-tabs__nav-action')).not.toBeNull();
expect(container.querySelector('.t-tabs__nav-action')).toBeInTheDocument();
});
});
Loading

0 comments on commit 2ce5f99

Please sign in to comment.