【发布时间】:2021-08-12 11:30:10
【问题描述】:
我正在使用 AntDesign 绘制水平选项卡,我想在选项卡旁边添加自定义添加按钮,如何使用 Ant design 来做到这一点,我们在 Antdesign 中内置了带有 + Symbol 的配置我该怎么做。到现在是这个样子。
这是代码
import React,{useState} from 'react'
import { Tabs, Button,Row,Col } from 'antd';
const { TabPane } = Tabs;
const CompoundsTabs = () => {
const initialPanes = [
{ title: "Tab 1", content: "Content of Tab 1", key: "1" },
{ title: "Tab 2", content: "Content of Tab 2", key: "2" }
];
let newTabIndex = 0;
const [activeState, setActiveState] = useState(initialPanes[0].key);
const [panes, setPanes] = useState(initialPanes);
const add = () => {
const activeKey =
(panes && panes.length ? +panes[panes.length - 1].key : 0) + 1;
setActiveState(activeKey);
setPanes((prev) => [
...prev,
{
title: "Tab " + activeKey,
content: "Content of new Tab",
key: activeKey
}
]);
};
const remove = (key) => {
setPanes((prev) => {
const idx = prev.findIndex((item) => +item.key === +key);
prev.splice(idx, 1);
return [...prev];
});
};
const onChange = (activeKey) => {
setActiveState(activeKey);
};
const onEdit = (targetKey, action) => {
if (action === "remove") {
console.log("sdsds", targetKey);
remove(targetKey);
} else if (action === "add") {
add();
}
};
const deleteCompound=()=>{
console.log("delete")
}
return (
<div>
<Tabs
type="editable-card"
onChange={onChange}
activeKey={activeState}
onEdit={onEdit}
hideRemove
>
{panes.map((pane) => (
<TabPane tab={<Row><Col span={18}>{pane.title} </Col>
<Col span={4}></Col>
<Col span={2} onClick={deleteCompound}>X</Col>
</Row>} key={pane.key}>
{pane.content}
</TabPane>
))}
</Tabs>
</div>
)
}
export default CompoundsTabs
我推荐了https://ant.design/components/tabs/ 和https://codepen.io/pen/?&editors=001 这里是标签上方的自定义按钮,我希望它在最后一个标签旁边。
谁能帮我解决这个问题?
谢谢
【问题讨论】: