diff --git a/components/tabs/demo/add.md b/components/tabs/demo/add.md
index 705de2cce..d4bb5464c 100644
--- a/components/tabs/demo/add.md
+++ b/components/tabs/demo/add.md
@@ -1,85 +1,101 @@
-# 添加
+# 动态的页签
- order: 4
-演示添加删除功能。
+演示添加删除和附加操作。
---
````jsx
-import { Tabs, Button, Icon } from 'antd';
+import { Tabs, Button, Icon, message } from 'antd';
const TabPane = Tabs.TabPane;
-var index = 0;
+let index = 0;
const closeStyle = {
position: 'absolute',
- top: 0,
- right: -10,
-};
-var addStyle = {
- pointerEvents: 'auto',
- color: 'black',
+ top: 8,
+ right: -9,
};
-var Test = React.createClass({
+const addStyle = {
+ pointerEvents: 'auto',
+ color: '#2db7f5',
+};
+
+const Test = React.createClass({
getInitialState() {
return {
tabs: [{
title: 'title ' + index,
content: 'content ' + index,
+ index: index
}],
- activeKey: 'title ' + index
+ activeKey: index.toString()
};
},
- remove(title, e) {
+ remove(index, e) {
e.stopPropagation();
- if(this.state.tabs.length === 1) {
- antd.message.error('仅剩一个,不能删除');
+ let tabs = this.state.tabs;
+ let activeKey = this.state.activeKey;
+ let foundIndex = 0;
+
+ if(tabs.length === 1) {
+ message.error('仅剩一个,不能删除');
return;
}
- var foundIndex = 0;
- var tabs = this.state.tabs.filter(function (t, index) {
- if (t.title !== title) {
+
+ const newTabs = tabs.filter(tab => {
+ if (tab.index !== index) {
return true;
} else {
foundIndex = index;
return false;
}
});
- var activeKey = this.state.activeKey;
- if (activeKey === title) {
- if (foundIndex) {
- foundIndex--;
- }
- activeKey = tabs[foundIndex].title;
+
+ if (activeKey === index) {
+ activeKey = tabs[foundIndex - 1].index;
}
- this.setState({tabs, activeKey})
+
+ this.setState({
+ tabs: newTabs, activeKey
+ });
},
add() {
- index++;
+ index += 1;
this.setState({
tabs: this.state.tabs.concat({
- title: 'title '+index,
- content: 'content '+index,
- })
+ title: 'title ' + index,
+ content: 'content ' + index,
+ index: index,
+ }),
+ activeKey: index.toString(),
});
},
onChange(activeKey) {
- this.setState({activeKey});
+ console.log(activeKey);
+ this.setState({ activeKey });
},
render() {
- return 其它操作}>
- {
- this.state.tabs.map((t)=>{
- return {t.title} }>
- {t.content}
- ;
- }).concat(} />)
- }
-
+ const addBtn = ;
+ const operations = ;
+ return (
+
+ {
+ this.state.tabs.map(tab => (
+
+ {tab.title}
+
+
+ }>{tab.content}
+ ))
+ }
+
+
+ );
}
})