Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Tab Item support icon prop #46096

Merged
merged 8 commits into from Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions components/tabs/__tests__/__snapshots__/demo-extend.test.ts.snap
Expand Up @@ -3244,7 +3244,9 @@ exports[`renders components/tabs/demo/icon.tsx extend context correctly 1`] = `
role="tab"
tabindex="0"
>
<span>
<span
class="ant-tabs-tab-icon"
>
<span
aria-label="apple"
class="anticon anticon-apple"
Expand All @@ -3264,6 +3266,8 @@ exports[`renders components/tabs/demo/icon.tsx extend context correctly 1`] = `
/>
</svg>
</span>
</span>
<span>
Tab 1
</span>
</div>
Expand All @@ -3280,7 +3284,9 @@ exports[`renders components/tabs/demo/icon.tsx extend context correctly 1`] = `
role="tab"
tabindex="0"
>
<span>
<span
class="ant-tabs-tab-icon"
>
<span
aria-label="android"
class="anticon anticon-android"
Expand All @@ -3300,6 +3306,8 @@ exports[`renders components/tabs/demo/icon.tsx extend context correctly 1`] = `
/>
</svg>
</span>
</span>
<span>
Tab 2
</span>
</div>
Expand Down
12 changes: 10 additions & 2 deletions components/tabs/__tests__/__snapshots__/demo.test.ts.snap
Expand Up @@ -2709,7 +2709,9 @@ exports[`renders components/tabs/demo/icon.tsx correctly 1`] = `
role="tab"
tabindex="0"
>
<span>
<span
class="ant-tabs-tab-icon"
>
<span
aria-label="apple"
class="anticon anticon-apple"
Expand All @@ -2729,6 +2731,8 @@ exports[`renders components/tabs/demo/icon.tsx correctly 1`] = `
/>
</svg>
</span>
</span>
<span>
Tab
<!-- -->
1
Expand All @@ -2745,7 +2749,9 @@ exports[`renders components/tabs/demo/icon.tsx correctly 1`] = `
role="tab"
tabindex="0"
>
<span>
<span
class="ant-tabs-tab-icon"
>
<span
aria-label="android"
class="anticon anticon-android"
Expand All @@ -2765,6 +2771,8 @@ exports[`renders components/tabs/demo/icon.tsx correctly 1`] = `
/>
</svg>
</span>
</span>
<span>
Tab
<!-- -->
2
Expand Down
9 changes: 2 additions & 7 deletions components/tabs/demo/icon.tsx
Expand Up @@ -7,16 +7,11 @@ const App: React.FC = () => (
defaultActiveKey="2"
items={[AppleOutlined, AndroidOutlined].map((Icon, i) => {
const id = String(i + 1);

return {
label: (
<span>
<Icon />
Tab {id}
</span>
),
label: <span>Tab {id}</span>,
key: id,
children: `Tab ${id}`,
icon: <Icon />,
};
})}
/>
Expand Down
1 change: 1 addition & 0 deletions components/tabs/index.en-US.md
Expand Up @@ -82,6 +82,7 @@ More option at [rc-tabs tabs](https://github.com/react-component/tabs#tabs)
| forceRender | Forced render of content in tabs, not lazy render after clicking on tabs | boolean | false | |
| key | TabPane's key | string | - | |
| label | TabPane's head display text | ReactNode | - | |
| icon | TabPane's head display icon | ReactNode | - | 5.12.0 |
| children | TabPane's head display content | ReactNode | - | |
| closable | Whether a close (x) button is visible, Only works while `type="editable-card"` | boolean | true | |

Expand Down
1 change: 1 addition & 0 deletions components/tabs/index.zh-CN.md
Expand Up @@ -84,6 +84,7 @@ Ant Design 依次提供了三级选项卡,分别用于不同的场景。
| forceRender | 被隐藏时是否渲染 DOM 结构 | boolean | false | |
| key | 对应 activeKey | string | - | |
| label | 选项卡头显示文字 | ReactNode | - | |
| icon | 选项卡头显示图标 | ReactNode | - | 5.12.0 |
| children | 选项卡头显示内容 | ReactNode | - | |
| closable | 是否显示选项卡的关闭按钮,在 `type="editable-card"` 时有效 | boolean | true | |

Expand Down
5 changes: 4 additions & 1 deletion components/tabs/style/index.ts
Expand Up @@ -691,6 +691,9 @@ const genTabStyle: GenerateStyle<TabsToken, CSSObject> = (token: TabsToken) => {
'&-btn': {
outline: 'none',
transition: 'all 0.3s',
[`${tabCls}-icon:not(:last-child)`]: {
marginInlineEnd: token.marginSM,
},
},
'&-remove': {
flex: 'none',
Expand Down Expand Up @@ -734,7 +737,7 @@ const genTabStyle: GenerateStyle<TabsToken, CSSObject> = (token: TabsToken) => {
[`& ${tabCls}-remove ${iconCls}`]: {
margin: 0,
},
[iconCls]: {
[`${iconCls}:not(:last-child)`]: {
marginRight: {
Copy link

@ANM699 ANM699 Feb 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里会导致之前版本icon的margin-right丢失

_skip_check_: true,
value: token.marginSM,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -151,7 +151,7 @@
"rc-steps": "~6.0.1",
"rc-switch": "~4.1.0",
"rc-table": "~7.36.0",
"rc-tabs": "~12.13.1",
"rc-tabs": "~12.14.1",
"rc-textarea": "~1.5.3",
"rc-tooltip": "~6.1.2",
"rc-tree": "~5.8.2",
Expand Down