I'm using a react typescript project with ant design tab, every time, when I click on the 2nd tab, the icon on the 1st tab should be changed to lock and the 2nd tab will have the book icon. If I then again click the 1st tab, it will display the book icon instead and the 2nd tab changed to lock.
code here
import React from 'react';
import ReactDOM from 'react-dom';
import 'antd/dist/antd.css';
import './index.css';
import { Tabs } from 'antd';
import { FileDoneOutlined, LockOutlined } from '@ant-design/icons';
const { TabPane } = Tabs;
ReactDOM.render(
<Tabs defaultActiveKey="2">
<TabPane
tab={
<span>
<FileDoneOutlined />
Tab 1
</span>
}
key="1"
>
Tab 1
</TabPane>
<TabPane
tab={
<span>
< LockOutlined/>
Tab 2
</span>
}
key="2"
>
Tab 2
</TabPane>
</Tabs>,
document.getElementById('container'),
);
The easiest way is to switch to using the Tabs as a controlled component, so you can make changes to the render based on the currently active tab.
Then just use a ternary operator to switch out the Icon for each tab based on if it's active
Working Stackblitz: https://stackblitz.com/edit/react-uwhrx3-oajdjw?file=index.js
Here's the code:
Just for fun, I set it up so that the Tabs uses a configuration array to set up the panes.
https://stackblitz.com/edit/react-uwhrx3-vnkdcq?file=index.js